Skip to content

Commit

Permalink
Vendorise packaging.versions.LegacyVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed May 5, 2023
1 parent 853d009 commit 5333cbd
Show file tree
Hide file tree
Showing 17 changed files with 360 additions and 99 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/dependencies/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ myst-parser==1.0.0 ; python_version >= "3.7" and python_version < "3.12"
numpy==1.21.6 ; python_version >= "3.7" and python_version < "3.8"
numpy==1.24.2 ; python_version >= "3.8" and python_version < "3.12"
outcome==1.2.0 ; python_version >= "3.7" and python_version < "3.12"
packaging==21.3 ; python_version >= "3.7" and python_version < "3.12"
packaging==23.1 ; python_version >= "3.7" and python_version < "3.12"
pathspec==0.11.1 ; python_version >= "3.7" and python_version < "3.12"
pillow==9.5.0 ; python_version >= "3.7" and python_version < "3.12"
pkce==1.0.3 ; python_version >= "3.7" and python_version < "3.12"
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/dependencies/pinned-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ numpy==1.21.6 ; python_version >= "3.7" and python_version < "3.8"
numpy==1.24.2 ; python_version >= "3.8" and python_version < "3.12"
oauthlib==3.2.2 ; python_version >= "3.7" and python_version < "3.12"
oyaml==1.0 ; python_version >= "3.7" and python_version < "3.12"
packaging==21.3 ; python_version >= "3.7" and python_version < "3.12"
packaging==23.1 ; python_version >= "3.7" and python_version < "3.12"
paramiko==3.1.0 ; python_version >= "3.7" and python_version < "3.12"
parse==1.19.0 ; python_version >= "3.7" and python_version < "3.12"
parsley==1.3 ; python_version >= "3.7" and python_version < "3.12"
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
TYPE_CHECKING,
)

import packaging.version
import yaml
from packaging.version import Version
from pulsar.client.staging import COMMAND_VERSION_FILENAME

from galaxy import (
Expand Down Expand Up @@ -1089,7 +1089,7 @@ def job_io(self):
@property
def outputs_directory(self):
"""Default location of ``outputs_to_working_directory``."""
return None if self.created_with_galaxy_version < packaging.version.parse("20.01") else "outputs"
return None if self.created_with_galaxy_version < Version("20.01") else "outputs"

@property
def outputs_to_working_directory(self):
Expand All @@ -1098,7 +1098,7 @@ def outputs_to_working_directory(self):
@property
def created_with_galaxy_version(self):
galaxy_version = self.get_job().galaxy_version or "19.05"
return packaging.version.parse(galaxy_version)
return Version(galaxy_version)

@property
def dependency_shell_commands(self):
Expand Down
14 changes: 7 additions & 7 deletions lib/galaxy/jobs/runners/pulsar.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
Dict,
)

import packaging.version
import pulsar.core
import yaml
from packaging.version import Version
from pulsar.client import (
build_client_manager,
CLIENT_INPUT_PATH_TYPES,
Expand Down Expand Up @@ -64,9 +64,9 @@
)

MINIMUM_PULSAR_VERSIONS = {
"_default_": packaging.version.parse("0.7.0.dev3"),
"remote_metadata": packaging.version.parse("0.8.0"),
"remote_container_handling": packaging.version.parse("0.9.1.dev0"), # probably 0.10 ultimately?
"_default_": Version("0.7.0.dev3"),
"remote_metadata": Version("0.8.0"),
"remote_container_handling": Version("0.9.1.dev0"), # probably 0.10 ultimately?
}

NO_REMOTE_GALAXY_FOR_METADATA_MESSAGE = "Pulsar misconfiguration - Pulsar client configured to set metadata remotely, but remote Pulsar isn't properly configured with a galaxy_home directory."
Expand Down Expand Up @@ -498,7 +498,7 @@ def __prepare_job(self, job_wrapper, job_destination):
pulsar_version=pulsar_version,
)
rewrite_paths = not PulsarJobRunner.__rewrite_parameters(client)
if pulsar_version < packaging.version.parse("0.14.999") and rewrite_paths:
if pulsar_version < Version("0.14.999") and rewrite_paths:
job_wrapper.disable_commands_in_new_shell()
container = None
if remote_container is None:
Expand Down Expand Up @@ -810,15 +810,15 @@ def __client_outputs(self, client, job_wrapper):

@staticmethod
def pulsar_version(remote_job_config):
pulsar_version = packaging.version.parse(remote_job_config.get("pulsar_version", "0.6.0"))
pulsar_version = Version(remote_job_config.get("pulsar_version", "0.6.0"))
return pulsar_version

@staticmethod
def check_job_config(remote_job_config, check_features=None):
check_features = check_features or {}
# 0.6.0 was newest Pulsar version that did not report it's version.
pulsar_version = PulsarJobRunner.pulsar_version(remote_job_config)
needed_version = packaging.version.parse("0.0.0")
needed_version = Version("0.0.0")
log.info(f"pulsar_version is {pulsar_version}")
for feature, needed in list(check_features.items()) + [("_default_", True)]:
if not needed:
Expand Down
28 changes: 14 additions & 14 deletions lib/galaxy/tool_util/deps/conda_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Union,
)

import packaging.version
from packaging.version import Version

from galaxy.util import (
commands,
Expand Down Expand Up @@ -87,7 +87,7 @@ def find_conda_prefix() -> str:
class CondaContext(installable.InstallableContext):
installable_description = "Conda"
_conda_build_available: Optional[bool]
_conda_version: Optional[Union[packaging.version.Version, packaging.version.LegacyVersion]]
_conda_version: Optional[Version]
_experimental_solver_available: Optional[bool]

def __init__(
Expand Down Expand Up @@ -132,10 +132,10 @@ def _reset_conda_properties(self) -> None:
self._experimental_solver_available = None

@property
def conda_version(self) -> Union[packaging.version.Version, packaging.version.LegacyVersion]:
def conda_version(self) -> Version:
if self._conda_version is None:
self._guess_conda_properties()
assert isinstance(self._conda_version, (packaging.version.Version, packaging.version.LegacyVersion))
assert isinstance(self._conda_version, Version)
return self._conda_version

@property
Expand All @@ -147,12 +147,12 @@ def conda_build_available(self) -> bool:

def _guess_conda_properties(self) -> None:
info = self.conda_info()
self._conda_version = packaging.version.parse(info["conda_version"])
self._conda_version = Version(info["conda_version"])
self._conda_build_available = False
conda_build_version = info.get("conda_build_version")
if conda_build_version and conda_build_version != "not installed":
try:
packaging.version.parse(conda_build_version)
Version(conda_build_version)
self._conda_build_available = True
except Exception:
pass
Expand All @@ -169,9 +169,9 @@ def _override_channels_args(self) -> List[str]:
@property
def _experimental_solver_args(self) -> List[str]:
if self._experimental_solver_available is None:
self._experimental_solver_available = self.conda_version >= packaging.version.parse(
"4.12.0"
) and self.is_package_installed("conda-libmamba-solver")
self._experimental_solver_available = self.conda_version >= Version("4.12.0") and self.is_package_installed(
"conda-libmamba-solver"
)
if self._experimental_solver_available:
return ["--experimental-solver", "libmamba"]
else:
Expand Down Expand Up @@ -282,7 +282,7 @@ def exec_create(self, args: Iterable[str], allow_local: bool = True, stdout_path
for try_strict in [True, False]:
create_args = ["-y", "--quiet"]
if try_strict:
if self.conda_version >= packaging.version.parse("4.7.5"):
if self.conda_version >= Version("4.7.5"):
create_args.append("--strict-channel-priority")
else:
continue
Expand Down Expand Up @@ -313,7 +313,7 @@ def exec_install(self, args: Iterable[str], allow_local: bool = True, stdout_pat
for try_strict in [True, False]:
install_args = ["-y"]
if try_strict:
if self.conda_version >= packaging.version.parse("4.7.5"):
if self.conda_version >= Version("4.7.5"):
install_args.append("--strict-channel-priority")
else:
continue
Expand Down Expand Up @@ -567,7 +567,7 @@ def best_search_result(
# the latest update time.
hits = json.loads(res).get(conda_target.package, [])[::-1]
hits = sorted(hits, key=lambda hit: hit["build_number"], reverse=True)
hits = sorted(hits, key=lambda hit: packaging.version.parse(hit["version"]), reverse=True)
hits = sorted(hits, key=lambda hit: Version(hit["version"]), reverse=True)
except commands.CommandLineException as e:
log.error(f"Could not execute: '{e.command}'\n{e}")
hits = []
Expand Down Expand Up @@ -632,8 +632,8 @@ def build_isolated_environment(
# Adjust fix if they fix Conda - xref
# - https://github.com/galaxyproject/galaxy/issues/3635
# - https://github.com/conda/conda/issues/2035
offline_works = (conda_context.conda_version < packaging.version.parse("4.3")) or (
conda_context.conda_version >= packaging.version.parse("4.4")
offline_works = (conda_context.conda_version < Version("4.3")) or (
conda_context.conda_version >= Version("4.4")
)
if offline_works:
create_args.append("--offline")
Expand Down
7 changes: 4 additions & 3 deletions lib/galaxy/tool_util/deps/mulled/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
Union,
)

import packaging.version
import requests
from conda_package_streaming.package_streaming import stream_conda_info
from conda_package_streaming.url import stream_conda_info as stream_conda_info_from_url

from galaxy.tool_util.version import parse_version

if TYPE_CHECKING:
from galaxy.tool_util.deps.container_resolvers import ResolutionCache

Expand Down Expand Up @@ -189,8 +190,8 @@ def parse_tag(tag):
build_number = -1
return PARSED_TAG(
tag=tag,
version=packaging.version.parse(version),
build_string=packaging.version.parse(build_string),
version=parse_version(version),
build_string=parse_version(build_string),
build_number=build_number,
)

Expand Down
9 changes: 6 additions & 3 deletions lib/galaxy/tool_util/linters/general.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""This module contains linting functions for general aspects of the tool."""
import re

import packaging.version
from galaxy.tool_util.version import (
LegacyVersion,
parse_version,
)

ERROR_VERSION_MSG = "Tool version is missing or empty."
WARN_VERSION_MSG = "Tool version [%s] is not compliant with PEP 440."
Expand Down Expand Up @@ -34,10 +37,10 @@ def lint_general(tool_source, lint_ctx):
else:
tool_node = None
version = tool_source.parse_version() or ""
parsed_version = packaging.version.parse(version)
parsed_version = parse_version(version)
if not version:
lint_ctx.error(ERROR_VERSION_MSG, node=tool_node)
elif isinstance(parsed_version, packaging.version.LegacyVersion):
elif isinstance(parsed_version, LegacyVersion):
lint_ctx.warn(WARN_VERSION_MSG % version, node=tool_node)
elif version != version.strip():
lint_ctx.warn(WARN_WHITESPACE_PRESUFFIX % ("Tool version", version), node=tool_node)
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/tool_util/parser/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Optional,
)

import packaging.version
from packaging.version import Version

from galaxy.tool_util.deps import requirements
from galaxy.tool_util.parser.util import (
Expand Down Expand Up @@ -525,7 +525,7 @@ def parse_stdio(self):

def parse_strict_shell(self):
command_el = self._command_el
if packaging.version.parse(self.parse_profile()) < packaging.version.parse("20.09"):
if Version(self.parse_profile()) < Version("20.09"):
default = "False"
else:
default = "True"
Expand Down Expand Up @@ -558,7 +558,7 @@ def parse_tests_to_dict(self) -> ToolSourceTests:

return rval

def parse_profile(self):
def parse_profile(self) -> str:
# Pre-16.04 or default XML defaults
# - Use standard error for error detection.
# - Don't run shells with -e
Expand All @@ -573,7 +573,7 @@ def parse_license(self):
def parse_python_template_version(self):
python_template_version = self.root.get("python_template_version")
if python_template_version is not None:
python_template_version = packaging.version.Version(python_template_version)
python_template_version = Version(python_template_version)
return python_template_version

def parse_creator(self):
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/toolbox/lineages/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
List,
)

import packaging.version
from sortedcontainers import SortedSet

from galaxy.tool_util.version import parse_version
from galaxy.util.tool_version import remove_version_from_guid


Expand Down Expand Up @@ -46,7 +46,7 @@ class ToolLineage:

def __init__(self, tool_id, **kwds):
self.tool_id = tool_id
self.tool_versions = SortedSet(key=packaging.version.parse)
self.tool_versions = SortedSet(key=parse_version)

@property
def tool_ids(self) -> List[str]:
Expand Down
7 changes: 2 additions & 5 deletions lib/galaxy/tool_util/verify/interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
)

import requests
from packaging.version import (
parse as parse_version,
Version,
)
from packaging.version import Version
from requests import Response
from requests.cookies import RequestsCookieJar
from typing_extensions import (
Expand Down Expand Up @@ -200,7 +197,7 @@ def __init__(self, **kwds):
@property
def target_galaxy_version(self):
if self._target_galaxy_version is None:
self._target_galaxy_version = parse_version(self._get("version").json()["version_major"])
self._target_galaxy_version = Version(self._get("version").json()["version_major"])
return self._target_galaxy_version

@property
Expand Down
Loading

0 comments on commit 5333cbd

Please sign in to comment.