Format code with pep8 style

This commit is contained in:
Ivan Kravets
2016-08-03 23:38:20 +03:00
parent 0c9d539a92
commit 87d0ead203
27 changed files with 514 additions and 446 deletions
+2 -2
View File
@@ -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
+13 -20
View File
@@ -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
+1 -3
View File
@@ -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(_):
+8 -16
View File
@@ -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:
+1 -2
View File
@@ -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"):
+18 -28
View File
@@ -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"]: