diff options
author | Cristián Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2019-11-17 13:06:37 +0100 |
---|---|---|
committer | Cristián Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2019-11-25 21:50:17 +0100 |
commit | 69d511949fdf1da8309c9adab8b00ed6f80053a0 (patch) | |
tree | 313e4f8578fcd4797a8b411c31aedaf35f3ee9a7 /build_scripts/qp5_tool.py | |
parent | 2914408d9017d192f254b4c7b2d298bb7b6e885e (diff) |
Improve code style with flake8
- We agreed on 100 columns time ago, so I move around a few things,
- Removing unused modules,
- Fix white-spaces tabs without being multiple of 4,
- Encourage the use of os.path.join when joining paths,
- Using .format() for string formatting,
- Remove white-spaces from default arguments,
- Adjusting white-spaces before inline comments,
- Adding extra newlines when expected,
- Adjust spaces for lines under-indented for visual indent,
- Remove white-spaces from parenthesis, and adding them for arithmetic operators.
Change-Id: I9cb28cefd114d63580b584a063c452f90d3ca885
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'build_scripts/qp5_tool.py')
-rw-r--r-- | build_scripts/qp5_tool.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/build_scripts/qp5_tool.py b/build_scripts/qp5_tool.py index aca8cf7f6..108e38d87 100644 --- a/build_scripts/qp5_tool.py +++ b/build_scripts/qp5_tool.py @@ -72,6 +72,7 @@ Modules=$(MinimalModules),Multimedia Modules-pyside-setup-minimal=$(MinimalModules) """ + def which(needle): """Perform a path search""" needles = [needle] @@ -86,6 +87,7 @@ def which(needle): return binary return None + def execute(args): """Execute a command and print to log""" log_string = '[{}] {}'.format(os.path.basename(os.getcwd()), ' '.join(args)) @@ -94,31 +96,34 @@ def execute(args): if exit_code != 0: raise RuntimeError('FAIL({}): {}'.format(exit_code, log_string)) + def run_git(args): """Run git in the current directory and its submodules""" - args.insert(0, git) # run in repo + args.insert(0, git) # run in repo execute(args) # run for submodules module_args = [git, "submodule", "foreach"] module_args.extend(args) execute(module_args) + def expand_reference(dict, value): """Expand references to other keys in config files $(name) by value.""" pattern = re.compile(r"\$\([^)]+\)") while True: - match = pattern.match(value) - if not match: - break - key = match.group(0)[2:-1] - value = value[:match.start(0)] + dict[key] + value[match.end(0):] + match = pattern.match(value) + if not match: + break + key = match.group(0)[2:-1] + value = value[:match.start(0)] + dict[key] + value[match.end(0):] return value + """ Config file handling, cache and read function """ - config_dict = {} + def read_config_file(fileName): global config_dict keyPattern = re.compile(r'^\s*([A-Za-z0-9\_\-]+)\s*=\s*(.*)$') @@ -136,6 +141,7 @@ def read_config_file(fileName): value += f.readline().rstrip() config_dict[key] = expand_reference(config_dict, value) + def read_tool_config(key): """ Read a value from the '$HOME/.qp5_tool' configuration file. When given @@ -147,11 +153,13 @@ def read_tool_config(key): repo_value = config_dict.get(key + '-' + base_dir) return repo_value if repo_value else config_dict.get(key) + def read_config_build_arguments(): value = read_tool_config('BuildArguments') if value: return re.split(r'\s+', value) - return default_build_args; + return default_build_args + def read_config_modules_argument(): value = read_tool_config('Modules') @@ -159,10 +167,12 @@ def read_config_modules_argument(): return '--module-subset=' + value return None + def read_config_python_binary(): binary = read_tool_config('Python') return binary if binary else 'python' + def get_config_file(): home = os.getenv('HOME') if is_windows: @@ -182,6 +192,7 @@ def get_config_file(): config_file = os.path.join(home, '.' + config_file_name) return config_file + def get_options(desc): parser = ArgumentParser(description=desc, formatter_class=RawTextHelpFormatter) parser.add_argument('--reset', '-r', action='store_true', @@ -199,6 +210,7 @@ def get_options(desc): return parser.parse_args() + if __name__ == '__main__': git = None |