From 164d7bea4b3daca123c45275795120b6b2c8ff87 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 7 Jun 2016 23:40:00 +0200 Subject: [PATCH] recompile_requirements: Add replace command --- misc/requirements/README.md | 2 ++ misc/requirements/requirements-pylint-master.txt-raw | 6 ++++++ scripts/dev/recompile_requirements.py | 10 +++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/misc/requirements/README.md b/misc/requirements/README.md index a02edc530..f38c4443e 100644 --- a/misc/requirements/README.md +++ b/misc/requirements/README.md @@ -8,6 +8,7 @@ Those files can also contain some special commands: - Add an additional comment to a line: `#@ comment: ` - Filter a line for requirements.io: `#@ filter: ` - Don't include a package in the output: `#@ ignore: ` (or multiple packages) +- Replace a part of a frozen package specification with another: `#@ replace ` Some examples: @@ -15,4 +16,5 @@ Some examples: #@ comment: mypkg blah blub #@ filter: mypkg != 1.0.0 #@ ignore: mypkg, otherpkg +#@ replace: foo bar ``` diff --git a/misc/requirements/requirements-pylint-master.txt-raw b/misc/requirements/requirements-pylint-master.txt-raw index d438b1617..f6b13df41 100644 --- a/misc/requirements/requirements-pylint-master.txt-raw +++ b/misc/requirements/requirements-pylint-master.txt-raw @@ -4,3 +4,9 @@ # https://github.com/PyCQA/pylint/issues/932 mccabe==0.5.0 + +# remove @commit-id for scm installs +#@ replace: @.*# # + +# fix qute-pylint location +#@ replace: qute-pylint==.* ./scripts/dev/pylint_checkers \ No newline at end of file diff --git a/scripts/dev/recompile_requirements.py b/scripts/dev/recompile_requirements.py index 9eb9199a9..0db266ee5 100644 --- a/scripts/dev/recompile_requirements.py +++ b/scripts/dev/recompile_requirements.py @@ -38,11 +38,7 @@ REQ_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), def convert_line(line, comments): - replacements = { - (r'@.*#', '#'), # remove @commit-id for scm installs - (r'qute-pylint==.*', './scripts/dev/pylint_checkers'), - } - for pattern, repl in replacements: + for pattern, repl in comments['replace'].items(): line = re.sub(pattern, repl, line) pkgname = line.split('=')[0] @@ -68,6 +64,7 @@ def read_comments(fobj): 'filter': {}, 'comment': {}, 'ignore': [], + 'replace': {}, } for line in fobj: if line.startswith('#@'): @@ -82,6 +79,9 @@ def read_comments(fobj): comments['comment'][pkg] = comment elif command == 'ignore': comments['ignore'] += args.split(', ') + elif command == 'replace': + pattern, replacement = args.split(' ', maxsplit=1) + comments['replace'][pattern] = replacement return comments