From ec9cf616904d92509b8b44662e7097352d894484 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sat, 12 Jan 2013 19:47:31 -0800 Subject: [PATCH] Rename pip-requires to requirements.txt. Change-Id: I4cfdd0ef6cddfa3d75b4d650362f9645486755c8 --- README.rst | 2 +- tools/pip-requires => requirements.txt | 0 tools/test-requires => test-requirements.txt | 0 update.py | 28 +++++++++++--------- 4 files changed, 16 insertions(+), 14 deletions(-) rename tools/pip-requires => requirements.txt (100%) rename tools/test-requires => test-requirements.txt (100%) diff --git a/README.rst b/README.rst index af4405f22a..e398b3088a 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,7 @@ To use this, run: python update.py path/to/project -Entries in tools/pip-requires and tools/test-requires +Entries in requirements.txt and test-requirements.txt will have their versions updated to match the entires listed here. Any entries in the target project which do not first exist here will be removed. No entries diff --git a/tools/pip-requires b/requirements.txt similarity index 100% rename from tools/pip-requires rename to requirements.txt diff --git a/tools/test-requires b/test-requirements.txt similarity index 100% rename from tools/test-requires rename to test-requirements.txt diff --git a/update.py b/update.py index 2ff469ba83..852c6153ad 100644 --- a/update.py +++ b/update.py @@ -58,23 +58,30 @@ def _parse_reqs(filename): return reqs -def _copy_requires(req, source_paths, dest_dir): +def _copy_requires(source_path, dest_dir): """Copy requirements files.""" - dest_path = os.path.join(dest_dir, req) + target_map = { + 'requirements.txt': ('requirements.txt', 'tools/pip-requires'), + 'test-requirements.txt': ( + 'test-requirements.txt', 'tools/test-requires'), + } + for dest in target_map[source_path]: + dest_path = os.path.join(dest_dir, dest) + if os.path.exists(dest_path): + break + # Catch the fall through if not os.path.exists(dest_path): # This can happen, we try all paths return - source_reqs = dict() - for s in source_paths: - source_reqs.update(_parse_reqs(s)) + source_reqs = _parse_reqs(source_path) with open(dest_path, 'r') as dest_reqs_file: dest_reqs = dest_reqs_file.readlines() - print "Syncing %s" % req + print "Syncing %s" % source_path with open(dest_path, 'w') as new_reqs: for old_require in dest_reqs: @@ -102,13 +109,8 @@ def _copy_requires(req, source_paths, dest_dir): def main(argv): - for req in ('tools/pip-requires', 'requirements.txt'): - _copy_requires(req, ['tools/pip-requires'], argv[0]) - - for req in ('tools/test-requires', 'test-requirements.txt'): - _copy_requires(req, - ['tools/pip-requires', 'tools/test-requires'], - argv[0]) + for req in ('requirements.txt', 'test-requirements.txt'): + _copy_requires(req, argv[0]) if __name__ == "__main__":