forked from platformio/platformio-core
Format code with pep8 style
This commit is contained in:
2
.style.yapf
Normal file
2
.style.yapf
Normal file
@ -0,0 +1,2 @@
|
||||
[style]
|
||||
blank_line_before_nested_class_or_def = true
|
7
Makefile
7
Makefile
@ -4,6 +4,13 @@ lint:
|
||||
|
||||
isort:
|
||||
isort -rc ./platformio
|
||||
isort -rc ./tests
|
||||
isort -rc ./scripts
|
||||
|
||||
yapf:
|
||||
yapf --recursive --in-place platformio/
|
||||
|
||||
before-commit: isort yapf pylint
|
||||
|
||||
clean-docs:
|
||||
rm -rf docs/_build
|
||||
|
@ -18,12 +18,10 @@ VERSION = (3, 0, "0.dev18")
|
||||
__version__ = ".".join([str(s) for s in VERSION])
|
||||
|
||||
__title__ = "platformio"
|
||||
__description__ = (
|
||||
"An open source ecosystem for IoT development. "
|
||||
"Cross-platform build system and library manager. "
|
||||
"Continuous and IDE integration. "
|
||||
"Arduino and MBED compatible. Ready for Cloud compiling."
|
||||
)
|
||||
__description__ = ("An open source ecosystem for IoT development. "
|
||||
"Cross-platform build system and library manager. "
|
||||
"Continuous and IDE integration. "
|
||||
"Arduino and MBED compatible. Ready for Cloud compiling.")
|
||||
__url__ = "http://platformio.org"
|
||||
|
||||
__author__ = "Ivan Kravets"
|
||||
@ -35,7 +33,6 @@ __copyright__ = "Copyright 2014-2016 Ivan Kravets"
|
||||
__apiurl__ = "http://api.platformio.org"
|
||||
__apiip__ = "198.7.57.247"
|
||||
|
||||
|
||||
if sys.version_info < (2, 7, 0) or sys.version_info >= (3, 0, 0):
|
||||
msg = ("PlatformIO version %s does not run under Python version %s.\n"
|
||||
"Python 3 is not yet supported.\n")
|
||||
|
@ -40,8 +40,8 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904
|
||||
def get_command(self, ctx, name):
|
||||
mod = None
|
||||
try:
|
||||
mod = __import__("platformio.commands." + name,
|
||||
None, None, ["cli"])
|
||||
mod = __import__("platformio.commands." + name, None, None,
|
||||
["cli"])
|
||||
except ImportError:
|
||||
try:
|
||||
return self._handle_obsolate_command(name)
|
||||
@ -57,11 +57,15 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904
|
||||
raise AttributeError()
|
||||
|
||||
|
||||
@click.command(cls=PlatformioCLI,
|
||||
context_settings=dict(help_option_names=["-h", "--help"]))
|
||||
@click.command(
|
||||
cls=PlatformioCLI,
|
||||
context_settings=dict(help_option_names=["-h", "--help"]))
|
||||
@click.version_option(__version__, prog_name="PlatformIO")
|
||||
@click.option("--force", "-f", is_flag=True,
|
||||
help="Force to accept any confirmation prompts.")
|
||||
@click.option(
|
||||
"--force",
|
||||
"-f",
|
||||
is_flag=True,
|
||||
help="Force to accept any confirmation prompts.")
|
||||
@click.option("--caller", "-c", help="Caller ID (service).")
|
||||
@click.pass_context
|
||||
def cli(ctx, force, caller):
|
||||
|
@ -49,28 +49,23 @@ DEFAULT_SETTINGS = {
|
||||
"value": False
|
||||
},
|
||||
"enable_telemetry": {
|
||||
"description": (
|
||||
"Telemetry service <http://docs.platformio.org/en/stable/"
|
||||
"userguide/cmd_settings.html?#enable-telemetry> (Yes/No)"),
|
||||
"description":
|
||||
("Telemetry service <http://docs.platformio.org/en/stable/"
|
||||
"userguide/cmd_settings.html?#enable-telemetry> (Yes/No)"),
|
||||
"value": True
|
||||
},
|
||||
"enable_prompts": {
|
||||
"description": (
|
||||
"Can PlatformIO communicate with you via prompts: "
|
||||
"propose to install platforms which aren't installed yet, "
|
||||
"paginate over library search results and etc.)? ATTENTION!!! "
|
||||
"If you call PlatformIO like subprocess, "
|
||||
"please disable prompts to avoid blocking (Yes/No)"),
|
||||
"description":
|
||||
("Can PlatformIO communicate with you via prompts: "
|
||||
"propose to install platforms which aren't installed yet, "
|
||||
"paginate over library search results and etc.)? ATTENTION!!! "
|
||||
"If you call PlatformIO like subprocess, "
|
||||
"please disable prompts to avoid blocking (Yes/No)"),
|
||||
"value": True
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SESSION_VARS = {
|
||||
"command_ctx": None,
|
||||
"force_option": False,
|
||||
"caller_id": None
|
||||
}
|
||||
SESSION_VARS = {"command_ctx": None, "force_option": False, "caller_id": None}
|
||||
|
||||
|
||||
class State(object):
|
||||
@ -108,8 +103,8 @@ class State(object):
|
||||
return
|
||||
self._lockfile = LockFile(self.path)
|
||||
|
||||
if (self._lockfile.is_locked() and
|
||||
(time() - getmtime(self._lockfile.lock_file)) > 10):
|
||||
if self._lockfile.is_locked() and \
|
||||
(time() - getmtime(self._lockfile.lock_file)) > 10:
|
||||
self._lockfile.break_lock()
|
||||
|
||||
self._lockfile.acquire()
|
||||
|
@ -43,7 +43,7 @@ def generate(env):
|
||||
|
||||
env.Replace(
|
||||
_huge_sources_hook=_huge_sources_hook,
|
||||
ARCOM=env.get("ARCOM", "").replace(
|
||||
"$SOURCES", "${_huge_sources_hook(SOURCES)}"))
|
||||
ARCOM=env.get("ARCOM", "").replace("$SOURCES",
|
||||
"${_huge_sources_hook(SOURCES)}"))
|
||||
|
||||
return env
|
||||
|
@ -25,15 +25,12 @@ from platformio import util
|
||||
|
||||
class InoToCPPConverter(object):
|
||||
|
||||
PROTOTYPE_RE = re.compile(
|
||||
r"""^(
|
||||
PROTOTYPE_RE = re.compile(r"""^(
|
||||
(\s*[a-z_\d]+\*?){1,2} # return type
|
||||
(\s+[a-z_\d]+\s*) # name of prototype
|
||||
\([a-z_,\.\*\&\[\]\s\d]*\) # arguments
|
||||
)\s*\{ # must end with {
|
||||
""",
|
||||
re.X | re.M | re.I
|
||||
)
|
||||
""", re.X | re.M | re.I)
|
||||
DETECTMAIN_RE = re.compile(r"void\s+(setup|loop)\s*\(", re.M | re.I)
|
||||
PROTOPTRS_TPLRE = r"\([^&\(]*&(%s)[^\)]*\)"
|
||||
|
||||
@ -66,20 +63,18 @@ class InoToCPPConverter(object):
|
||||
split_pos = item['match'].start()
|
||||
break
|
||||
|
||||
match_ptrs = re.search(
|
||||
self.PROTOPTRS_TPLRE % ("|".join(prototype_names)),
|
||||
contents[:split_pos],
|
||||
re.M
|
||||
)
|
||||
match_ptrs = re.search(self.PROTOPTRS_TPLRE %
|
||||
("|".join(prototype_names)),
|
||||
contents[:split_pos], re.M)
|
||||
if match_ptrs:
|
||||
split_pos = contents.rfind("\n", 0, match_ptrs.start())
|
||||
|
||||
result.append(contents[:split_pos].strip())
|
||||
result.append("%s;" %
|
||||
";\n".join([p['match'].group(1) for p in prototypes]))
|
||||
result.append('#line %d "%s"' % (
|
||||
contents.count("\n", 0, split_pos) + 2,
|
||||
file_path.replace("\\", "/")))
|
||||
result.append('#line %d "%s"' %
|
||||
(contents.count("\n", 0, split_pos) + 2,
|
||||
file_path.replace("\\", "/")))
|
||||
result.append(contents[split_pos:].strip())
|
||||
|
||||
return result
|
||||
@ -106,8 +101,8 @@ class InoToCPPConverter(object):
|
||||
result.append('#line 1 "%s"' % file_path.replace("\\", "/"))
|
||||
|
||||
if is_first and prototypes:
|
||||
result += self.append_prototypes(
|
||||
file_path, contents, prototypes)
|
||||
result += self.append_prototypes(file_path, contents,
|
||||
prototypes)
|
||||
else:
|
||||
result.append(contents)
|
||||
is_first = False
|
||||
@ -187,9 +182,7 @@ def DumpIDEData(env):
|
||||
if env['PIOPLATFORM'] == "atmelavr":
|
||||
defines.append(
|
||||
"__AVR_%s__" % env.BoardConfig().get("build.mcu").upper()
|
||||
.replace("ATMEGA", "ATmega")
|
||||
.replace("ATTINY", "ATtiny")
|
||||
)
|
||||
.replace("ATMEGA", "ATmega").replace("ATTINY", "ATtiny"))
|
||||
return defines
|
||||
|
||||
LINTCCOM = "$CFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS"
|
||||
@ -257,8 +250,8 @@ def GetActualLDScript(env):
|
||||
return path
|
||||
|
||||
if script:
|
||||
env.Exit("Error: Could not find '%s' LD script in LDPATH '%s'" % (
|
||||
script, env.subst("$LIBPATH")))
|
||||
env.Exit("Error: Could not find '%s' LD script in LDPATH '%s'" %
|
||||
(script, env.subst("$LIBPATH")))
|
||||
|
||||
return None
|
||||
|
||||
|
@ -89,9 +89,7 @@ def LoadPioPlatform(env, variables):
|
||||
env.Replace(**{k: board_config.get("%s.%s" % (_opt, _val))})
|
||||
|
||||
if "build.ldscript" in board_config:
|
||||
env.Replace(
|
||||
LDSCRIPT_PATH=board_config.get("build.ldscript")
|
||||
)
|
||||
env.Replace(LDSCRIPT_PATH=board_config.get("build.ldscript"))
|
||||
|
||||
|
||||
def exists(_):
|
||||
|
@ -28,7 +28,6 @@ FRAMEWORK_PARAMETERS = {
|
||||
"serial_begin": "Serial.begin(9600)",
|
||||
"serial_end": "Serial.end()"
|
||||
},
|
||||
|
||||
"mbed": {
|
||||
"framework": "mbed.h",
|
||||
"serial_obj": "Serial pc(USBTX, USBRX);",
|
||||
@ -37,7 +36,6 @@ FRAMEWORK_PARAMETERS = {
|
||||
"serial_begin": "pc.baud(9600)",
|
||||
"serial_end": ""
|
||||
},
|
||||
|
||||
"energia": {
|
||||
"framework": "Energia.h",
|
||||
"serial_obj": "",
|
||||
@ -52,19 +50,14 @@ FRAMEWORK_PARAMETERS = {
|
||||
def ProcessTest(env):
|
||||
env.Append(
|
||||
CPPDEFINES=[
|
||||
"UNIT_TEST",
|
||||
"UNITY_INCLUDE_CONFIG_H"
|
||||
"UNIT_TEST", "UNITY_INCLUDE_CONFIG_H"
|
||||
],
|
||||
|
||||
CPPPATH=[
|
||||
join("$BUILD_DIR", "UnityTestLib")
|
||||
]
|
||||
)
|
||||
])
|
||||
unitylib = env.BuildLibrary(
|
||||
join("$BUILD_DIR", "UnityTestLib"),
|
||||
env.PioPlatform().get_package_dir("tool-unity")
|
||||
|
||||
)
|
||||
env.PioPlatform().get_package_dir("tool-unity"))
|
||||
env.Prepend(LIBS=[unitylib])
|
||||
|
||||
test_dir = env.subst("$PROJECTTEST_DIR")
|
||||
@ -75,8 +68,7 @@ def ProcessTest(env):
|
||||
src_filter += " +<%s%s>" % (env['PIOTEST'], sep)
|
||||
|
||||
return env.CollectBuildFiles(
|
||||
"$BUILDTEST_DIR", test_dir, src_filter=src_filter, duplicate=False
|
||||
)
|
||||
"$BUILDTEST_DIR", test_dir, src_filter=src_filter, duplicate=False)
|
||||
|
||||
|
||||
def GenerateOutputReplacement(env, destination_dir):
|
||||
@ -124,11 +116,11 @@ void output_complete(void)
|
||||
|
||||
framework = env.subst("$PIOFRAMEWORK").lower()
|
||||
if framework not in FRAMEWORK_PARAMETERS:
|
||||
env.Exit(
|
||||
"Error: %s framework doesn't support testing feature!" % framework)
|
||||
env.Exit("Error: %s framework doesn't support testing feature!" %
|
||||
framework)
|
||||
else:
|
||||
data = Template(TEMPLATECPP).substitute(
|
||||
FRAMEWORK_PARAMETERS[framework])
|
||||
data = Template(TEMPLATECPP).substitute(FRAMEWORK_PARAMETERS[
|
||||
framework])
|
||||
|
||||
tmp_file = join(destination_dir, "output_export.cpp")
|
||||
with open(tmp_file, "w") as f:
|
||||
|
@ -120,8 +120,7 @@ def AutodetectUploadPort(*args, **kwargs): # pylint: disable=unused-argument
|
||||
"\nWarning! Please install `99-platformio-udev.rules` and "
|
||||
"check that your board's PID and VID are listed in the rules."
|
||||
"\n https://raw.githubusercontent.com/platformio/platformio"
|
||||
"/develop/scripts/99-platformio-udev.rules\n"
|
||||
)
|
||||
"/develop/scripts/99-platformio-udev.rules\n")
|
||||
env.Replace(UPLOAD_PORT=_look_for_serial_port())
|
||||
|
||||
if env.subst("$UPLOAD_PORT"):
|
||||
|
@ -32,18 +32,14 @@ SRC_FILTER_DEFAULT = ["+<*>", "-<.git%s>" % sep, "-<svn%s>" % sep]
|
||||
def BuildProgram(env):
|
||||
|
||||
def _append_pio_macros():
|
||||
env.AppendUnique(
|
||||
CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format(
|
||||
*pioversion_to_intstr())])
|
||||
env.AppendUnique(CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format(
|
||||
*pioversion_to_intstr())])
|
||||
|
||||
_append_pio_macros()
|
||||
|
||||
# fix ASM handling under non-casitive OS
|
||||
if not case_sensitive_suffixes(".s", ".S"):
|
||||
env.Replace(
|
||||
AS="$CC",
|
||||
ASCOM="$ASPPCOM"
|
||||
)
|
||||
env.Replace(AS="$CC", ASCOM="$ASPPCOM")
|
||||
|
||||
# process extra flags from board
|
||||
if "BOARD" in env and "build.extra_flags" in env.BoardConfig():
|
||||
@ -55,7 +51,8 @@ def BuildProgram(env):
|
||||
|
||||
if env.get("PIOFRAMEWORK"):
|
||||
env.BuildFrameworks([
|
||||
f.lower().strip() for f in env['PIOFRAMEWORK'].split(",")])
|
||||
f.lower().strip() for f in env['PIOFRAMEWORK'].split(",")
|
||||
])
|
||||
|
||||
# restore PIO macros if it was deleted by framework
|
||||
_append_pio_macros()
|
||||
@ -66,18 +63,12 @@ def BuildProgram(env):
|
||||
# append specified LD_SCRIPT
|
||||
if ("LDSCRIPT_PATH" in env and
|
||||
not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
|
||||
env.Append(
|
||||
LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"']
|
||||
)
|
||||
env.Append(LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"'])
|
||||
|
||||
# enable "cyclic reference" for linker
|
||||
if env.get("LIBS", deplibs) and env.GetCompilerType() == "gcc":
|
||||
env.Prepend(
|
||||
_LIBFLAGS="-Wl,--start-group "
|
||||
)
|
||||
env.Append(
|
||||
_LIBFLAGS=" -Wl,--end-group"
|
||||
)
|
||||
env.Prepend(_LIBFLAGS="-Wl,--start-group ")
|
||||
env.Append(_LIBFLAGS=" -Wl,--end-group")
|
||||
|
||||
# Handle SRC_BUILD_FLAGS
|
||||
env.ProcessFlags(env.get("SRC_BUILD_FLAGS"))
|
||||
@ -96,14 +87,11 @@ def BuildProgram(env):
|
||||
env.Append(PIOBUILDFILES=env.ProcessTest())
|
||||
|
||||
if not env['PIOBUILDFILES'] and not COMMAND_LINE_TARGETS:
|
||||
env.Exit(
|
||||
"Error: Nothing to build. Please put your source code files "
|
||||
"to '%s' folder" % env.subst("$PROJECTSRC_DIR"))
|
||||
env.Exit("Error: Nothing to build. Please put your source code files "
|
||||
"to '%s' folder" % env.subst("$PROJECTSRC_DIR"))
|
||||
|
||||
program = env.Program(
|
||||
join("$BUILD_DIR", env.subst("$PROGNAME")),
|
||||
env['PIOBUILDFILES']
|
||||
)
|
||||
join("$BUILD_DIR", env.subst("$PROGNAME")), env['PIOBUILDFILES'])
|
||||
|
||||
if set(["upload", "uploadlazy", "program"]) & set(COMMAND_LINE_TARGETS):
|
||||
env.AddPostAction(program, env.CheckUploadSize)
|
||||
@ -210,8 +198,11 @@ def VariantDirWrap(env, variant_dir, src_dir, duplicate=False):
|
||||
env.VariantDir(variant_dir, src_dir, duplicate)
|
||||
|
||||
|
||||
def CollectBuildFiles(env, variant_dir, src_dir,
|
||||
src_filter=None, duplicate=False):
|
||||
def CollectBuildFiles(env,
|
||||
variant_dir,
|
||||
src_dir,
|
||||
src_filter=None,
|
||||
duplicate=False):
|
||||
sources = []
|
||||
variants = []
|
||||
|
||||
@ -239,9 +230,8 @@ def BuildFrameworks(env, frameworks):
|
||||
return
|
||||
|
||||
if "BOARD" not in env:
|
||||
env.Exit(
|
||||
"Please specify `board` in `platformio.ini` to use "
|
||||
"with '%s' framework" % ", ".join(frameworks))
|
||||
env.Exit("Please specify `board` in `platformio.ini` to use "
|
||||
"with '%s' framework" % ", ".join(frameworks))
|
||||
|
||||
board_frameworks = env.BoardConfig().get("frameworks", [])
|
||||
if frameworks == ["platformio"]:
|
||||
|
@ -48,15 +48,21 @@ def cli(query, installed, json_output): # pylint: disable=R0912
|
||||
click.echo("Platform: ", nl=False)
|
||||
click.secho(platform, bold=True)
|
||||
click.echo("-" * terminal_width)
|
||||
click.echo(BOARDLIST_TPL.format(
|
||||
type=click.style("ID", fg="cyan"), mcu="MCU",
|
||||
frequency="Frequency", flash="Flash", ram="RAM", name="Name"))
|
||||
click.echo(
|
||||
BOARDLIST_TPL.format(
|
||||
type=click.style(
|
||||
"ID", fg="cyan"),
|
||||
mcu="MCU",
|
||||
frequency="Frequency",
|
||||
flash="Flash",
|
||||
ram="RAM",
|
||||
name="Name"))
|
||||
click.echo("-" * terminal_width)
|
||||
|
||||
for board in sorted(pboards, key=lambda b: b['id']):
|
||||
if query:
|
||||
search_data = "%s %s" % (
|
||||
board['id'], json.dumps(board).lower())
|
||||
search_data = "%s %s" % (board['id'],
|
||||
json.dumps(board).lower())
|
||||
if query.lower() not in search_data.lower():
|
||||
continue
|
||||
|
||||
@ -71,11 +77,15 @@ def cli(query, installed, json_output): # pylint: disable=R0912
|
||||
else:
|
||||
ram_size = "%dB" % ram_size
|
||||
|
||||
click.echo(BOARDLIST_TPL.format(
|
||||
type=click.style(board['id'], fg="cyan"),
|
||||
mcu=board['mcu'],
|
||||
frequency="%dMhz" % (board['fcpu'] / 1000000),
|
||||
flash=flash_size, ram=ram_size, name=board['name']))
|
||||
click.echo(
|
||||
BOARDLIST_TPL.format(
|
||||
type=click.style(
|
||||
board['id'], fg="cyan"),
|
||||
mcu=board['mcu'],
|
||||
frequency="%dMhz" % (board['fcpu'] / 1000000),
|
||||
flash=flash_size,
|
||||
ram=ram_size,
|
||||
name=board['name']))
|
||||
|
||||
|
||||
def _get_boards(installed=False):
|
||||
|
@ -55,19 +55,37 @@ def validate_path(ctx, param, value): # pylint: disable=W0613
|
||||
@click.argument("src", nargs=-1, callback=validate_path)
|
||||
@click.option("-l", "--lib", multiple=True, callback=validate_path)
|
||||
@click.option("--exclude", multiple=True)
|
||||
@click.option("-b", "--board", multiple=True, metavar="ID",
|
||||
callback=validate_boards)
|
||||
@click.option("--build-dir", default=mkdtemp,
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||
writable=True, resolve_path=True))
|
||||
@click.option(
|
||||
"-b", "--board", multiple=True, metavar="ID", callback=validate_boards)
|
||||
@click.option(
|
||||
"--build-dir",
|
||||
default=mkdtemp,
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=False,
|
||||
dir_okay=True,
|
||||
writable=True,
|
||||
resolve_path=True))
|
||||
@click.option("--keep-build-dir", is_flag=True)
|
||||
@click.option("--project-conf",
|
||||
type=click.Path(exists=True, file_okay=True, dir_okay=False,
|
||||
readable=True, resolve_path=True))
|
||||
@click.option(
|
||||
"--project-conf",
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=True,
|
||||
dir_okay=False,
|
||||
readable=True,
|
||||
resolve_path=True))
|
||||
@click.option("-v", "--verbose", is_flag=True)
|
||||
@click.pass_context
|
||||
def cli(ctx, src, lib, exclude, board, # pylint: disable=R0913
|
||||
build_dir, keep_build_dir, project_conf, verbose):
|
||||
def cli(ctx, # pylint: disable=R0913
|
||||
src,
|
||||
lib,
|
||||
exclude,
|
||||
board,
|
||||
build_dir,
|
||||
keep_build_dir,
|
||||
project_conf,
|
||||
verbose):
|
||||
|
||||
if not src:
|
||||
src = getenv("PLATFORMIO_CI_SRC", "").split(":")
|
||||
@ -102,9 +120,8 @@ def cli(ctx, src, lib, exclude, board, # pylint: disable=R0913
|
||||
finally:
|
||||
if not keep_build_dir:
|
||||
rmtree(
|
||||
build_dir, onerror=lambda action, name, exc:
|
||||
(chmod(name, stat.S_IWRITE), remove(name))
|
||||
)
|
||||
build_dir,
|
||||
onerror=lambda action, name, exc: (chmod(name, stat.S_IWRITE), remove(name)))
|
||||
|
||||
|
||||
def _clean_dir(dirpath):
|
||||
@ -113,10 +130,7 @@ def _clean_dir(dirpath):
|
||||
|
||||
|
||||
def _copy_contents(dst_dir, contents):
|
||||
items = {
|
||||
"dirs": set(),
|
||||
"files": set()
|
||||
}
|
||||
items = {"dirs": set(), "files": set()}
|
||||
|
||||
for path in contents:
|
||||
if isdir(path):
|
||||
|
@ -37,24 +37,35 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613
|
||||
assert not unknown_boards
|
||||
return value
|
||||
except AssertionError:
|
||||
raise click.BadParameter(
|
||||
"%s. Please search for the board ID using "
|
||||
"`platformio boards` command" % ", ".join(unknown_boards))
|
||||
raise click.BadParameter("%s. Please search for the board ID using "
|
||||
"`platformio boards` command" %
|
||||
", ".join(unknown_boards))
|
||||
|
||||
|
||||
@click.command("init", short_help="Initialize new PlatformIO based project")
|
||||
@click.option("--project-dir", "-d", default=getcwd,
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||
writable=True, resolve_path=True))
|
||||
@click.option("-b", "--board", multiple=True, metavar="ID",
|
||||
callback=validate_boards)
|
||||
@click.option("--ide",
|
||||
type=click.Choice(ProjectGenerator.get_supported_ides()))
|
||||
@click.option(
|
||||
"--project-dir",
|
||||
"-d",
|
||||
default=getcwd,
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=False,
|
||||
dir_okay=True,
|
||||
writable=True,
|
||||
resolve_path=True))
|
||||
@click.option(
|
||||
"-b", "--board", multiple=True, metavar="ID", callback=validate_boards)
|
||||
@click.option(
|
||||
"--ide", type=click.Choice(ProjectGenerator.get_supported_ides()))
|
||||
@click.option("--enable-auto-uploading", is_flag=True)
|
||||
@click.option("--env-prefix", default="")
|
||||
@click.pass_context
|
||||
def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
enable_auto_uploading, env_prefix):
|
||||
def cli(ctx, # pylint: disable=R0913
|
||||
project_dir,
|
||||
board,
|
||||
ide,
|
||||
enable_auto_uploading,
|
||||
env_prefix):
|
||||
|
||||
if project_dir == getcwd():
|
||||
click.secho("\nThe current working directory", fg="yellow", nl=False)
|
||||
@ -63,18 +74,20 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
"will be used for project.\n"
|
||||
"You can specify another project directory via\n"
|
||||
"`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
|
||||
fg="yellow"
|
||||
)
|
||||
fg="yellow")
|
||||
click.echo("")
|
||||
|
||||
click.echo("The next files/directories will be created in %s" %
|
||||
click.style(project_dir, fg="cyan"))
|
||||
click.style(
|
||||
project_dir, fg="cyan"))
|
||||
click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" %
|
||||
click.style("platformio.ini", fg="cyan"))
|
||||
click.echo("%s - Put your source files here" %
|
||||
click.style("src", fg="cyan"))
|
||||
click.style(
|
||||
"platformio.ini", fg="cyan"))
|
||||
click.echo("%s - Put your source files here" % click.style(
|
||||
"src", fg="cyan"))
|
||||
click.echo("%s - Put here project specific (private) libraries" %
|
||||
click.style("lib", fg="cyan"))
|
||||
click.style(
|
||||
"lib", fg="cyan"))
|
||||
|
||||
if (app.get_setting("enable_prompts") and
|
||||
not click.confirm("Do you want to continue?")):
|
||||
@ -83,10 +96,8 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
init_base_project(project_dir)
|
||||
|
||||
if board:
|
||||
fill_project_envs(
|
||||
ctx, project_dir, board,
|
||||
enable_auto_uploading, env_prefix, ide is not None
|
||||
)
|
||||
fill_project_envs(ctx, project_dir, board, enable_auto_uploading,
|
||||
env_prefix, ide is not None)
|
||||
|
||||
if ide:
|
||||
if not board:
|
||||
@ -102,8 +113,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
"However, the IDE features (code autocompletion, syntax "
|
||||
"linter) have been configured for the first board '%s' from "
|
||||
"your list '%s'." % (board[0], ", ".join(board)),
|
||||
fg="yellow"
|
||||
)
|
||||
fg="yellow")
|
||||
pg = ProjectGenerator(project_dir, ide, board[0])
|
||||
pg.generate()
|
||||
|
||||
@ -116,8 +126,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
"`platformio run --target clean` - clean project (remove compiled "
|
||||
"files)\n"
|
||||
"`platformio run --help` - additional information",
|
||||
fg="green"
|
||||
)
|
||||
fg="green")
|
||||
|
||||
|
||||
def get_first_board(project_dir):
|
||||
@ -132,8 +141,9 @@ def get_first_board(project_dir):
|
||||
|
||||
def init_base_project(project_dir):
|
||||
if not util.is_platformio_project(project_dir):
|
||||
copyfile(join(util.get_source_dir(), "projectconftpl.ini"),
|
||||
join(project_dir, "platformio.ini"))
|
||||
copyfile(
|
||||
join(util.get_source_dir(), "projectconftpl.ini"),
|
||||
join(project_dir, "platformio.ini"))
|
||||
|
||||
lib_dir = join(project_dir, "lib")
|
||||
src_dir = join(project_dir, "src")
|
||||
@ -275,8 +285,8 @@ def init_cvs_ignore(project_dir):
|
||||
|
||||
|
||||
def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals
|
||||
ctx, project_dir, board_ids, enable_auto_uploading,
|
||||
env_prefix, force_download):
|
||||
ctx, project_dir, board_ids, enable_auto_uploading, env_prefix,
|
||||
force_download):
|
||||
installed_boards = PlatformManager().get_installed_boards()
|
||||
content = []
|
||||
used_boards = []
|
||||
@ -291,8 +301,8 @@ def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals
|
||||
|
||||
for id_ in board_ids:
|
||||
manifest = None
|
||||
for boards in (
|
||||
installed_boards, PlatformManager.get_registered_boards()):
|
||||
for boards in (installed_boards,
|
||||
PlatformManager.get_registered_boards()):
|
||||
for b in boards:
|
||||
if b['id'] == id_:
|
||||
manifest = b
|
||||
@ -329,10 +339,10 @@ def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals
|
||||
|
||||
def _install_dependent_platforms(ctx, platforms):
|
||||
installed_platforms = [
|
||||
p['name'] for p in PlatformManager().get_installed()]
|
||||
p['name'] for p in PlatformManager().get_installed()
|
||||
]
|
||||
if set(platforms) <= set(installed_platforms):
|
||||
return
|
||||
ctx.invoke(
|
||||
cli_platform_install,
|
||||
platforms=list(set(platforms) - set(installed_platforms))
|
||||
)
|
||||
platforms=list(set(platforms) - set(installed_platforms)))
|
||||
|
@ -33,14 +33,26 @@ from platformio.managers.platform import PlatformFactory
|
||||
@click.option("-e", "--environment", multiple=True)
|
||||
@click.option("-t", "--target", multiple=True)
|
||||
@click.option("--upload-port")
|
||||
@click.option("-d", "--project-dir", default=getcwd,
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||
writable=True, resolve_path=True))
|
||||
@click.option(
|
||||
"-d",
|
||||
"--project-dir",
|
||||
default=getcwd,
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=False,
|
||||
dir_okay=True,
|
||||
writable=True,
|
||||
resolve_path=True))
|
||||
@click.option("-v", "--verbose", is_flag=True)
|
||||
@click.option("--disable-auto-clean", is_flag=True)
|
||||
@click.pass_context
|
||||
def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
project_dir, verbose, disable_auto_clean):
|
||||
def cli(ctx, # pylint: disable=R0913,R0914
|
||||
environment,
|
||||
target,
|
||||
upload_port,
|
||||
project_dir,
|
||||
verbose,
|
||||
disable_auto_clean):
|
||||
assert check_project_envs(project_dir, environment)
|
||||
with util.cd(project_dir):
|
||||
# clean obsolete .pioenvs dir
|
||||
@ -59,7 +71,8 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
if config.has_option("platformio", "env_default"):
|
||||
env_default = [
|
||||
e.strip()
|
||||
for e in config.get("platformio", "env_default").split(",")]
|
||||
for e in config.get("platformio", "env_default").split(",")
|
||||
]
|
||||
|
||||
results = []
|
||||
for section in config.sections():
|
||||
@ -71,9 +84,10 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
raise exception.InvalidEnvName(section)
|
||||
|
||||
envname = section[4:]
|
||||
if ((environment and envname not in environment) or
|
||||
(not environment and env_default and
|
||||
envname not in env_default)):
|
||||
skipenv = any([environment and envname not in environment,
|
||||
not environment and env_default and
|
||||
envname not in env_default])
|
||||
if skipenv:
|
||||
# echo("Skipped %s environment" % style(envname, fg="yellow"))
|
||||
continue
|
||||
|
||||
@ -86,8 +100,8 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
if "piotest" not in options and "piotest" in ctx.meta:
|
||||
options['piotest'] = ctx.meta['piotest']
|
||||
|
||||
ep = EnvironmentProcessor(
|
||||
ctx, envname, options, target, upload_port, verbose)
|
||||
ep = EnvironmentProcessor(ctx, envname, options, target,
|
||||
upload_port, verbose)
|
||||
results.append(ep.process())
|
||||
|
||||
if not all(results):
|
||||
@ -96,10 +110,7 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
|
||||
class EnvironmentProcessor(object):
|
||||
|
||||
REMAPED_OPTIONS = {
|
||||
"FRAMEWORK": "PIOFRAMEWORK",
|
||||
"PLATFORM": "PIOPLATFORM"
|
||||
}
|
||||
REMAPED_OPTIONS = {"FRAMEWORK": "PIOFRAMEWORK", "PLATFORM": "PIOPLATFORM"}
|
||||
|
||||
RENAMED_OPTIONS = {
|
||||
"INSTALL_LIBS": "LIB_INSTALL",
|
||||
@ -107,8 +118,13 @@ class EnvironmentProcessor(object):
|
||||
"LIB_USE": "LIB_FORCE"
|
||||
}
|
||||
|
||||
def __init__(self, cmd_ctx, name, options, # pylint: disable=R0913
|
||||
targets, upload_port, verbose):
|
||||
def __init__(self, # pylint: disable=R0913
|
||||
cmd_ctx,
|
||||
name,
|
||||
options,
|
||||
targets,
|
||||
upload_port,
|
||||
verbose):
|
||||
self.cmd_ctx = cmd_ctx
|
||||
self.name = name
|
||||
self.options = self._validate_options(options)
|
||||
@ -121,21 +137,21 @@ class EnvironmentProcessor(object):
|
||||
start_time = time()
|
||||
|
||||
click.echo("[%s] Processing %s (%s)" % (
|
||||
datetime.now().strftime("%c"),
|
||||
click.style(self.name, fg="cyan", bold=True),
|
||||
", ".join(["%s: %s" % (k, v) for k, v in self.options.iteritems()])
|
||||
))
|
||||
datetime.now().strftime("%c"), click.style(
|
||||
self.name, fg="cyan", bold=True), ", ".join(
|
||||
["%s: %s" % (k, v) for k, v in self.options.iteritems()])))
|
||||
click.secho("-" * terminal_width, bold=True)
|
||||
|
||||
result = self._run()
|
||||
|
||||
is_error = result['returncode'] != 0
|
||||
if is_error or "piotest_processor" not in self.cmd_ctx.meta:
|
||||
print_header("[%s] Took %.2f seconds" % (
|
||||
(click.style("ERROR", fg="red", bold=True) if is_error
|
||||
else click.style("SUCCESS", fg="green", bold=True)),
|
||||
time() - start_time
|
||||
), is_error=is_error)
|
||||
print_header(
|
||||
"[%s] Took %.2f seconds" % ((click.style(
|
||||
"ERROR", fg="red", bold=True) if is_error else click.style(
|
||||
"SUCCESS", fg="green", bold=True)),
|
||||
time() - start_time),
|
||||
is_error=is_error)
|
||||
|
||||
return not is_error
|
||||
|
||||
@ -148,10 +164,8 @@ class EnvironmentProcessor(object):
|
||||
click.secho(
|
||||
"Warning! `%s` option is deprecated and will be "
|
||||
"removed in the next release! Please use "
|
||||
"`%s` instead." % (
|
||||
k, self.RENAMED_OPTIONS[_k].lower()),
|
||||
fg="yellow"
|
||||
)
|
||||
"`%s` instead." % (k, self.RENAMED_OPTIONS[_k].lower()),
|
||||
fg="yellow")
|
||||
k = self.RENAMED_OPTIONS[_k].lower()
|
||||
result[k] = v
|
||||
return result
|
||||
@ -249,12 +263,10 @@ def check_project_envs(project_dir, environments):
|
||||
if not config.sections():
|
||||
raise exception.ProjectEnvsNotAvailable()
|
||||
|
||||
known = set([s[4:] for s in config.sections()
|
||||
if s.startswith("env:")])
|
||||
known = set([s[4:] for s in config.sections() if s.startswith("env:")])
|
||||
unknown = set(environments) - known
|
||||
if unknown:
|
||||
raise exception.UnknownEnvNames(
|
||||
", ".join(unknown), ", ".join(known))
|
||||
raise exception.UnknownEnvNames(", ".join(unknown), ", ".join(known))
|
||||
return True
|
||||
|
||||
|
||||
|
@ -46,41 +46,72 @@ def serialports_list(json_output):
|
||||
|
||||
|
||||
if int(PYSERIAL_VERSION[0]) == 3:
|
||||
|
||||
@cli.command("monitor", short_help="Monitor Serial port")
|
||||
@click.option("--port", "-p", help="Port, a number or a device name")
|
||||
@click.option("--baud", "-b", type=int, default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@click.option("--parity", default="N",
|
||||
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@click.option("--rtscts", is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@click.option("--xonxoff", is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@click.option("--rts", default=None, type=click.Choice(["0", "1"]),
|
||||
help="Set initial RTS line state")
|
||||
@click.option("--dtr", default=None, type=click.Choice(["0", "1"]),
|
||||
help="Set initial DTR line state")
|
||||
@click.option("--echo", is_flag=True,
|
||||
help="Enable local echo, default=Off")
|
||||
@click.option("--encoding", default="UTF-8",
|
||||
help="Set the encoding for the serial port (e.g. hexlify, "
|
||||
"Latin1, UTF-8), default: UTF-8")
|
||||
@click.option("--filter", "-f", multiple=True,
|
||||
help="Add text transformation")
|
||||
@click.option("--eol", default="CRLF",
|
||||
type=click.Choice(["CR", "LF", "CRLF"]),
|
||||
help="End of line mode, default=CRLF")
|
||||
@click.option("--raw", is_flag=True,
|
||||
help="Do not apply any encodings/transformations")
|
||||
@click.option("--exit-char", type=int, default=29,
|
||||
help="ASCII code of special character that is used to exit "
|
||||
"the application, default=29 (DEC)")
|
||||
@click.option("--menu-char", type=int, default=20,
|
||||
help="ASCII code of special character that is used to "
|
||||
"control miniterm (menu), default=20 (DEC)")
|
||||
@click.option("--quiet", is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
@click.option(
|
||||
"--baud",
|
||||
"-b",
|
||||
type=int,
|
||||
default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@click.option(
|
||||
"--parity",
|
||||
default="N",
|
||||
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@click.option(
|
||||
"--rtscts",
|
||||
is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@click.option(
|
||||
"--xonxoff",
|
||||
is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@click.option(
|
||||
"--rts",
|
||||
default=None,
|
||||
type=click.Choice(["0", "1"]),
|
||||
help="Set initial RTS line state")
|
||||
@click.option(
|
||||
"--dtr",
|
||||
default=None,
|
||||
type=click.Choice(["0", "1"]),
|
||||
help="Set initial DTR line state")
|
||||
@click.option(
|
||||
"--echo", is_flag=True, help="Enable local echo, default=Off")
|
||||
@click.option(
|
||||
"--encoding",
|
||||
default="UTF-8",
|
||||
help="Set the encoding for the serial port (e.g. hexlify, "
|
||||
"Latin1, UTF-8), default: UTF-8")
|
||||
@click.option(
|
||||
"--filter", "-f", multiple=True, help="Add text transformation")
|
||||
@click.option(
|
||||
"--eol",
|
||||
default="CRLF",
|
||||
type=click.Choice(["CR", "LF", "CRLF"]),
|
||||
help="End of line mode, default=CRLF")
|
||||
@click.option(
|
||||
"--raw",
|
||||
is_flag=True,
|
||||
help="Do not apply any encodings/transformations")
|
||||
@click.option(
|
||||
"--exit-char",
|
||||
type=int,
|
||||
default=29,
|
||||
help="ASCII code of special character that is used to exit "
|
||||
"the application, default=29 (DEC)")
|
||||
@click.option(
|
||||
"--menu-char",
|
||||
type=int,
|
||||
default=20,
|
||||
help="ASCII code of special character that is used to "
|
||||
"control miniterm (menu), default=20 (DEC)")
|
||||
@click.option(
|
||||
"--quiet",
|
||||
is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
def serialports_monitor(**kwargs):
|
||||
if not kwargs['port']:
|
||||
for item in get_serialports():
|
||||
@ -107,47 +138,78 @@ if int(PYSERIAL_VERSION[0]) == 3:
|
||||
default_port=kwargs['port'],
|
||||
default_baudrate=kwargs['baud'],
|
||||
default_rts=kwargs['rts'],
|
||||
default_dtr=kwargs['dtr']
|
||||
)
|
||||
default_dtr=kwargs['dtr'])
|
||||
except Exception as e: # pylint: disable=W0702
|
||||
raise MinitermException(e)
|
||||
else:
|
||||
|
||||
@cli.command("monitor", short_help="Monitor Serial port")
|
||||
@click.option("--port", "-p", help="Port, a number or a device name")
|
||||
@click.option("--baud", "-b", type=int, default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@click.option("--parity", default="N",
|
||||
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@click.option("--rtscts", is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@click.option("--xonxoff", is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@click.option("--rts", default=None, type=click.Choice(["0", "1"]),
|
||||
help="Set initial RTS line state, default=0")
|
||||
@click.option("--dtr", default=None, type=click.Choice(["0", "1"]),
|
||||
help="Set initial DTR line state, default=0")
|
||||
@click.option("--echo", is_flag=True,
|
||||
help="Enable local echo, default=Off")
|
||||
@click.option("--cr", is_flag=True,
|
||||
help="Do not send CR+LF, send CR only, default=Off")
|
||||
@click.option("--lf", is_flag=True,
|
||||
help="Do not send CR+LF, send LF only, default=Off")
|
||||
@click.option("--debug", "-d", count=True,
|
||||
help="""Debug received data (escape non-printable chars)
|
||||
@click.option(
|
||||
"--baud",
|
||||
"-b",
|
||||
type=int,
|
||||
default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@click.option(
|
||||
"--parity",
|
||||
default="N",
|
||||
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@click.option(
|
||||
"--rtscts",
|
||||
is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@click.option(
|
||||
"--xonxoff",
|
||||
is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@click.option(
|
||||
"--rts",
|
||||
default=None,
|
||||
type=click.Choice(["0", "1"]),
|
||||
help="Set initial RTS line state, default=0")
|
||||
@click.option(
|
||||
"--dtr",
|
||||
default=None,
|
||||
type=click.Choice(["0", "1"]),
|
||||
help="Set initial DTR line state, default=0")
|
||||
@click.option(
|
||||
"--echo", is_flag=True, help="Enable local echo, default=Off")
|
||||
@click.option(
|
||||
"--cr",
|
||||
is_flag=True,
|
||||
help="Do not send CR+LF, send CR only, default=Off")
|
||||
@click.option(
|
||||
"--lf",
|
||||
is_flag=True,
|
||||
help="Do not send CR+LF, send LF only, default=Off")
|
||||
@click.option(
|
||||
"--debug",
|
||||
"-d",
|
||||
count=True,
|
||||
help="""Debug received data (escape non-printable chars)
|
||||
# --debug can be given multiple times:
|
||||
# 0: just print what is received
|
||||
# 1: escape non-printable characters, do newlines as unusual
|
||||
# 2: escape non-printable characters, newlines too
|
||||
# 3: hex dump everything""")
|
||||
@click.option("--exit-char", type=int, default=29,
|
||||
help="ASCII code of special character that is used to exit "
|
||||
"the application, default=29 (DEC)")
|
||||
@click.option("--menu-char", type=int, default=20,
|
||||
help="ASCII code of special character that is used to "
|
||||
"control miniterm (menu), default=20 (DEC)")
|
||||
@click.option("--quiet", is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
@click.option(
|
||||
"--exit-char",
|
||||
type=int,
|
||||
default=29,
|
||||
help="ASCII code of special character that is used to exit "
|
||||
"the application, default=29 (DEC)")
|
||||
@click.option(
|
||||
"--menu-char",
|
||||
type=int,
|
||||
default=20,
|
||||
help="ASCII code of special character that is used to "
|
||||
"control miniterm (menu), default=20 (DEC)")
|
||||
@click.option(
|
||||
"--quiet",
|
||||
is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
def serialports_monitor(**kwargs):
|
||||
sys.argv = app.get_session_var("command_ctx").args[1:]
|
||||
|
||||
|
@ -29,12 +29,14 @@ def settings_get(name):
|
||||
list_tpl = "{name:<40} {value:<35} {description}"
|
||||
terminal_width, _ = click.get_terminal_size()
|
||||
|
||||
click.echo(list_tpl.format(
|
||||
name=click.style("Name", fg="cyan"),
|
||||
value=(click.style("Value", fg="green") +
|
||||
click.style(" [Default]", fg="yellow")),
|
||||
description="Description"
|
||||
))
|
||||
click.echo(
|
||||
list_tpl.format(
|
||||
name=click.style(
|
||||
"Name", fg="cyan"),
|
||||
value=(click.style(
|
||||
"Value", fg="green") + click.style(
|
||||
" [Default]", fg="yellow")),
|
||||
description="Description"))
|
||||
click.echo("-" * terminal_width)
|
||||
|
||||
for _name, _data in sorted(app.DEFAULT_SETTINGS.items()):
|
||||
@ -55,11 +57,12 @@ def settings_get(name):
|
||||
else:
|
||||
_value_str += click.style(" ", fg="yellow")
|
||||
|
||||
click.echo(list_tpl.format(
|
||||
name=click.style(_name, fg="cyan"),
|
||||
value=_value_str,
|
||||
description=_data['description']
|
||||
))
|
||||
click.echo(
|
||||
list_tpl.format(
|
||||
name=click.style(
|
||||
_name, fg="cyan"),
|
||||
value=_value_str,
|
||||
description=_data['description']))
|
||||
|
||||
|
||||
@cli.command("set", short_help="Set new value for the setting")
|
||||
|
@ -32,9 +32,16 @@ from platformio.managers.platform import PlatformFactory
|
||||
@click.option("--environment", "-e", multiple=True, metavar="<environment>")
|
||||
@click.option("--skip", multiple=True, metavar="<pattern>")
|
||||
@click.option("--upload-port", metavar="<upload port>")
|
||||
@click.option("-d", "--project-dir", default=getcwd,
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||
writable=True, resolve_path=True))
|
||||
@click.option(
|
||||
"-d",
|
||||
"--project-dir",
|
||||
default=getcwd,
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=False,
|
||||
dir_okay=True,
|
||||
writable=True,
|
||||
resolve_path=True))
|
||||
@click.option("--verbose", "-v", is_flag=True)
|
||||
@click.pass_context
|
||||
def cli(ctx, environment, skip, upload_port, project_dir, verbose):
|
||||
@ -85,16 +92,17 @@ def cli(ctx, environment, skip, upload_port, project_dir, verbose):
|
||||
elif status is None:
|
||||
status_str = click.style("IGNORED", fg="yellow")
|
||||
|
||||
click.echo("test:%s/env:%s\t%s" % (
|
||||
click.style(testname, fg="yellow"),
|
||||
click.style(envname, fg="cyan"),
|
||||
status_str), err=status is False)
|
||||
click.echo(
|
||||
"test:%s/env:%s\t%s" % (click.style(
|
||||
testname, fg="yellow"), click.style(
|
||||
envname, fg="cyan"), status_str),
|
||||
err=status is False)
|
||||
|
||||
print_header("[%s] Took %.2f seconds" % (
|
||||
(click.style("PASSED", fg="green", bold=True) if passed
|
||||
else click.style("FAILED", fg="red", bold=True)),
|
||||
time() - start_time
|
||||
), is_error=not passed)
|
||||
print_header(
|
||||
"[%s] Took %.2f seconds" % ((click.style(
|
||||
"PASSED", fg="green", bold=True) if passed else click.style(
|
||||
"FAILED", fg="red", bold=True)), time() - start_time),
|
||||
is_error=not passed)
|
||||
|
||||
if not passed:
|
||||
raise exception.ReturnErrorCode()
|
||||
@ -122,41 +130,42 @@ class TestProcessor(object):
|
||||
return self._run_hardware_test()
|
||||
|
||||
def _progress(self, text, is_error=False):
|
||||
print_header("[test::%s] %s" % (
|
||||
click.style(self.test_name, fg="yellow", bold=True),
|
||||
text
|
||||
), is_error=is_error)
|
||||
print_header(
|
||||
"[test::%s] %s" % (click.style(
|
||||
self.test_name, fg="yellow", bold=True), text),
|
||||
is_error=is_error)
|
||||
click.echo()
|
||||
|
||||
def _build_or_upload(self, target):
|
||||
if self.test_name != "*":
|
||||
self.cmd_ctx.meta['piotest'] = self.test_name
|
||||
return self.cmd_ctx.invoke(
|
||||
cmd_run, project_dir=self.options['project_dir'],
|
||||
cmd_run,
|
||||
project_dir=self.options['project_dir'],
|
||||
upload_port=self.options['upload_port'],
|
||||
verbose=self.options['verbose'],
|
||||
environment=[self.env_name],
|
||||
target=target
|
||||
)
|
||||
target=target)
|
||||
|
||||
def _run_hardware_test(self):
|
||||
click.echo("If you don't see any output for the first 10 secs, "
|
||||
"please reset board (press reset button)")
|
||||
click.echo()
|
||||
ser = serial.Serial(self.get_serial_port(), self.SERIAL_BAUDRATE,
|
||||
timeout=self.SERIAL_TIMEOUT)
|
||||
ser = serial.Serial(
|
||||
self.get_serial_port(),
|
||||
self.SERIAL_BAUDRATE,
|
||||
timeout=self.SERIAL_TIMEOUT)
|
||||
passed = True
|
||||
while True:
|
||||
line = ser.readline().strip()
|
||||
if not line:
|
||||
continue
|
||||
if line.endswith(":PASS"):
|
||||
click.echo("%s\t%s" % (
|
||||
line[:-5], click.style("PASSED", fg="green")))
|
||||
click.echo("%s\t%s" % (line[:-5], click.style(
|
||||
"PASSED", fg="green")))
|
||||
elif ":FAIL:" in line:
|
||||
passed = False
|
||||
click.echo("%s\t%s" % (
|
||||
line, click.style("FAILED", fg="red")))
|
||||
click.echo("%s\t%s" % (line, click.style("FAILED", fg="red")))
|
||||
else:
|
||||
click.echo(line)
|
||||
if all([l in line for l in ("Tests", "Failures", "Ignored")]):
|
||||
|
@ -19,8 +19,8 @@ from platformio.commands.platform import platform_update as cmd_platform_update
|
||||
from platformio.managers.lib import LibraryManager
|
||||
|
||||
|
||||
@click.command("update",
|
||||
short_help="Update installed Platforms, Packages and Libraries")
|
||||
@click.command(
|
||||
"update", short_help="Update installed Platforms, Packages and Libraries")
|
||||
@click.option(
|
||||
"-c",
|
||||
"--only-check",
|
||||
|
@ -22,26 +22,22 @@ import requests
|
||||
from platformio import VERSION, __version__, exception, util
|
||||
|
||||
|
||||
@click.command("upgrade",
|
||||
short_help="Upgrade PlatformIO to the latest version")
|
||||
@click.command(
|
||||
"upgrade", short_help="Upgrade PlatformIO to the latest version")
|
||||
def cli():
|
||||
latest = get_latest_version()
|
||||
if __version__ == latest:
|
||||
return click.secho(
|
||||
"You're up-to-date!\nPlatformIO %s is currently the "
|
||||
"newest version available." % __version__, fg="green"
|
||||
)
|
||||
"newest version available." % __version__,
|
||||
fg="green")
|
||||
else:
|
||||
click.secho("Please wait while upgrading PlatformIO ...",
|
||||
fg="yellow")
|
||||
click.secho("Please wait while upgrading PlatformIO ...", fg="yellow")
|
||||
|
||||
to_develop = not all([c.isdigit() for c in latest if c != "."])
|
||||
cmds = (
|
||||
["pip", "install", "--upgrade",
|
||||
"https://github.com/platformio/platformio/archive/develop.zip"
|
||||
if to_develop else "platformio"],
|
||||
["platformio", "--version"]
|
||||
)
|
||||
cmds = (["pip", "install", "--upgrade",
|
||||
"https://github.com/platformio/platformio/archive/develop.zip"
|
||||
if to_develop else "platformio"], ["platformio", "--version"])
|
||||
|
||||
cmd = None
|
||||
r = None
|
||||
@ -63,21 +59,19 @@ def cli():
|
||||
actual_version = r['out'].strip().split("version", 1)[1].strip()
|
||||
click.secho(
|
||||
"PlatformIO has been successfully upgraded to %s" %
|
||||
actual_version, fg="green")
|
||||
actual_version,
|
||||
fg="green")
|
||||
click.echo("Release notes: ", nl=False)
|
||||
click.secho("http://docs.platformio.org/en/stable/history.html",
|
||||
fg="cyan")
|
||||
click.secho(
|
||||
"http://docs.platformio.org/en/stable/history.html", fg="cyan")
|
||||
except Exception as e: # pylint: disable=W0703
|
||||
if not r:
|
||||
raise exception.UpgradeError(
|
||||
"\n".join([str(cmd), str(e)]))
|
||||
permission_errors = (
|
||||
"permission denied",
|
||||
"not permitted"
|
||||
)
|
||||
raise exception.UpgradeError("\n".join([str(cmd), str(e)]))
|
||||
permission_errors = ("permission denied", "not permitted")
|
||||
if (any([m in r['err'].lower() for m in permission_errors]) and
|
||||
"windows" not in util.get_systype()):
|
||||
click.secho("""
|
||||
click.secho(
|
||||
"""
|
||||
-----------------
|
||||
Permission denied
|
||||
-----------------
|
||||
@ -86,11 +80,13 @@ You need the `sudo` permission to install Python packages. Try
|
||||
> sudo pip install -U platformio
|
||||
|
||||
WARNING! Don't use `sudo` for the rest PlatformIO commands.
|
||||
""", fg="yellow", err=True)
|
||||
""",
|
||||
fg="yellow",
|
||||
err=True)
|
||||
raise exception.ReturnErrorCode()
|
||||
else:
|
||||
raise exception.UpgradeError(
|
||||
"\n".join([str(cmd), r['out'], r['err']]))
|
||||
raise exception.UpgradeError("\n".join([str(cmd), r['out'], r[
|
||||
'err']]))
|
||||
|
||||
|
||||
def get_latest_version():
|
||||
@ -107,11 +103,9 @@ def get_latest_version():
|
||||
|
||||
def get_develop_latest_version():
|
||||
version = None
|
||||
r = requests.get(
|
||||
"https://raw.githubusercontent.com/platformio/platformio"
|
||||
"/develop/platformio/__init__.py",
|
||||
headers=util.get_request_defheaders()
|
||||
)
|
||||
r = requests.get("https://raw.githubusercontent.com/platformio/platformio"
|
||||
"/develop/platformio/__init__.py",
|
||||
headers=util.get_request_defheaders())
|
||||
r.raise_for_status()
|
||||
for line in r.text.split("\n"):
|
||||
line = line.strip()
|
||||
@ -129,9 +123,7 @@ def get_develop_latest_version():
|
||||
|
||||
|
||||
def get_pypi_latest_version():
|
||||
r = requests.get(
|
||||
"https://pypi.python.org/pypi/platformio/json",
|
||||
headers=util.get_request_defheaders()
|
||||
)
|
||||
r = requests.get("https://pypi.python.org/pypi/platformio/json",
|
||||
headers=util.get_request_defheaders())
|
||||
r.raise_for_status()
|
||||
return r.json()['info']['version']
|
||||
|
@ -41,7 +41,8 @@ class FileDownloader(object):
|
||||
self._request = None
|
||||
|
||||
# make connection
|
||||
self._request = requests.get(url, stream=True,
|
||||
self._request = requests.get(url,
|
||||
stream=True,
|
||||
headers=util.get_request_defheaders())
|
||||
if self._request.status_code != 200:
|
||||
raise FDUnrecognizedStatusCode(self._request.status_code, url)
|
||||
|
@ -59,19 +59,14 @@ class ProjectGenerator(object):
|
||||
|
||||
@util.memoized
|
||||
def get_project_build_data(self):
|
||||
data = {
|
||||
"defines": [],
|
||||
"includes": [],
|
||||
"cxx_path": None
|
||||
}
|
||||
data = {"defines": [], "includes": [], "cxx_path": None}
|
||||
envdata = self.get_project_env()
|
||||
if "env_name" not in envdata:
|
||||
return data
|
||||
cmd = [
|
||||
normpath(sys.executable), "-m",
|
||||
"platformio" + (
|
||||
".__main__" if sys.version_info < (2, 7, 0) else ""),
|
||||
"-f"
|
||||
"platformio" + (".__main__"
|
||||
if sys.version_info < (2, 7, 0) else ""), "-f"
|
||||
]
|
||||
if app.get_session_var("caller_id"):
|
||||
cmd.extend(["-c", app.get_session_var("caller_id")])
|
||||
@ -80,8 +75,8 @@ class ProjectGenerator(object):
|
||||
result = util.exec_command(cmd)
|
||||
|
||||
if result['returncode'] != 0 or '"includes":' not in result['out']:
|
||||
raise exception.PlatformioException(
|
||||
"\n".join([result['out'], result['err']]))
|
||||
raise exception.PlatformioException("\n".join([result['out'],
|
||||
result['err']]))
|
||||
|
||||
output = result['out']
|
||||
start_index = output.index('{"')
|
||||
@ -125,8 +120,7 @@ class ProjectGenerator(object):
|
||||
file_name = basename(tpl_path)[:-4]
|
||||
self._merge_contents(
|
||||
join(dst_dir, file_name),
|
||||
self._render_tpl(tpl_path).encode("utf8")
|
||||
)
|
||||
self._render_tpl(tpl_path).encode("utf8"))
|
||||
|
||||
def _render_tpl(self, tpl_path):
|
||||
content = ""
|
||||
@ -161,13 +155,13 @@ class ProjectGenerator(object):
|
||||
"project_dir": self.project_dir,
|
||||
"project_src_dir": self.project_src_dir,
|
||||
"systype": util.get_systype(),
|
||||
"platformio_path": self._fix_os_path(
|
||||
util.where_is_program("platformio")),
|
||||
"platformio_path":
|
||||
self._fix_os_path(util.where_is_program("platformio")),
|
||||
"env_pathsep": os.pathsep,
|
||||
"env_path": self._fix_os_path(os.getenv("PATH"))
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def _fix_os_path(path):
|
||||
return (re.sub(r"[\\]+", '\\' * 4, path) if "windows" in
|
||||
util.get_systype() else path)
|
||||
return (re.sub(r"[\\]+", '\\' * 4, path)
|
||||
if "windows" in util.get_systype() else path)
|
||||
|
@ -56,8 +56,10 @@ def on_platformio_end(ctx, result): # pylint: disable=W0613
|
||||
check_internal_updates(ctx, "platforms")
|
||||
check_internal_updates(ctx, "libraries")
|
||||
except (exception.GetLatestVersionError, exception.APIRequestError):
|
||||
click.secho("Failed to check for PlatformIO upgrades. "
|
||||
"Please check your Internet connection.", fg="red")
|
||||
click.secho(
|
||||
"Failed to check for PlatformIO upgrades. "
|
||||
"Please check your Internet connection.",
|
||||
fg="red")
|
||||
|
||||
|
||||
def on_platformio_exception(e):
|
||||
@ -100,8 +102,7 @@ class Upgrader(object):
|
||||
continue
|
||||
os.remove(join(boards_dir, item))
|
||||
for key, value in data.items():
|
||||
with open(join(boards_dir, "%s.json" % key),
|
||||
"w") as f:
|
||||
with open(join(boards_dir, "%s.json" % key), "w") as f:
|
||||
json.dump(value, f, sort_keys=True, indent=2)
|
||||
|
||||
# re-install PlatformIO 2.0 development platforms
|
||||
@ -120,8 +121,7 @@ def after_upgrade(ctx):
|
||||
if last_version == "0.0.0":
|
||||
app.set_state_item("last_version", __version__)
|
||||
else:
|
||||
click.secho("Please wait while upgrading PlatformIO ...",
|
||||
fg="yellow")
|
||||
click.secho("Please wait while upgrading PlatformIO ...", fg="yellow")
|
||||
|
||||
u = Upgrader(last_version, __version__)
|
||||
if u.run(ctx):
|
||||
@ -132,11 +132,15 @@ def after_upgrade(ctx):
|
||||
for manifest in pm.get_installed():
|
||||
pm.update(manifest['name'], "^" + manifest['version'])
|
||||
|
||||
click.secho("PlatformIO has been successfully upgraded to %s!\n" %
|
||||
__version__, fg="green")
|
||||
click.secho(
|
||||
"PlatformIO has been successfully upgraded to %s!\n" %
|
||||
__version__,
|
||||
fg="green")
|
||||
|
||||
telemetry.on_event(category="Auto", action="Upgrade",
|
||||
label="%s > %s" % (last_version, __version__))
|
||||
telemetry.on_event(
|
||||
category="Auto",
|
||||
action="Upgrade",
|
||||
label="%s > %s" % (last_version, __version__))
|
||||
else:
|
||||
raise exception.UpgradeError("Auto upgrading...")
|
||||
click.echo("")
|
||||
@ -144,29 +148,24 @@ def after_upgrade(ctx):
|
||||
# PlatformIO banner
|
||||
terminal_width, _ = click.get_terminal_size()
|
||||
click.echo("*" * terminal_width)
|
||||
click.echo("If you like %s, please:" % (
|
||||
click.style("PlatformIO", fg="cyan")
|
||||
))
|
||||
click.echo(
|
||||
"- %s us on Twitter to stay up-to-date "
|
||||
"on the latest project news > %s" %
|
||||
(click.style("follow", fg="cyan"),
|
||||
click.style("https://twitter.com/PlatformIO_Org", fg="cyan"))
|
||||
)
|
||||
click.echo("- %s it on GitHub > %s" % (
|
||||
click.style("star", fg="cyan"),
|
||||
click.style("https://github.com/platformio/platformio", fg="cyan")
|
||||
))
|
||||
click.echo("If you like %s, please:" % (click.style(
|
||||
"PlatformIO", fg="cyan")))
|
||||
click.echo("- %s us on Twitter to stay up-to-date "
|
||||
"on the latest project news > %s" % (click.style(
|
||||
"follow", fg="cyan"), click.style(
|
||||
"https://twitter.com/PlatformIO_Org", fg="cyan")))
|
||||
click.echo("- %s it on GitHub > %s" % (click.style(
|
||||
"star", fg="cyan"), click.style(
|
||||
"https://github.com/platformio/platformio", fg="cyan")))
|
||||
if not getenv("PLATFORMIO_IDE"):
|
||||
click.echo("- %s PlatformIO IDE for IoT development > %s" % (
|
||||
click.style("try", fg="cyan"),
|
||||
click.style("http://platformio.org/platformio-ide", fg="cyan")
|
||||
))
|
||||
click.echo("- %s PlatformIO IDE for IoT development > %s" %
|
||||
(click.style(
|
||||
"try", fg="cyan"), click.style(
|
||||
"http://platformio.org/platformio-ide", fg="cyan")))
|
||||
if not util.is_ci():
|
||||
click.echo("- %s to keep PlatformIO alive! > %s" % (
|
||||
click.style("donate", fg="cyan"),
|
||||
click.style("http://platformio.org/donate", fg="cyan")
|
||||
))
|
||||
click.echo("- %s to keep PlatformIO alive! > %s" % (click.style(
|
||||
"donate", fg="cyan"), click.style(
|
||||
"http://platformio.org/donate", fg="cyan")))
|
||||
|
||||
click.echo("*" * terminal_width)
|
||||
click.echo("")
|
||||
@ -191,12 +190,14 @@ def check_platformio_upgrade():
|
||||
|
||||
click.echo("")
|
||||
click.echo("*" * terminal_width)
|
||||
click.secho("There is a new version %s of PlatformIO available.\n"
|
||||
"Please upgrade it via `" % latest_version,
|
||||
fg="yellow", nl=False)
|
||||
click.secho(
|
||||
"There is a new version %s of PlatformIO available.\n"
|
||||
"Please upgrade it via `" % latest_version,
|
||||
fg="yellow",
|
||||
nl=False)
|
||||
if getenv("PLATFORMIO_IDE"):
|
||||
click.secho("PlatformIO IDE Menu: Upgrade PlatformIO",
|
||||
fg="cyan", nl=False)
|
||||
click.secho(
|
||||
"PlatformIO IDE Menu: Upgrade PlatformIO", fg="cyan", nl=False)
|
||||
click.secho("`.", fg="yellow")
|
||||
elif join("Cellar", "platformio") in util.get_source_dir():
|
||||
click.secho("brew update && brew upgrade", fg="cyan", nl=False)
|
||||
@ -235,20 +236,29 @@ def check_internal_updates(ctx, what):
|
||||
|
||||
click.echo("")
|
||||
click.echo("*" * terminal_width)
|
||||
click.secho("There are the new updates for %s (%s)" %
|
||||
(what, ", ".join(outdated_items)), fg="yellow")
|
||||
click.secho(
|
||||
"There are the new updates for %s (%s)" %
|
||||
(what, ", ".join(outdated_items)),
|
||||
fg="yellow")
|
||||
|
||||
if not app.get_setting("auto_update_" + what):
|
||||
click.secho("Please update them via ", fg="yellow", nl=False)
|
||||
click.secho("`platformio %s update`" %
|
||||
("lib --global" if what == "libraries" else "platform"),
|
||||
fg="cyan", nl=False)
|
||||
click.secho(
|
||||
"`platformio %s update`" %
|
||||
("lib --global" if what == "libraries" else "platform"),
|
||||
fg="cyan",
|
||||
nl=False)
|
||||
click.secho(" command.\n", fg="yellow")
|
||||
click.secho("If you want to manually check for the new versions "
|
||||
"without updating, please use ", fg="yellow", nl=False)
|
||||
click.secho("`platformio %s update --only-check`" %
|
||||
("lib --global" if what == "libraries" else "platform"),
|
||||
fg="cyan", nl=False)
|
||||
click.secho(
|
||||
"If you want to manually check for the new versions "
|
||||
"without updating, please use ",
|
||||
fg="yellow",
|
||||
nl=False)
|
||||
click.secho(
|
||||
"`platformio %s update --only-check`" %
|
||||
("lib --global" if what == "libraries" else "platform"),
|
||||
fg="cyan",
|
||||
nl=False)
|
||||
click.secho(" command.", fg="yellow")
|
||||
else:
|
||||
click.secho("Please wait while updating %s ..." % what, fg="yellow")
|
||||
|
@ -210,8 +210,7 @@ class MPDataPusher(object):
|
||||
"https://ssl.google-analytics.com/collect",
|
||||
data=data,
|
||||
headers=util.get_request_defheaders(),
|
||||
timeout=1
|
||||
)
|
||||
timeout=1)
|
||||
r.raise_for_status()
|
||||
return True
|
||||
except: # pylint: disable=W0702
|
||||
@ -233,11 +232,7 @@ def on_command():
|
||||
|
||||
|
||||
def measure_ci():
|
||||
event = {
|
||||
"category": "CI",
|
||||
"action": "NoName",
|
||||
"label": None
|
||||
}
|
||||
event = {"category": "CI", "action": "NoName", "label": None}
|
||||
|
||||
envmap = {
|
||||
"APPVEYOR": {"label": getenv("APPVEYOR_REPO_NAME")},
|
||||
@ -258,11 +253,7 @@ def measure_ci():
|
||||
|
||||
def measure_caller(calller_id):
|
||||
calller_id = str(calller_id)[:20].lower()
|
||||
event = {
|
||||
"category": "Caller",
|
||||
"action": "Misc",
|
||||
"label": calller_id
|
||||
}
|
||||
event = {"category": "Caller", "action": "Misc", "label": calller_id}
|
||||
if calller_id in (["atom", "vim"] + ProjectGenerator.get_supported_ides()):
|
||||
event['action'] = "IDE"
|
||||
on_event(**event)
|
||||
|
@ -64,8 +64,7 @@ class ZIPArchive(ArchiveBase):
|
||||
def preserve_mtime(item, dest_dir):
|
||||
util.change_filemtime(
|
||||
join(dest_dir, item.filename),
|
||||
mktime(list(item.date_time) + [0] * 3)
|
||||
)
|
||||
mktime(list(item.date_time) + [0] * 3))
|
||||
|
||||
def get_items(self):
|
||||
return self._afo.infolist()
|
||||
@ -97,8 +96,8 @@ class FileUnpacker(object):
|
||||
for item in self._unpacker.get_items():
|
||||
self._unpacker.extract_item(item, self._dest_dir)
|
||||
else:
|
||||
with click.progressbar(self._unpacker.get_items(),
|
||||
label="Unpacking") as pb:
|
||||
items = self._unpacker.get_items()
|
||||
with click.progressbar(items, label="Unpacking") as pb:
|
||||
for item in pb:
|
||||
self._unpacker.extract_item(item, self._dest_dir)
|
||||
return True
|
||||
|
@ -81,7 +81,6 @@ class cd(object):
|
||||
|
||||
|
||||
class memoized(object):
|
||||
|
||||
'''
|
||||
Decorator. Caches a function's return value each time it is called.
|
||||
If called later with the same arguments, the cached value is returned
|
||||
@ -122,6 +121,7 @@ def singleton(cls):
|
||||
if cls not in _instances:
|
||||
_instances[cls] = cls(*args, **kwargs)
|
||||
return _instances[cls]
|
||||
|
||||
return get_instance
|
||||
|
||||
|
||||
@ -162,10 +162,8 @@ def _get_projconf_option_dir(name, default=None):
|
||||
|
||||
|
||||
def get_home_dir():
|
||||
home_dir = _get_projconf_option_dir(
|
||||
"home_dir",
|
||||
join(expanduser("~"), ".platformio")
|
||||
)
|
||||
home_dir = _get_projconf_option_dir("home_dir",
|
||||
join(expanduser("~"), ".platformio"))
|
||||
|
||||
if "windows" in get_systype():
|
||||
try:
|
||||
@ -234,10 +232,8 @@ URL=http://docs.platformio.org/en/stable/projectconf.html#envs-dir
|
||||
|
||||
|
||||
def get_projectdata_dir():
|
||||
return _get_projconf_option_dir(
|
||||
"data_dir",
|
||||
join(get_project_dir(), "data")
|
||||
)
|
||||
return _get_projconf_option_dir("data_dir",
|
||||
join(get_project_dir(), "data"))
|
||||
|
||||
|
||||
def load_project_config(project_dir=None):
|
||||
@ -259,17 +255,12 @@ def is_ci():
|
||||
|
||||
|
||||
def exec_command(*args, **kwargs):
|
||||
result = {
|
||||
"out": None,
|
||||
"err": None,
|
||||
"returncode": None
|
||||
}
|
||||
result = {"out": None, "err": None, "returncode": None}
|
||||
|
||||
default = dict(
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=system() == "Windows"
|
||||
)
|
||||
shell=system() == "Windows")
|
||||
default.update(kwargs)
|
||||
kwargs = default
|
||||
|
||||
@ -344,9 +335,8 @@ def get_logicaldisks():
|
||||
|
||||
def get_request_defheaders():
|
||||
import requests
|
||||
return {"User-Agent": "PlatformIO/%s CI/%d %s" % (
|
||||
__version__, int(is_ci()), requests.utils.default_user_agent()
|
||||
)}
|
||||
data = (__version__, int(is_ci()), requests.utils.default_user_agent())
|
||||
return {"User-Agent": "PlatformIO/%s CI/%d %s" % data}
|
||||
|
||||
|
||||
@memoized
|
||||
@ -364,7 +354,7 @@ def get_api_result(path, params=None, data=None, skipdns=False):
|
||||
url = __apiurl__
|
||||
if skipdns:
|
||||
url = "http://%s" % __apiip__
|
||||
headers['host'] = __apiurl__[__apiurl__.index("://")+3:]
|
||||
headers['host'] = __apiurl__[__apiurl__.index("://") + 3:]
|
||||
|
||||
try:
|
||||
if data:
|
||||
@ -390,8 +380,8 @@ def get_api_result(path, params=None, data=None, skipdns=False):
|
||||
"Could not connect to PlatformIO Registry Service. "
|
||||
"Please try later.")
|
||||
except ValueError:
|
||||
raise exception.APIRequestError(
|
||||
"Invalid response: %s" % r.text.encode("utf-8"))
|
||||
raise exception.APIRequestError("Invalid response: %s" %
|
||||
r.text.encode("utf-8"))
|
||||
finally:
|
||||
if r:
|
||||
r.close()
|
||||
@ -401,8 +391,8 @@ def get_api_result(path, params=None, data=None, skipdns=False):
|
||||
@memoized
|
||||
def _lookup_frameworks():
|
||||
frameworks = {}
|
||||
frameworks_path = join(
|
||||
get_source_dir(), "builder", "scripts", "frameworks")
|
||||
frameworks_path = join(get_source_dir(), "builder", "scripts",
|
||||
"frameworks")
|
||||
|
||||
frameworks_list = [f[:-3] for f in os.listdir(frameworks_path)
|
||||
if not f.startswith("__") and f.endswith(".py")]
|
||||
@ -412,8 +402,8 @@ def _lookup_frameworks():
|
||||
fcontent = f.read()
|
||||
assert '"""' in fcontent
|
||||
_doc_start = fcontent.index('"""') + 3
|
||||
fdoc = fcontent[
|
||||
_doc_start:fcontent.index('"""', _doc_start)].strip()
|
||||
fdoc = fcontent[_doc_start:fcontent.index('"""',
|
||||
_doc_start)].strip()
|
||||
doclines = [l.strip() for l in fdoc.splitlines() if l.strip()]
|
||||
frameworks[_type] = {
|
||||
"name": doclines[0],
|
||||
@ -446,8 +436,7 @@ def where_is_program(program, envpath=None):
|
||||
try:
|
||||
result = exec_command(
|
||||
["where" if "windows" in get_systype() else "which", program],
|
||||
env=env
|
||||
)
|
||||
env=env)
|
||||
if result['returncode'] == 0 and isfile(result['out'].strip()):
|
||||
return result['out'].strip()
|
||||
except OSError:
|
||||
|
5
setup.py
5
setup.py
@ -12,8 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
from platformio import (__author__, __description__, __email__, __license__,
|
||||
@ -29,9 +27,6 @@ install_requires = [
|
||||
"pyserial<4"
|
||||
]
|
||||
|
||||
if sys.version_info < (2, 7, 0):
|
||||
install_requires[-1] = "pyserial<3"
|
||||
|
||||
setup(
|
||||
name=__title__,
|
||||
version=__version__,
|
||||
|
Reference in New Issue
Block a user