diff --git a/tools/merge_requirements.py b/tools/merge_requirements.py index 521d28b8f..0d41d12c4 100755 --- a/tools/merge_requirements.py +++ b/tools/merge_requirements.py @@ -55,21 +55,24 @@ def main(*paths): """Merges multiple requirements files together and prints the result. Requirement files specified later in the list take precedence over earlier - files. + files. Files are read from file paths passed from the command line arguments. - :param tuple paths: paths to requirements files + If no command line arguments are defined, data is read from stdin instead. + + :param tuple paths: paths to requirements files provided on command line """ data = {} - for path in paths: - data.update(process_entries(read_file(path))) - - # Need to check if interactive to avoid blocking if nothing is piped - if not sys.stdin.isatty(): - stdin_data = [] - for line in sys.stdin: - stdin_data.append(line) - data.update(process_entries(stdin_data)) + if paths: + for path in paths: + data.update(process_entries(read_file(path))) + else: + # Need to check if interactive to avoid blocking if nothing is piped + if not sys.stdin.isatty(): + stdin_data = [] + for line in sys.stdin: + stdin_data.append(line) + data.update(process_entries(stdin_data)) return output_requirements(data) diff --git a/tools/pip_install.py b/tools/pip_install.py index 8f0437d9c..15dc2f0c0 100755 --- a/tools/pip_install.py +++ b/tools/pip_install.py @@ -48,7 +48,7 @@ def certbot_normal_processing(tools_path, test_constraints): with open(certbot_requirements, 'r') as fd: data = fd.readlines() with open(test_constraints, 'w') as fd: - data = os.linesep.join(strip_hashes.process_entries(data)) + data = "\n".join(strip_hashes.process_entries(data)) fd.write(data) diff --git a/tools/strip_hashes.py b/tools/strip_hashes.py index 7e7809458..988e72eb8 100755 --- a/tools/strip_hashes.py +++ b/tools/strip_hashes.py @@ -2,7 +2,6 @@ """Removes hash information from requirement files passed to it as file path arguments or simply piped to stdin.""" -import os import re import sys @@ -24,22 +23,28 @@ def process_entries(entries): return out_lines def main(*paths): - """Reads dependency definitions from a (list of) file(s) or stdin and - removes hashes from returned entries""" + """ + Reads dependency definitions from a (list of) file(s) provided on the + command line. If no command line arguments are present, data is read from + stdin instead. + + Hashes are removed from returned entries. + """ deps = [] - for path in paths: - with open(path) as file_h: - deps += process_entries(file_h.readlines()) + if paths: + for path in paths: + with open(path) as file_h: + deps += process_entries(file_h.readlines()) + else: + # Need to check if interactive to avoid blocking if nothing is piped + if not sys.stdin.isatty(): + stdin_data = [] + for line in sys.stdin: + stdin_data.append(line) + deps += process_entries(stdin_data) - # Need to check if interactive to avoid blocking if nothing is piped - if not sys.stdin.isatty(): - stdin_data = [] - for line in sys.stdin: - stdin_data.append(line) - deps += process_entries(stdin_data) - - return os.linesep.join(deps) + return "\n".join(deps) if __name__ == '__main__': print(main(*sys.argv[1:])) # pylint: disable=star-args