-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add dry-run option #78
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
Changes from 3 commits
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 |
|---|---|---|
|
|
@@ -121,6 +121,25 @@ these exact identifiers directly, if you need something specific. | |
| The ``source`` release is always automatically included. ``pip`` will use | ||
| this as a fallback in the case a suitable wheel cannot be found. | ||
|
|
||
| Dry run mode | ||
| ============ | ||
|
|
||
| There are some use cases, when you maybe don't want to edit your requirements.txt | ||
| right away. You can use the ``-dry-run`` argument to just print the lines, as if they | ||
| would be added to your requirements.txt file. | ||
|
||
|
|
||
| Example:: | ||
|
|
||
| hashin --dry-run requests==2.19.1 | ||
|
|
||
| Would result in a printout on the command line:: | ||
|
|
||
| requests==2.19.1 \ | ||
| --hash=sha256:63b52e3c866428a224f97cab011de738c36aec0185aa91cfacd418b5d58911d1 \ | ||
| --hash=sha256:ec22d826a36ed72a7358ff3fe56cbd4ba69dd7a6718ffd450ff0e9df7a47ce6a | ||
|
|
||
|
|
||
|
|
||
| PEP-0496 Environment Markers | ||
| ============================ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,12 @@ | |
| action='store_true', | ||
| default=False, | ||
| ) | ||
| parser.add_argument( | ||
| '--dry-run', | ||
| help='Don\'t touch requirements.txt and just show hashes', | ||
|
||
| action='store_true', | ||
| default=False, | ||
| ) | ||
|
|
||
|
|
||
| major_pip_version = int(pip_api.version().split('.')[0]) | ||
|
|
@@ -101,7 +107,7 @@ def _download(url, binary=False): | |
| # Note that urlopen will, by default, follow redirects. | ||
| status_code = r.getcode() | ||
|
|
||
| if status_code >= 301 and status_code < 400: | ||
| if 301 <= status_code < 400: | ||
| location, _ = cgi.parse_header(r.headers.get('location', '')) | ||
| if not location: | ||
| raise PackageError("No 'Location' header on {0} ({1})".format( | ||
|
|
@@ -137,6 +143,7 @@ def run_single_package( | |
| python_versions=None, | ||
| verbose=False, | ||
| include_prereleases=False, | ||
| dry_run=False, | ||
| ): | ||
| restriction = None | ||
| if ';' in spec: | ||
|
|
@@ -159,7 +166,6 @@ def run_single_package( | |
| package = data['package'] | ||
|
|
||
| maybe_restriction = '' if not restriction else '; {0}'.format(restriction) | ||
| new_lines = '' | ||
| new_lines = '{0}=={1}{2} \\\n'.format( | ||
| package, | ||
| data['version'], | ||
|
|
@@ -175,6 +181,11 @@ def run_single_package( | |
| new_lines += ' \\' | ||
| new_lines += '\n' | ||
|
|
||
| if dry_run: | ||
| if verbose: | ||
| _verbose('Dry run, not editing ', file) | ||
| print(new_lines) | ||
| return | ||
| if verbose: | ||
| _verbose('Editing', file) | ||
| with open(file) as f: | ||
|
|
@@ -498,6 +509,7 @@ def main(): | |
| args.python_version, | ||
| verbose=args.verbose, | ||
| include_prereleases=args.include_prereleases, | ||
| dry_run=args.dry_run, | ||
| ) | ||
| except PackageError as exception: | ||
| print(str(exception), file=sys.stderr) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ def test_everything(): | |
| verbose=True, | ||
| version=False, | ||
| include_prereleases=False, | ||
| dry_run=False, | ||
max-wittig marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| assert args == (expected, []) | ||
|
|
||
|
|
@@ -30,6 +31,7 @@ def test_everything_long(): | |
| '--algorithm', 'sha512', | ||
| '--python-version', '3.5', | ||
| '--verbose', | ||
| '--dry-run', | ||
| ]) | ||
| expected = argparse.Namespace( | ||
| algorithm='sha512', | ||
|
|
@@ -39,6 +41,7 @@ def test_everything_long(): | |
| verbose=True, | ||
| version=False, | ||
| include_prereleases=False, | ||
| dry_run=True, | ||
| ) | ||
| assert args == (expected, []) | ||
|
|
||
|
|
@@ -53,5 +56,6 @@ def test_minimal(): | |
| verbose=False, | ||
| version=False, | ||
| include_prereleases=False, | ||
| dry_run=False, | ||
|
Owner
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. Isn't this the default anyway?
Contributor
Author
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. Tests fail otherwise here
Contributor
Author
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. Should I leave it like this or what changes should be made? |
||
| ) | ||
| assert args == (expected, []) | ||
Uh oh!
There was an error while loading. Please reload this page.