opensafely-core / opensafely-core/opensafely-cli
Confusing error when an OpenSAFELY upgrade is available, but unsupported by installed Python
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2
- Forks
- 5
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 4
Description
I'll put this here for discussion in case it's worth bothering to handle nicely.
Issue reproduction
From this support question:
Every time I submit command in my Anaconda prompt I'm told that v1.17.1 of opensafely is available (I currently have 1.15.1). But everytime I run , it says it cannot find a version that satisfies the requirement for opensafely =1.17.1 (despite listing 1.15.1 in the list of options).
I believe the cause is:
- Have
opensafelycorrectly installed on Python 3.7 - Run
opensafelywhich tells you to runopensafely upgrade - Run
opensafely upgradewhich fails because there is no package suitable for Python 3.8
It's a confusing error for a non-developer, because it makes it seem like the CLI is trying to pull a non-existent version:
ERROR: Could not find a version that satisfies the requirement opensafely==1.20.0 (from versions: 1.0.1, 1.0.2, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.4.0, 1.4.1, 1.4.2, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.9.2, 1.10.0, 1.10.1, 1.10.2, 1.10.3, 1.11.0, 1.11.1, 1.11.2, 1.12.0, 1.13.0, 1.14.0, 1.15.0, 1.15.1)
ERROR: No matching distribution found for opensafely==1.20.0
Possible fix
We just need to check when upgrading, maybe something[^1] like:
import platform
from packaging.specifiers import SpecifierSet
# resp here is https://pypi.org/pypi/opensafely/json as a dict
version_specifier = SpecifierSet(resp["info"]["requires_python"])
if (python_version := platform.python_version()) not in version_specifier:
raise Exception(f"The latest OpenSAFELY CLI does not support {python_version}; please upgrade your Python.")
[^1]: I think this would be the canonical Python way of checking, but feel free to correct me.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in opensafely/upgrade.py around lines 72-75 and inspect how the PyPI response and installed Python version are handled during an upgrade. Reproduce the upgrade on an unsupported Python version, then verify that the CLI reports the compatibility problem clearly instead of exposing pip's confusing version error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100