Skip to content

Commit

Permalink
manually fix other ruff errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mirpedrol committed Jan 4, 2024
1 parent 4fc75f9 commit d00c1b6
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 83 deletions.
16 changes: 8 additions & 8 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def modules_lint(ctx, tool, dir, registry, key, all, fail_warned, local, passed,
Test modules within a pipeline or a clone of the
nf-core/modules repository.
"""
from nf_core.components.lint import LintException
from nf_core.components.lint import LintExceptionError
from nf_core.modules import ModuleLint

try:
Expand All @@ -960,7 +960,7 @@ def modules_lint(ctx, tool, dir, registry, key, all, fail_warned, local, passed,
)
if len(module_lint.failed) > 0:
sys.exit(1)
except LintException as e:
except LintExceptionError as e:
log.error(e)
sys.exit(1)
except (UserWarning, LookupError) as e:
Expand Down Expand Up @@ -1020,7 +1020,7 @@ def bump_versions(ctx, tool, dir, all, show_all):
the nf-core/modules repo.
"""
from nf_core.modules.bump_versions import ModuleVersionBumper
from nf_core.modules.modules_utils import ModuleException
from nf_core.modules.modules_utils import ModuleExceptionError

try:
version_bumper = ModuleVersionBumper(
Expand All @@ -1030,7 +1030,7 @@ def bump_versions(ctx, tool, dir, all, show_all):
ctx.obj["modules_repo_no_pull"],
)
version_bumper.bump_versions(module=tool, all_modules=all, show_uptodate=show_all)
except ModuleException as e:
except ModuleExceptionError as e:
log.error(e)
sys.exit(1)
except (UserWarning, LookupError) as e:
Expand Down Expand Up @@ -1207,7 +1207,7 @@ def subworkflows_lint(ctx, subworkflow, dir, registry, key, all, fail_warned, lo
Test subworkflows within a pipeline or a clone of the
nf-core/modules repository.
"""
from nf_core.components.lint import LintException
from nf_core.components.lint import LintExceptionError
from nf_core.subworkflows import SubworkflowLint

try:
Expand All @@ -1232,7 +1232,7 @@ def subworkflows_lint(ctx, subworkflow, dir, registry, key, all, fail_warned, lo
)
if len(subworkflow_lint.failed) > 0:
sys.exit(1)
except LintException as e:
except LintExceptionError as e:
log.error(e)
sys.exit(1)
except (UserWarning, LookupError) as e:
Expand Down Expand Up @@ -1647,7 +1647,7 @@ def sync(dir, from_branch, pull_request, github_repository, username, template_y
the pipeline. It is run automatically for all pipelines when ever a
new release of [link=https://github.com/nf-core/tools]nf-core/tools[/link] (and the included template) is made.
"""
from nf_core.sync import PipelineSync, PullRequestException, SyncException
from nf_core.sync import PipelineSync, PullRequestExceptionError, SyncExceptionError
from nf_core.utils import is_pipeline_directory

# Check if pipeline directory contains necessary files
Expand All @@ -1657,7 +1657,7 @@ def sync(dir, from_branch, pull_request, github_repository, username, template_y
sync_obj = PipelineSync(dir, from_branch, pull_request, github_repository, username, template_yaml)
try:
sync_obj.sync()
except (SyncException, PullRequestException) as e:
except (SyncExceptionError, PullRequestExceptionError) as e:
log.error(e)
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion nf_core/components/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
log = logging.getLogger(__name__)


class LintException(Exception):
class LintExceptionError(Exception):
"""Exception raised when there was an error with module or subworkflow linting"""

pass
Expand Down
4 changes: 2 additions & 2 deletions nf_core/components/nfcore_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_inputs_from_main_nf(self):
input_data = data.split("input:")[1].split("output:")[0]
regex = r"(val|path)\s*(\(([^)]+)\)|\s*([^)\s,]+))"
matches = re.finditer(regex, input_data, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
for _, match in enumerate(matches, start=1):
if match.group(3):
inputs.append(match.group(3))
elif match.group(4):
Expand All @@ -187,7 +187,7 @@ def get_outputs_from_main_nf(self):
output_data = data.split("output:")[1].split("when:")[0]
regex = r"emit:\s*([^)\s,]+)"
matches = re.finditer(regex, output_data, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
for _, match in enumerate(matches, start=1):
outputs.append(match.group(1))
log.info(f"Found {len(outputs)} outputs in {self.main_nf}")
self.outputs = outputs
28 changes: 14 additions & 14 deletions nf_core/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import rich
import rich.progress
from git.exc import GitCommandError, InvalidGitRepositoryError
from pkg_resources import parse_version as VersionParser
from pkg_resources import parse_version as version_parser

import nf_core
import nf_core.list
Expand Down Expand Up @@ -1065,10 +1065,10 @@ def get_singularity_images(self, current_revision=""):
self.singularity_pull_image(*container, library, progress)
# Pulling the image was successful, no ContainerError was raised, break the library loop
break
except ContainerError.ImageExists:
except ContainerError.ImageExistsError:
# Pulling not required
break
except ContainerError.RegistryNotFound as e:
except ContainerError.RegistryNotFoundError as e:
self.container_library.remove(library)
# The only library was removed
if not self.container_library:
Expand All @@ -1078,13 +1078,13 @@ def get_singularity_images(self, current_revision=""):
else:
# Other libraries can be used
continue
except ContainerError.ImageNotFound as e:
except ContainerError.ImageNotFoundError as e:
# Try other registries
if e.error_log.absolute_URI:
break # there no point in trying other registries if absolute URI was specified.
else:
continue
except ContainerError.InvalidTag:
except ContainerError.InvalidTagError:
# Try other registries
continue
except ContainerError.OtherError as e:
Expand Down Expand Up @@ -1523,7 +1523,7 @@ def tidy_tags_and_branches(self):
else:
# desired revisions may contain arbitrary branch names that do not correspond to valid sematic versioning patterns.
valid_versions = [
VersionParser(v)
version_parser(v)
for v in desired_revisions
if re.match(r"\d+\.\d+(?:\.\d+)*(?:[\w\-_])*", v)
]
Expand Down Expand Up @@ -1582,7 +1582,7 @@ def __init__(self, container, registry, address, absolute_URI, out_path, singula

for line in error_msg:
if re.search(r"dial\stcp.*no\ssuch\shost", line):
self.error_type = self.RegistryNotFound(self)
self.error_type = self.RegistryNotFoundError(self)
break
elif (
re.search(r"requested\saccess\sto\sthe\sresource\sis\sdenied", line)
Expand All @@ -1594,13 +1594,13 @@ def __init__(self, container, registry, address, absolute_URI, out_path, singula
# unauthorized: authentication required
# Quay.io: StatusCode: 404, <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n']
# ghcr.io: Requesting bearer token: invalid status code from registry 400 (Bad Request)
self.error_type = self.ImageNotFound(self)
self.error_type = self.ImageNotFoundError(self)
break
elif re.search(r"manifest\sunknown", line):
self.error_type = self.InvalidTag(self)
self.error_type = self.InvalidTagError(self)
break
elif re.search(r"Image\sfile\salready\sexists", line):
self.error_type = self.ImageExists(self)
self.error_type = self.ImageExistsError(self)
break
else:
continue
Expand All @@ -1614,7 +1614,7 @@ def __init__(self, container, registry, address, absolute_URI, out_path, singula

raise self.error_type

class RegistryNotFound(ConnectionRefusedError):
class RegistryNotFoundError(ConnectionRefusedError):
"""The specified registry does not resolve to a valid IP address"""

def __init__(self, error_log):
Expand All @@ -1627,7 +1627,7 @@ def __init__(self, error_log):
)
super().__init__(self.message, self.helpmessage, self.error_log)

class ImageNotFound(FileNotFoundError):
class ImageNotFoundError(FileNotFoundError):
"""The image can not be found in the registry"""

def __init__(self, error_log):
Expand All @@ -1643,7 +1643,7 @@ def __init__(self, error_log):

super().__init__(self.message)

class InvalidTag(AttributeError):
class InvalidTagError(AttributeError):
"""Image and registry are valid, but the (version) tag is not"""

def __init__(self, error_log):
Expand All @@ -1652,7 +1652,7 @@ def __init__(self, error_log):
self.helpmessage = f'Please chose a different library than {self.error_log.registry}\nor try to locate the "{self.error_log.address.split(":")[-1]}" version of "{self.error_log.container}" manually.\nPlease troubleshoot the command \n"{" ".join(self.error_log.singularity_command)}" manually.\n'
super().__init__(self.message)

class ImageExists(FileExistsError):
class ImageExistsError(FileExistsError):
"""Image already exists in cache/output directory."""

def __init__(self, error_log):
Expand Down
2 changes: 1 addition & 1 deletion nf_core/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .list import ModuleList
from .modules_json import ModulesJson
from .modules_repo import ModulesRepo
from .modules_utils import ModuleException
from .modules_utils import ModuleExceptionError
from .patch import ModulePatch
from .remove import ModuleRemove
from .update import ModuleUpdate
8 changes: 5 additions & 3 deletions nf_core/modules/bump_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def bump_versions(

# Verify that this is not a pipeline
if not self.repo_type == "modules":
raise nf_core.modules.modules_utils.ModuleException(
raise nf_core.modules.modules_utils.ModuleExceptionError(
"This command only works on the nf-core/modules repository, not on pipelines!"
)

Expand Down Expand Up @@ -102,12 +102,14 @@ def bump_versions(
if module:
self.show_up_to_date = True
if all_modules:
raise nf_core.modules.modules_utils.ModuleException(
raise nf_core.modules.modules_utils.ModuleExceptionError(
"You cannot specify a tool and request all tools to be bumped."
)
nfcore_modules = [m for m in nfcore_modules if m.component_name == module]
if len(nfcore_modules) == 0:
raise nf_core.modules.modules_utils.ModuleException(f"Could not find the specified module: '{module}'")
raise nf_core.modules.modules_utils.ModuleExceptionError(
f"Could not find the specified module: '{module}'"
)

progress_bar = Progress(
"[bold blue]{task.description}",
Expand Down
6 changes: 3 additions & 3 deletions nf_core/modules/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import nf_core.modules.modules_utils
import nf_core.utils
from nf_core.components.lint import ComponentLint, LintException, LintResult
from nf_core.components.lint import ComponentLint, LintExceptionError, LintResult
from nf_core.lint_utils import console

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -118,11 +118,11 @@ def lint(
# Only lint the given module
if module:
if all_modules:
raise LintException("You cannot specify a tool and request all tools to be linted.")
raise LintExceptionError("You cannot specify a tool and request all tools to be linted.")
local_modules = []
remote_modules = [m for m in self.all_remote_components if m.component_name == module]
if len(remote_modules) == 0:
raise LintException(f"Could not find the specified module: '{module}'")
raise LintExceptionError(f"Could not find the specified module: '{module}'")
else:
local_modules = self.all_local_components
remote_modules = self.all_remote_components
Expand Down
4 changes: 2 additions & 2 deletions nf_core/modules/modules_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
log = logging.getLogger(__name__)


class ModuleException(Exception):
class ModuleExceptionError(Exception):
"""Exception raised when there was an error with module commands"""

pass
Expand Down Expand Up @@ -69,7 +69,7 @@ def get_installed_modules(dir: str, repo_type="modules") -> Tuple[List[str], Lis
if os.path.exists(nfcore_modules_dir):
for m in sorted([m for m in os.listdir(nfcore_modules_dir) if not m == "lib"]):
if not os.path.isdir(os.path.join(nfcore_modules_dir, m)):
raise ModuleException(
raise ModuleExceptionError(
f"File found in '{nfcore_modules_dir}': '{m}'! This directory should only contain module directories."
)
m_content = os.listdir(os.path.join(nfcore_modules_dir, m))
Expand Down
6 changes: 3 additions & 3 deletions nf_core/subworkflows/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import nf_core.modules.modules_utils
import nf_core.utils
from nf_core.components.lint import ComponentLint, LintException, LintResult
from nf_core.components.lint import ComponentLint, LintExceptionError, LintResult
from nf_core.lint_utils import console

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -113,11 +113,11 @@ def lint(
# Only lint the given module
if subworkflow:
if all_subworkflows:
raise LintException("You cannot specify a tool and request all tools to be linted.")
raise LintExceptionError("You cannot specify a tool and request all tools to be linted.")
local_subworkflows = []
remote_subworkflows = [s for s in self.all_remote_components if s.component_name == subworkflow]
if len(remote_subworkflows) == 0:
raise LintException(f"Could not find the specified subworkflow: '{subworkflow}'")
raise LintExceptionError(f"Could not find the specified subworkflow: '{subworkflow}'")
else:
local_subworkflows = self.all_local_components
remote_subworkflows = self.all_remote_components
Expand Down
Loading

0 comments on commit d00c1b6

Please sign in to comment.