New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't install packages that could mess packaging up #397
Changes from 7 commits
52758c3
3544a4c
3a8e27c
9e026ba
4ce42fe
2cc1d0d
5ea0382
24f670e
2a5c6f5
b8f8f5b
1ede61e
dafc912
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Syntax sugar. | ||
source $BIN_DIR/utils | ||
|
||
pip-clean requirements.txt | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Usage: | ||
pip-clean <req-file> | ||
|
||
Options: | ||
-h --help Show this screen. | ||
""" | ||
from docopt import docopt | ||
|
||
BAD_PACKAGES = ['appdirs', 'packaging', 'pyparsing', 'six', 'setuptools', 'distribute'] | ||
|
||
|
||
def good_package(line): | ||
package_name = line.split('=')[0].split('<')[0].split('>')[0].split(' ')[0].split('#')[0].split('\n')[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Buggy. c.f. #400 |
||
return package_name not in BAD_PACKAGES | ||
|
||
def main(): | ||
args = docopt(__doc__, version='pip-grep') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! |
||
req_file = args['<req-file>'] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be streamlined? def good_package(line):
package_name = line.split('=')[0].split('<')[0].split('>')[0]
return package_name not in BAD_PACKAGES
lines = [line for line in f if good_package(line)] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to do as little parsing as possible, for fear of breaking anything with crazy requirements files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood... see other package names that begin with but do not end with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was planning to cross that bridge when I came to it, which I honestly doubt would happen any time soon. I'll see what I can do though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cclauss i updated the code; integrated what you suggested and made a few improvements |
||
with open(req_file, 'r') as f: | ||
# Iterate over every line in the requirements file. | ||
lines = [line for line in f if good_package(line)] | ||
|
||
# Write the requirements file to disk. | ||
with open(req_file, 'w') as f: | ||
f.write(''.join(lines)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing EOL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!