Skip to content
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

Upgrade type ignored with --requirements or --project #93

Open
max-nicholson opened this issue Jan 29, 2021 · 2 comments · May be fixed by #94
Open

Upgrade type ignored with --requirements or --project #93

max-nicholson opened this issue Jan 29, 2021 · 2 comments · May be fixed by #94
Assignees
Labels
bug Something isn't working

Comments

@max-nicholson
Copy link
Contributor

What's the bug all about?

Upgrade type is ignored when running --requirements or --project (all upgrades included rather than just the specified/default of minor/patch)

current version includes the specifier (in this case ==) not just the number

What command led to this issue?

pipupgrade --requirements requirements/foo.txt --upgrade-type minor --verbose
# requirements/foo.txt
requests==24.0.0

Logs

(.venv) E:\Max\Documents\Github\pipupgrade>pipupgrade --requirements requirements/foo.txt --upgrade-type minor --verbose
2021-01-29 18:42:09,001 | INFO | Environment: {'version': '1.8.4', 'python_version': '3.9.1', 'os': 'Windows-10-10.0.19041-SP0', 'config': {'path': {'BASE': 'e:\\max\\documents\\github\\pipupgrade\\src\\pipupgrade', 'DATA': 'e:\\max\\documents\\github\\pipupgrade\\src\\pipupgrade\\data', 'CACHE': 'C:\\Users\\max\\.config\\pipupgrade'}}, 'settings': {'settings': {'version': '1.8.4', 'cache_timeout': '86400', 'jobs': '4'}}}
2021-01-29 18:42:09,002 | INFO | Arguments Passed: {'args': (), 'kwargs': {'ARGUMENTS': <class 'inspect._empty'>, 'packages': [], 'ignore': None, 'pip_path': None, 'yes': 0, 'check': 0, 'upgrade_type': ['minor'], 'latest': 0, 'format': 'table', 'all': 0, 'pip': 0, 'self': False, 'requirements': ['requirements/foo.txt'], 'pipfile': None, 'interactive': 0, 'project': None, 'git_username': None, 'git_email': None, 'pull_request': False, 'github_access_token': None, 'github_reponame': None, 'github_username': None, 'target_branch': 'master', 'jobs': 4, 'user': 0, 'no_included_requirements': 0, 'no_cache': 0, 'output': None, 'ignore_error': 0, 'force': 0, 'no_color': 0, 'verbose': True}, 'a': <pipupgrade.to_params.<locals>.O object at 0x00000275EB4D48B0>}
Checking...
2021-01-29 18:42:09,012 | INFO | `pip` executables found: ['E:\\Max\\Documents\\Github\\pipupgrade\\.venv\\Scripts\\pip.EXE', 'E:\\Max\\Documents\\Github\\pipupgrade\\.venv\\Scripts\\pip3.EXE']
2021-01-29 18:42:09,013 | INFO | Using 4 jobs...
2021-01-29 18:42:09,013 | INFO | Detecting requirements...
2021-01-29 18:42:10,564 | INFO | Requirements found: ['requirements/foo.txt']
2021-01-29 18:42:13,007 | INFO | Initializing Package requests==24.0.0 (from -r requirements/foo.txt (line 1)) of type <class 'pip._internal.req.req_install.InstallRequirement'>...
2021-01-29 18:42:13,007 | INFO | Fetching package requests information from DB...
2021-01-29 18:42:13,011 | INFO | Using cached info for package <Package requests (==24.0.0)>.
2021-01-29 18:42:13,330 | INFO | Packages within requirements requirements/foo.txt found: [<Package requests (==24.0.0)>]...
2021-01-29 18:42:13,432 | INFO | Updating registries: [<pipupgrade.model.registry.Registry object at 0x00000275EEAAE160>]...

Source: E:\Max\Documents\Github\pipupgrade\requirements\foo.txt

Name     Current Version Latest Version Home Page
-------- --------------- -------------- -------------------------------
requests ==24.0.0        2.25.1         https://requests.readthedocs.io
@max-nicholson max-nicholson added the bug Something isn't working label Jan 29, 2021
@max-nicholson
Copy link
Contributor Author

I think the solution is to modify this line:

self.current_version = str(package.req.specifier)

package.req.specifier is a frozenset of Specifier classes (https://github.com/pypa/pip/blob/31eb524ff0d18d6190b30a0c7821c0c857a7523c/src/pip/_vendor/packaging/specifiers.py#L334)

So in this case the current version would be list(package.req.specifier)[0].version -> "24.0.0"

Happy to do a PR, but but wasn't sure what we'd want for current_version if the Specifier operator is something other than ==. @achillesrasquinha any thoughts?

@achillesrasquinha
Copy link
Owner

The current_version should expect the actual current version installed or available within the requirements if present.

max-nicholson added a commit to max-nicholson/pipupgrade that referenced this issue Jan 30, 2021
If `--requirements` or `--project` flags are used, current_version for
Packages was equal to the specifier in the requirements file
eg. requests==2.24.0 showed current_version as `==2.24.0` rather than
just `2.24.0`
This then caused the `upgrade_type` check later to fail (as the `==`
version prefix made the version difference calculation incorrect

Requirements will now include the version only if an exact version is
specified, otherwise the installed version is used.
If not installed, the entire specifier is used (eg. `~=1.0`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants