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

fix: add support for dev/alpha/beta/rc python versions #235

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions pysrc/pip_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,47 @@ def create_package_as_root(package, dir_as_root):
dir_as_root[DEPENDENCIES][package_as_root[NAME]] = package_tree
return dir_as_root

def satisfies_python_requirement(parsed_operator, py_version_str):

def satisfies_python_requirement(parsed_operator, py_version):
"""Check if a package required python versions matches the one of the system

Args:
parsed_operator (str): operator to compare by i.e. >, <=, ==
py_version (str): The python version that is required by the package

Returns:
bool: True if the version matches, False otherwise
"""
# TODO: use python semver library to compare versions
operator_func = {
operator = {
">": gt,
"==": eq,
"<": lt,
"<=": le,
">=": ge,
'!=': ne,
}[parsed_operator]
}
operator_func = operator.get(parsed_operator)
Comment on lines +185 to +193
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the way the operator function was established. It's pretty confusing to create the dictionary and extract values from it in one go. I think that is even more confusing for someone that doesn't work with Python on a daily basis.

system_py_version_tuple = (sys.version_info[0], sys.version_info[1])
py_version_tuple = tuple(py_version_str.split('.')) # string tuple
py_version_tuple = tuple(py_version.split('.')) # tuple of strings

# For wildcard versions like 3.9.*
if py_version_tuple[-1] == '*':
system_py_version_tuple = system_py_version_tuple[0]
py_version_tuple = int(py_version_tuple[0]) # int tuple
py_version_tuple = int(py_version_tuple[0]) # tuple of integers

# For dev/alpha/beta/rc versions like 3.9.dev0
elif not py_version_tuple[-1].isdigit():
py_version_tuple = (int(py_version_tuple[0]), int(py_version_tuple[1]))

# For stable releases like 3.9.2
else:
py_version_tuple = tuple(int(x) for x in py_version_tuple) # int tuple
py_version_tuple = tuple(int(x) for x in py_version_tuple)

result = operator_func(system_py_version_tuple, py_version_tuple)

return result

return operator_func(system_py_version_tuple, py_version_tuple)

def get_markers_text(requirement):
if isinstance(requirement, pipfile.PipfileRequirement):
Expand Down
14 changes: 14 additions & 0 deletions test/system/inspect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@ describe('inspect', () => {
},
],
},
{
workspace: 'pip-app-dev-alpha-beta-python-version',
uninstallPackages: [],
pluginOpts: {},
expected: [
{
pkg: {
name: 'requests',
version: '2.31.0',
},
directDeps: ['requests'],
},
],
},
])(
'should get a valid dependency graph for workspace = $workspace',
async ({ workspace, uninstallPackages, pluginOpts, expected }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.31.0 ; python_version >= "3.8.dev0"