Skip to content

Commit

Permalink
revert Python 3.8 changes for packages/packages_for_pulsar_by_dep_dag…
Browse files Browse the repository at this point in the history
….txt
  • Loading branch information
mr-c committed Nov 1, 2023
1 parent fbb51b8 commit 81d7c13
Show file tree
Hide file tree
Showing 46 changed files with 148 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_galaxy_packages_for_pulsar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8']
python-version: ['3.7'] # don't upgrade, see https://github.com/galaxyproject/galaxy/pull/16649
steps:
- uses: actions/checkout@v3
with:
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/files/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ def _get_error_msg_for(rule_name: str) -> str:

def uri_join(*args):
# url_join doesn't work with non-standard scheme
if "://" in (arg0 := args[0]):
arg0 = args[0]
if "://" in arg0:
scheme, path = arg0.split("://", 1)
rval = f"{scheme}://{slash_join(path, *args[1:]) if path else slash_join(*args[1:])}"
else:
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/files/sources/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def _serialization_props(self, user_context=None) -> HTTPFilesSourceProperties:
return cast(HTTPFilesSourceProperties, effective_props)

def score_url_match(self, url: str):
if match := self._url_regex.match(url):
match = self._url_regex.match(url)
if match:
return match.span()[1]
else:
return 0
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/job_metrics/instrumenters/cgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class CgroupPlugin(InstrumentPlugin):
def __init__(self, **kwargs):
self.verbose = asbool(kwargs.get("verbose", False))
self.cgroup_mount = kwargs.get("cgroup_mount", "/sys/fs/cgroup")
if params_str := kwargs.get("params", None):
params_str = kwargs.get("params", None)
if params_str:
params = [v.strip() for v in params_str.split(",")]
else:
params = list(TITLES.keys())
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/job_metrics/instrumenters/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class EnvPlugin(InstrumentPlugin):
default_safety = Safety.UNSAFE

def __init__(self, **kwargs):
if variables_str := kwargs.get("variables", None):
variables_str = kwargs.get("variables", None)
if variables_str:
self.variables = [v.strip() for v in variables_str.split(",")]
else:
self.variables = None
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/objectstore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,8 @@ def _create(self, obj, **kwargs):
return self.backends[object_store_id]

def _call_method(self, method, obj, default, default_is_exception, **kwargs):
if (object_store_id := self.__get_store_id_for(obj, **kwargs)) is not None:
object_store_id = self.__get_store_id_for(obj, **kwargs)
if object_store_id is not None:
return self.backends[object_store_id].__getattribute__(method)(obj, **kwargs)
if default_is_exception:
raise default(
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/objectstore/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def check_cache(cache_target: CacheTarget):
# Initiate cleaning once we reach cache_monitor_cache_limit percentage of the defined cache size?
# Convert GBs to bytes for comparison
cache_size_in_gb = cache_target.size * ONE_GIGA_BYTE
if total_size > (cache_limit := cache_size_in_gb * cache_target.limit):
cache_limit = cache_size_in_gb * cache_target.limit
if total_size > cache_limit:
log.debug(
"Initiating cache cleaning: current cache size: %s; clean until smaller than: %s",
nice_size(total_size),
Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/objectstore/pithos.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def to_dict(self):
def _authenticate(self):
auth = self.config_dict["auth"]
url, token = auth["url"], auth["token"]
if ca_certs := auth.get("ca_certs"):
ca_certs = auth.get("ca_certs")
if ca_certs:
utils.https.patch_with_certs(ca_certs)
elif auth.get("ignore_ssl").lower() in ("true", "yes", "on"):
utils.https.patch_ignore_ssl()
Expand Down Expand Up @@ -411,7 +412,8 @@ def _update_from_file(self, obj, **kwargs):

path = self._construct_path(obj, **kwargs)
cache_path = self._get_cache_path(path)
if file_name := kwargs.get("file_name"):
file_name = kwargs.get("file_name")
if file_name:
source_path = os.path.abspath(file_name)
try:
if source_path != cache_path:
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/biotools/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def simplify_edam_dicts(a_list: List[Dict[str, str]]):

def simplify_edam_dict(as_dict: Dict[str, str]) -> Optional[str]:
uri = as_dict["uri"]
if match := TERM_PATTERN.match(uri):
match = TERM_PATTERN.match(uri)
if match:
return match.group(1)
else:
# TODO: log problem...
Expand Down
7 changes: 5 additions & 2 deletions lib/galaxy/tool_util/cwl/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ def id(self):
return raw_id

def galaxy_id(self) -> str:
raw_id = self.id
tool_id = None
# don't reduce "search.cwl#index" to search
if raw_id := self.id:
if raw_id:
tool_id = os.path.basename(raw_id)
# tool_id = os.path.splitext(os.path.basename(raw_id))[0]
if not tool_id:
Expand Down Expand Up @@ -228,7 +229,9 @@ def doc(self):
return doc

def label(self):
if (label := self._tool.tool.get("label")) is not None:
label = self._tool.tool.get("label")

if label is not None:
return label.partition(":")[0] # return substring before ':'
else:
return ""
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/cwl/runtime_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def move_output(output, target_path, output_name=None):
file_description = file_dict_to_description(output)
file_description.write_to(target_path)

if secondary_files := output.get("secondaryFiles", []):
secondary_files = output.get("secondaryFiles", [])
if secondary_files:
order = []
index_contents = {"order": order}

Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/cwl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ def replacement_file(value):

return value

secondary_files = value.get("secondaryFiles", [])
secondary_files_tar_path = None
if secondary_files := value.get("secondaryFiles", []):
if secondary_files:
tmp = tempfile.NamedTemporaryFile(delete=False)
tf = tarfile.open(fileobj=tmp, mode="w:")
order: List[str] = []
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ def configure_and_load(
self.parse_column_spec(config_element)

# store repo info if available:
if (repo_elem := config_element.find("tool_shed_repository")) is not None:
repo_elem = config_element.find("tool_shed_repository")
if repo_elem is not None:
repo_info = dict(
tool_shed=repo_elem.find("tool_shed").text,
name=repo_elem.find("repository_name").text,
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/data/bundles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ def _xml_to_data_table_output_column_move(move_elem: Element) -> DataTableBundle
def _xml_to_data_table_output_column_translation(
value_translation_elem: Element,
) -> Optional[DataTableBundleProcessorDataTableOutputColumnTranslation]:
if (value_translation := value_translation_elem.text) is not None:
value_translation = value_translation_elem.text
if value_translation is not None:
value_translation_type = value_translation_elem.get("type", DEFAULT_VALUE_TRANSLATION_TYPE)
return DataTableBundleProcessorDataTableOutputColumnTranslation(
value=value_translation, type=value_translation_type
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/deps/brew_exts.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ def __action(sys):
def recipe_cellar_path(cellar_path, recipe, version):
recipe_base = recipe.split("/")[-1]
recipe_base_path = os.path.join(cellar_path, recipe_base, version)
if revision_paths := glob.glob(f"{recipe_base_path}_*"):
revision_paths = glob.glob(f"{recipe_base_path}_*")
if revision_paths:
revisions = map(lambda x: int(x.rsplit("_", 1)[-1]), revision_paths)
max_revision = max(revisions)
recipe_path = "%s_%d" % (recipe_base_path, max_revision)
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/deps/conda_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import platform
import re
import shlex
import shutil
import sys
import tempfile
Expand All @@ -29,6 +28,7 @@
commands,
download_to_file,
listify,
shlex_join,
smart_str,
which,
)
Expand Down Expand Up @@ -253,7 +253,7 @@ def exec_command(self, operation: str, args: List[str], stdout_path: Optional[st
env = {}
if self.condarc_override:
env["CONDARC"] = self.condarc_override
cmd_string = shlex.join(cmd)
cmd_string = shlex_join(cmd)
kwds = dict()
try:
if stdout_path:
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/deps/container_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ def add_var(name, value):

# Not all tools have a tool_directory - strip this out if supplied by
# job_conf.
if (tool_directory_index := volumes_str.find("$tool_directory")) > 0:
tool_directory_index = volumes_str.find("$tool_directory")
if tool_directory_index > 0:
end_index = volumes_str.find(",", tool_directory_index)
if end_index < 0:
end_index = len(volumes_str)
Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/tool_util/deps/container_resolvers/mulled.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ def docker_cached_container_description(
return None

cached_images = list_docker_cached_mulled_images(namespace, hash_func=hash_func, resolution_cache=resolution_cache)
image = find_best_matching_cached_image(targets, cached_images, hash_func)

container = None
if image := find_best_matching_cached_image(targets, cached_images, hash_func):
if image:
container = ContainerDescription(
image.image_identifier,
type="docker",
Expand All @@ -350,9 +351,10 @@ def singularity_cached_container_description(
return None

cached_images = cache_directory.list_cached_mulled_images_from_path()
image = find_best_matching_cached_image(targets, cached_images, hash_func)

container = None
if image := find_best_matching_cached_image(targets, cached_images, hash_func):
if image:
container = ContainerDescription(
os.path.abspath(os.path.join(cache_directory.path, image.image_identifier)),
type="singularity",
Expand Down
9 changes: 6 additions & 3 deletions lib/galaxy/tool_util/deps/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,15 @@ def __build_container_id_from_parts(
) -> str:
repo = ""
owner = ""
if (repo_key := f"{container_type}_repo_{mode}") in destination_info:
repo_key = f"{container_type}_repo_{mode}"
owner_key = f"{container_type}_owner_{mode}"
if repo_key in destination_info:
repo = f"{destination_info[repo_key]}/"
if (owner_key := f"{container_type}_owner_{mode}") in destination_info:
if owner_key in destination_info:
owner = f"{destination_info[owner_key]}/"
cont_id = repo + owner + destination_info[f"{container_type}_image_{mode}"]
if (tag_key := f"{container_type}_tag_{mode}") in destination_info:
tag_key = f"{container_type}_tag_{mode}"
if tag_key in destination_info:
cont_id += f":{destination_info[tag_key]}"
return cont_id

Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/deps/dockerfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def dockerfile_build(path, dockerfile=None, error=log.error, **kwds):
commands.execute(docker_command_parts)

commands.execute(docker_command_parts)
if docker_image_cache := kwds["docker_image_cache"]:
docker_image_cache = kwds["docker_image_cache"]
if docker_image_cache:
destination = docker_cache_path(docker_image_cache, image_identifier)
save_image_command_parts = docker_util.build_save_image_command(
image_identifier, destination, **docker_host_args(**kwds)
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/deps/mulled/mulled_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import json
import logging
import os
import shlex
import shutil
import stat
import string
Expand All @@ -39,6 +38,7 @@
commands,
download_to_file,
safe_makedirs,
shlex_join,
unicodify,
)
from ._cli import arg_parser
Expand Down Expand Up @@ -335,7 +335,7 @@ def mull_targets(
involucro_args.insert(6, "-set")
involucro_args.insert(7, f"TEST_BINDS={','.join(test_bind)}")
cmd = involucro_context.build_command(involucro_args)
print(f"Executing: {shlex.join(cmd)}")
print(f"Executing: {shlex_join(cmd)}")
if dry_run:
return 0
ensure_installed(involucro_context, True)
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/deps/mulled/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def parse_tag(tag: str) -> PARSED_TAG:
version = tag.rsplit(":")[-1]
build_string = "-1"
build_number = -1
if match := BUILD_NUMBER_REGEX.search(version):
match = BUILD_NUMBER_REGEX.search(version)
if match:
build_number = int(match.group(0))
if "--" in version:
version, build_string = version.rsplit("--", 1)
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/deps/resolvers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ def _expand_specs(self, requirement):
version = requirement.version
specs = requirement.specs

if (spec := self._find_specification(specs)) is not None:
spec = self._find_specification(specs)
if spec is not None:
name = spec.short_name
version = spec.version or version

Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/linters/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
def lint_general(tool_source, lint_ctx):
"""Check tool version, name, and id."""
# determine line to report for general problems with outputs
if tool_xml := getattr(tool_source, "xml_tree", None):
tool_xml = getattr(tool_source, "xml_tree", None)
if tool_xml:
tool_node = tool_xml.getroot()
else:
tool_node = None
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/linters/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def lint_help(tool_xml, lint_ctx):
if "TODO" in help_text:
lint_ctx.warn("Help contains TODO text.", node=helps[0])

if invalid_rst := rst_invalid(help_text):
invalid_rst = rst_invalid(help_text)
if invalid_rst:
lint_ctx.warn(f"Invalid reStructuredText found in help - [{invalid_rst}].", node=helps[0])
else:
lint_ctx.valid("Help contains valid reStructuredText.", node=helps[0])
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/linters/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ def lint_inputs(tool_source: "ToolSource", lint_ctx: "LintContext"):
lint_ctx.warn("Found no input parameters.", node=tool_node)

# check if there is an output with the same name as an input
if (outputs := tool_xml.find("./outputs")) is not None:
outputs = tool_xml.find("./outputs")
if outputs is not None:
for output in outputs:
if output.get("name") in input_names:
lint_ctx.error(
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/linters/stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def _lint_regex(tool_xml, child, lint_ctx):
for key in child.attrib.keys():
if key not in ["description", "level", "match", "source"]:
lint_ctx.warn(f"Unknown attribute [{key}] encountered on regex tag.", node=child)
if match := child.attrib.get("match"):
match = child.attrib.get("match")
if match:
try:
re.compile(match)
except Exception as e:
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/parser/cwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def _parse_output(self, tool, output_instance):

def parse_requirements_and_containers(self):
containers = []
if docker_identifier := self.tool_proxy.docker_identifier():
docker_identifier = self.tool_proxy.docker_identifier()
if docker_identifier:
containers.append({"type": "docker", "identifier": docker_identifier})

software_requirements = self.tool_proxy.software_requirements()
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tool_util/parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ def parse_tests_to_dict(self) -> ToolSourceTests:
return {"tests": []}

def __str__(self):
if source_path := self.source_path:
source_path = self.source_path
if source_path:
as_str = f"{self.__class__.__name__}[{source_path}]"
else:
as_str = f"{self.__class__.__name__}[In-memory]"
Expand Down
Loading

0 comments on commit 81d7c13

Please sign in to comment.