recompile_requirements: Add replace command
This commit is contained in:
parent
19037e8b75
commit
164d7bea4b
@ -8,6 +8,7 @@ Those files can also contain some special commands:
|
||||
- Add an additional comment to a line: `#@ comment: <package> <comment here>`
|
||||
- Filter a line for requirements.io: `#@ filter: <package> <filter>`
|
||||
- Don't include a package in the output: `#@ ignore: <package>` (or multiple packages)
|
||||
- Replace a part of a frozen package specification with another: `#@ replace <regex> <replacement>`
|
||||
|
||||
Some examples:
|
||||
|
||||
@ -15,4 +16,5 @@ Some examples:
|
||||
#@ comment: mypkg blah blub
|
||||
#@ filter: mypkg != 1.0.0
|
||||
#@ ignore: mypkg, otherpkg
|
||||
#@ replace: foo bar
|
||||
```
|
||||
|
@ -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
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user