mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Move command related modules to "commands" package
This commit is contained in:
@ -18,7 +18,7 @@ from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
from os import environ, makedirs, remove
|
||||
from os.path import join, isdir
|
||||
from os.path import isdir, join
|
||||
|
||||
from elftools.elf.descriptions import describe_sh_flags
|
||||
from elftools.elf.elffile import ELFFile
|
||||
@ -52,7 +52,7 @@ def _get_symbol_locations(env, elf_path, addrs):
|
||||
cmd = [env.subst("$CC").replace("-gcc", "-addr2line"), "-e", elf_path]
|
||||
result = _run_tool(cmd, env, addrs)
|
||||
locations = [line for line in result["out"].split("\n") if line]
|
||||
assert(len(addrs) == len(locations))
|
||||
assert len(addrs) == len(locations)
|
||||
|
||||
return dict(zip(addrs, [l.strip().replace("\\", "/") for l in locations]))
|
||||
|
||||
@ -61,12 +61,17 @@ def _get_demangled_names(env, mangled_names):
|
||||
if not mangled_names:
|
||||
return {}
|
||||
result = _run_tool(
|
||||
[env.subst("$CC").replace("-gcc", "-c++filt")], env, mangled_names)
|
||||
[env.subst("$CC").replace("-gcc", "-c++filt")], env, mangled_names
|
||||
)
|
||||
demangled_names = [line for line in result["out"].split("\n") if line]
|
||||
assert(len(mangled_names) == len(demangled_names))
|
||||
assert len(mangled_names) == len(demangled_names)
|
||||
|
||||
return dict(zip(mangled_names, [dn.strip().replace(
|
||||
"::__FUNCTION__", "") for dn in demangled_names]))
|
||||
return dict(
|
||||
zip(
|
||||
mangled_names,
|
||||
[dn.strip().replace("::__FUNCTION__", "") for dn in demangled_names],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _determine_section(sections, symbol_addr):
|
||||
@ -150,8 +155,7 @@ def _collect_symbols_info(env, elffile, elf_path, sections):
|
||||
symbol_addrs.append(hex(symbol_addr))
|
||||
symbols.append(symbol)
|
||||
|
||||
symbol_locations = _get_symbol_locations(
|
||||
env, elf_path, symbol_addrs)
|
||||
symbol_locations = _get_symbol_locations(env, elf_path, symbol_addrs)
|
||||
demangled_names = _get_demangled_names(env, mangled_names)
|
||||
for symbol in symbols:
|
||||
if symbol["name"].startswith("_Z"):
|
||||
|
@ -13,7 +13,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
from os.path import dirname, isfile, join
|
||||
|
||||
import click
|
||||
|
||||
@ -22,6 +21,10 @@ class PlatformioCLI(click.MultiCommand):
|
||||
|
||||
leftover_args = []
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PlatformioCLI, self).__init__(*args, **kwargs)
|
||||
self._pio_cmds_dir = os.path.dirname(__file__)
|
||||
|
||||
@staticmethod
|
||||
def in_silence():
|
||||
args = PlatformioCLI.leftover_args
|
||||
@ -42,34 +45,23 @@ class PlatformioCLI(click.MultiCommand):
|
||||
|
||||
def list_commands(self, ctx):
|
||||
cmds = []
|
||||
cmds_dir = dirname(__file__)
|
||||
for name in os.listdir(cmds_dir):
|
||||
if name.startswith("__init__"):
|
||||
for cmd_name in os.listdir(self._pio_cmds_dir):
|
||||
if cmd_name.startswith("__init__"):
|
||||
continue
|
||||
if isfile(join(cmds_dir, name, "command.py")):
|
||||
cmds.append(name)
|
||||
elif name.endswith(".py"):
|
||||
cmds.append(name[:-3])
|
||||
if os.path.isfile(os.path.join(self._pio_cmds_dir, cmd_name, "command.py")):
|
||||
cmds.append(cmd_name)
|
||||
elif cmd_name.endswith(".py"):
|
||||
cmds.append(cmd_name[:-3])
|
||||
cmds.sort()
|
||||
return cmds
|
||||
|
||||
def get_command(self, ctx, cmd_name):
|
||||
mod = None
|
||||
try:
|
||||
mod = __import__("platformio.commands." + cmd_name, None, None, ["cli"])
|
||||
mod_path = "platformio.commands." + cmd_name
|
||||
if os.path.isfile(os.path.join(self._pio_cmds_dir, cmd_name, "command.py")):
|
||||
mod_path = "platformio.commands.%s.command" % cmd_name
|
||||
mod = __import__(mod_path, None, None, ["cli"])
|
||||
except ImportError:
|
||||
raise click.UsageError('No such command "%s"' % cmd_name, ctx)
|
||||
return mod.cli
|
||||
|
||||
@staticmethod
|
||||
def _handle_obsolate_command(name):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
if name == "platforms":
|
||||
from platformio.commands import platform
|
||||
|
||||
return platform.cli
|
||||
if name == "serialports":
|
||||
from platformio.commands import device
|
||||
|
||||
return device.cli
|
||||
raise AttributeError()
|
||||
|
@ -24,8 +24,8 @@ import click
|
||||
from tabulate import tabulate
|
||||
|
||||
from platformio import app, exception, fs, util
|
||||
from platformio.check.defect import DefectItem
|
||||
from platformio.check.tools import CheckToolFactory
|
||||
from platformio.commands.check.defect import DefectItem
|
||||
from platformio.commands.check.tools import CheckToolFactory
|
||||
from platformio.compat import dump_json_to_unicode
|
||||
from platformio.project.config import ProjectConfig
|
||||
from platformio.project.helpers import find_project_dir_above, get_project_dir
|
@ -13,8 +13,8 @@
|
||||
# limitations under the License.
|
||||
|
||||
from platformio import exception
|
||||
from platformio.check.tools.clangtidy import ClangtidyCheckTool
|
||||
from platformio.check.tools.cppcheck import CppcheckCheckTool
|
||||
from platformio.commands.check.tools.clangtidy import ClangtidyCheckTool
|
||||
from platformio.commands.check.tools.cppcheck import CppcheckCheckTool
|
||||
|
||||
|
||||
class CheckToolFactory(object):
|
@ -15,7 +15,7 @@
|
||||
import click
|
||||
|
||||
from platformio import fs, proc
|
||||
from platformio.check.defect import DefectItem
|
||||
from platformio.commands.check.defect import DefectItem
|
||||
from platformio.project.helpers import get_project_dir, load_project_ide_data
|
||||
|
||||
|
@ -15,8 +15,8 @@
|
||||
import re
|
||||
from os.path import join
|
||||
|
||||
from platformio.check.defect import DefectItem
|
||||
from platformio.check.tools.base import CheckToolBase
|
||||
from platformio.commands.check.defect import DefectItem
|
||||
from platformio.commands.check.tools.base import CheckToolBase
|
||||
from platformio.managers.core import get_core_package_dir
|
||||
|
||||
|
@ -16,8 +16,8 @@ from os import remove
|
||||
from os.path import isfile, join
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from platformio.check.defect import DefectItem
|
||||
from platformio.check.tools.base import CheckToolBase
|
||||
from platformio.commands.check.defect import DefectItem
|
||||
from platformio.commands.check.tools.base import CheckToolBase
|
||||
from platformio.managers.core import get_core_package_dir
|
||||
|
||||
|
@ -23,7 +23,7 @@ import click
|
||||
from platformio import app, fs
|
||||
from platformio.commands.init import cli as cmd_init
|
||||
from platformio.commands.init import validate_boards
|
||||
from platformio.commands.run import cli as cmd_run
|
||||
from platformio.commands.run.command import cli as cmd_run
|
||||
from platformio.compat import glob_escape
|
||||
from platformio.exception import CIBuildEnvsEmpty
|
||||
from platformio.project.config import ProjectConfig
|
||||
|
@ -27,10 +27,10 @@ from twisted.internet import stdio # pylint: disable=import-error
|
||||
from twisted.internet import task # pylint: disable=import-error
|
||||
|
||||
from platformio import app, exception, fs, proc, util
|
||||
from platformio.commands.debug import helpers, initcfgs
|
||||
from platformio.commands.debug.process import BaseProcess
|
||||
from platformio.commands.debug.server import DebugServer
|
||||
from platformio.compat import hashlib_encode_data
|
||||
from platformio.debug import helpers, initcfgs
|
||||
from platformio.debug.process import BaseProcess
|
||||
from platformio.debug.server import DebugServer
|
||||
from platformio.project.helpers import get_project_cache_dir
|
||||
from platformio.telemetry import MeasurementProtocol
|
||||
|
@ -22,7 +22,7 @@ from os.path import isfile
|
||||
import click
|
||||
|
||||
from platformio import app, exception, fs, proc, util
|
||||
from platformio.debug import helpers
|
||||
from platformio.commands.debug import helpers
|
||||
from platformio.managers.core import inject_contrib_pysite
|
||||
from platformio.project.config import ProjectConfig
|
||||
from platformio.project.helpers import is_platformio_project, load_project_ide_data
|
||||
@ -139,7 +139,7 @@ def cli(ctx, project_dir, project_conf, environment, verbose, interface, __unpro
|
||||
inject_contrib_pysite()
|
||||
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from platformio.debug.client import GDBClient, reactor
|
||||
from platformio.commands.debug.client import GDBClient, reactor
|
||||
|
||||
client = GDBClient(project_dir, __unprocessed, debug_options, env_options)
|
||||
client.spawn(configuration["gdb_path"], configuration["prog_path"])
|
@ -21,7 +21,7 @@ from os.path import isfile
|
||||
|
||||
from platformio import exception, fs, util
|
||||
from platformio.commands.platform import platform_install as cmd_platform_install
|
||||
from platformio.commands.run import cli as cmd_run
|
||||
from platformio.commands.run.command import cli as cmd_run
|
||||
from platformio.managers.platform import PlatformFactory
|
||||
from platformio.project.config import ProjectConfig
|
||||
|
@ -19,7 +19,7 @@ from twisted.internet import error # pylint: disable=import-error
|
||||
from twisted.internet import reactor # pylint: disable=import-error
|
||||
|
||||
from platformio import exception, fs, util
|
||||
from platformio.debug.process import BaseProcess
|
||||
from platformio.commands.debug.process import BaseProcess
|
||||
from platformio.proc import where_is_program
|
||||
|
||||
|
@ -44,14 +44,14 @@ def cli(port, host, no_open):
|
||||
from twisted.internet import reactor
|
||||
from twisted.web import server
|
||||
|
||||
from platformio.home.rpc.handlers.app import AppRPC
|
||||
from platformio.home.rpc.handlers.ide import IDERPC
|
||||
from platformio.home.rpc.handlers.misc import MiscRPC
|
||||
from platformio.home.rpc.handlers.os import OSRPC
|
||||
from platformio.home.rpc.handlers.piocore import PIOCoreRPC
|
||||
from platformio.home.rpc.handlers.project import ProjectRPC
|
||||
from platformio.home.rpc.server import JSONRPCServerFactory
|
||||
from platformio.home.web import WebRoot
|
||||
from platformio.commands.home.rpc.handlers.app import AppRPC
|
||||
from platformio.commands.home.rpc.handlers.ide import IDERPC
|
||||
from platformio.commands.home.rpc.handlers.misc import MiscRPC
|
||||
from platformio.commands.home.rpc.handlers.os import OSRPC
|
||||
from platformio.commands.home.rpc.handlers.piocore import PIOCoreRPC
|
||||
from platformio.commands.home.rpc.handlers.project import ProjectRPC
|
||||
from platformio.commands.home.rpc.server import JSONRPCServerFactory
|
||||
from platformio.commands.home.web import WebRoot
|
||||
|
||||
factory = JSONRPCServerFactory()
|
||||
factory.addHandler(AppRPC(), namespace="app")
|
@ -18,7 +18,7 @@ import time
|
||||
from twisted.internet import defer, reactor # pylint: disable=import-error
|
||||
|
||||
from platformio import app
|
||||
from platformio.home.rpc.handlers.os import OSRPC
|
||||
from platformio.commands.home.rpc.handlers.os import OSRPC
|
||||
|
||||
|
||||
class MiscRPC(object):
|
@ -25,8 +25,8 @@ import click
|
||||
from twisted.internet import defer # pylint: disable=import-error
|
||||
|
||||
from platformio import app, fs, util
|
||||
from platformio.commands.home import helpers
|
||||
from platformio.compat import PY2, get_filesystem_encoding
|
||||
from platformio.home import helpers
|
||||
|
||||
|
||||
class OSRPC(object):
|
@ -26,8 +26,8 @@ from twisted.internet import threads # pylint: disable=import-error
|
||||
from twisted.internet import utils # pylint: disable=import-error
|
||||
|
||||
from platformio import __main__, __version__, fs
|
||||
from platformio.commands.home import helpers
|
||||
from platformio.compat import PY2, get_filesystem_encoding, is_bytes, string_types
|
||||
from platformio.home import helpers
|
||||
|
||||
try:
|
||||
from thread import get_ident as thread_get_ident
|
@ -22,9 +22,9 @@ from os.path import basename, getmtime, isdir, isfile, join, realpath, sep
|
||||
import jsonrpc # pylint: disable=import-error
|
||||
|
||||
from platformio import exception, fs
|
||||
from platformio.commands.home.rpc.handlers.app import AppRPC
|
||||
from platformio.commands.home.rpc.handlers.piocore import PIOCoreRPC
|
||||
from platformio.compat import PY2, get_filesystem_encoding
|
||||
from platformio.home.rpc.handlers.app import AppRPC
|
||||
from platformio.home.rpc.handlers.piocore import PIOCoreRPC
|
||||
from platformio.ide.projectgenerator import ProjectGenerator
|
||||
from platformio.managers.platform import PlatformManager
|
||||
from platformio.project.config import ProjectConfig
|
@ -22,11 +22,11 @@ from tabulate import tabulate
|
||||
|
||||
from platformio import app, exception, fs, util
|
||||
from platformio.commands.device import device_monitor as cmd_device_monitor
|
||||
from platformio.commands.run.helpers import clean_build_dir, handle_legacy_libdeps
|
||||
from platformio.commands.run.processor import EnvironmentProcessor
|
||||
from platformio.commands.test.processor import CTX_META_TEST_IS_RUNNING
|
||||
from platformio.project.config import ProjectConfig
|
||||
from platformio.project.helpers import find_project_dir_above
|
||||
from platformio.run.helpers import clean_build_dir, handle_legacy_libdeps
|
||||
from platformio.run.processor import EnvironmentProcessor
|
||||
from platformio.test.processor import CTX_META_TEST_IS_RUNNING
|
||||
|
||||
# pylint: disable=too-many-arguments,too-many-locals,too-many-branches
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
from platformio import exception, telemetry
|
||||
from platformio.commands.platform import platform_install as cmd_platform_install
|
||||
from platformio.commands.test.processor import CTX_META_TEST_RUNNING_NAME
|
||||
from platformio.managers.platform import PlatformFactory
|
||||
from platformio.test.processor import CTX_META_TEST_RUNNING_NAME
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
|
@ -23,9 +23,9 @@ import click
|
||||
from tabulate import tabulate
|
||||
|
||||
from platformio import app, exception, fs, util
|
||||
from platformio.commands.test.embedded import EmbeddedTestProcessor
|
||||
from platformio.commands.test.native import NativeTestProcessor
|
||||
from platformio.project.config import ProjectConfig
|
||||
from platformio.test.embedded import EmbeddedTestProcessor
|
||||
from platformio.test.native import NativeTestProcessor
|
||||
|
||||
|
||||
@click.command("test", short_help="Unit Testing")
|
@ -18,8 +18,8 @@ import click
|
||||
import serial
|
||||
|
||||
from platformio import exception, util
|
||||
from platformio.commands.test.processor import TestProcessorBase
|
||||
from platformio.managers.platform import PlatformFactory
|
||||
from platformio.test.processor import TestProcessorBase
|
||||
|
||||
|
||||
class EmbeddedTestProcessor(TestProcessorBase):
|
@ -15,8 +15,8 @@
|
||||
from os.path import join
|
||||
|
||||
from platformio import proc
|
||||
from platformio.commands.test.processor import TestProcessorBase
|
||||
from platformio.proc import LineBufferedAsyncPipe
|
||||
from platformio.test.processor import TestProcessorBase
|
||||
|
||||
|
||||
class NativeTestProcessor(TestProcessorBase):
|
@ -113,7 +113,7 @@ class TestProcessorBase(object):
|
||||
|
||||
try:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from platformio.commands.run import cli as cmd_run
|
||||
from platformio.commands.run.command import cli as cmd_run
|
||||
|
||||
return self.cmd_ctx.invoke(
|
||||
cmd_run,
|
@ -137,7 +137,7 @@ def compute_project_checksum(config):
|
||||
|
||||
def load_project_ide_data(project_dir, env_or_envs):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from platformio.commands.run import cli as cmd_run
|
||||
from platformio.commands.run.command import cli as cmd_run
|
||||
|
||||
assert env_or_envs
|
||||
envs = env_or_envs
|
||||
|
@ -17,7 +17,7 @@ from os.path import isfile, join
|
||||
|
||||
import pytest
|
||||
|
||||
from platformio.commands.check import cli as cmd_check
|
||||
from platformio.commands.check.command import cli as cmd_check
|
||||
|
||||
DEFAULT_CONFIG = """
|
||||
[env:native]
|
||||
|
@ -12,7 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from platformio.commands.run import cli as cmd_run
|
||||
from platformio.commands.run.command import cli as cmd_run
|
||||
|
||||
|
||||
def test_build_flags(clirunner, validate_cliresult, tmpdir):
|
||||
|
Reference in New Issue
Block a user