Skip to content

Commit

Permalink
code maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianegli committed Aug 11, 2022
1 parent cdfa294 commit cd0e5a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 52 deletions.
22 changes: 6 additions & 16 deletions nf_core/modules/bump_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,16 @@ def get_bioconda_version(self, module):
Extract the bioconda version from a module
"""
# Check whether file exists and load it
bioconda_packages = None
bioconda_packages = False
try:
with open(module.main_nf, "r") as fh:
lines = fh.readlines()
except FileNotFoundError as e:
for l in fh:
if "bioconda::" in l:
bioconda_packages = [b for b in l.split() if "bioconda::" in b]
except FileNotFoundError:
log.error(f"Could not read `main.nf` of {module.module_name} module.")
return False

for l in lines:
if re.search("bioconda::", l):
bioconda_packages = [b for b in l.split() if "bioconda::" in b]
if re.search("org/singularity", l):
singularity_tag = l.split("/")[-1].replace('"', "").replace("'", "").split("--")[-1].strip()
if re.search("biocontainers", l):
docker_tag = l.split("/")[-1].replace('"', "").replace("'", "").split("--")[-1].strip()

if bioconda_packages:
return bioconda_packages
else:
return False
return bioconda_packages

def _print_results(self):
"""
Expand Down
19 changes: 6 additions & 13 deletions nf_core/modules/lint/main_nf.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,16 @@ def check_when_section(self, lines):
if len(lines) == 0:
self.failed.append(("when_exist", "when: condition has been removed", self.main_nf))
return
elif len(lines) > 1:
if len(lines) > 1:
self.failed.append(("when_exist", "when: condition has too many lines", self.main_nf))
return
else:
self.passed.append(("when_exist", "when: condition is present", self.main_nf))
self.passed.append(("when_exist", "when: condition is present", self.main_nf))

# Check the condition hasn't been changed.
if lines[0].strip() != "task.ext.when == null || task.ext.when":
self.failed.append(("when_condition", "when: condition has been altered", self.main_nf))
return
else:
self.passed.append(("when_condition", "when: condition is unchanged", self.main_nf))
self.passed.append(("when_condition", "when: condition is unchanged", self.main_nf))


def check_process_section(self, lines, fix_version, progress_bar):
Expand All @@ -222,8 +220,7 @@ def check_process_section(self, lines, fix_version, progress_bar):
if len(lines) == 0:
self.failed.append(("process_exist", "Process definition does not exist", self.main_nf))
return
else:
self.passed.append(("process_exist", "Process definition exists", self.main_nf))
self.passed.append(("process_exist", "Process definition exists", self.main_nf))

# Checks that build numbers of bioconda, singularity and docker container are matching
singularity_tag = "singularity"
Expand Down Expand Up @@ -337,10 +334,7 @@ def check_process_section(self, lines, fix_version, progress_bar):
else:
self.passed.append(("bioconda_latest", f"Conda package is the latest available: `{bp}`", self.main_nf))

if docker_tag == singularity_tag:
return True
else:
return False
return docker_tag == singularity_tag


def _parse_input(self, line_raw):
Expand Down Expand Up @@ -477,7 +471,6 @@ def _container_type(line):
url_match = re.search(url_regex, line, re.S)
if url_match:
return "singularity"
else:
return None
return None
if line.startswith("biocontainers/") or line.startswith("quay.io/"):
return "docker"
44 changes: 21 additions & 23 deletions nf_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,29 +377,28 @@ def poll_nfcore_web_api(api_url, post_data=None):
response = requests.get(api_url, headers={"Cache-Control": "no-cache"})
else:
response = requests.post(url=api_url, data=post_data)
except (requests.exceptions.Timeout):
except requests.exceptions.Timeout:
raise AssertionError(f"URL timed out: {api_url}")
except (requests.exceptions.ConnectionError):
except requests.exceptions.ConnectionError:
raise AssertionError(f"Could not connect to URL: {api_url}")
else:
if response.status_code != 200:
log.debug(f"Response content:\n{response.content}")
raise AssertionError(
f"Could not access remote API results: {api_url} (HTML {response.status_code} Error)"
)
try:
web_response = json.loads(response.content)
if "status" not in web_response:
raise AssertionError()
except (json.decoder.JSONDecodeError, AssertionError, TypeError):
log.debug(f"Response content:\n{response.content}")
raise AssertionError(
f"nf-core website API results response not recognised: {api_url}\n "
"See verbose log for full response"
)
else:
try:
web_response = json.loads(response.content)
if "status" not in web_response:
raise AssertionError()
except (json.decoder.JSONDecodeError, AssertionError, TypeError) as e:
log.debug(f"Response content:\n{response.content}")
raise AssertionError(
f"nf-core website API results response not recognised: {api_url}\n "
"See verbose log for full response"
)
else:
return web_response
return web_response


class GitHub_API_Session(requests_cache.CachedSession):
Expand Down Expand Up @@ -588,20 +587,20 @@ def anaconda_package(dep, dep_channels=None):
anaconda_api_url = f"https://api.anaconda.org/package/{ch}/{depname}"
try:
response = requests.get(anaconda_api_url, timeout=10)
except (requests.exceptions.Timeout):
except requests.exceptions.Timeout:
raise LookupError(f"Anaconda API timed out: {anaconda_api_url}")
except (requests.exceptions.ConnectionError):
except requests.exceptions.ConnectionError:
raise LookupError("Could not connect to Anaconda API")
else:
if response.status_code == 200:
return response.json()
elif response.status_code != 404:
if response.status_code != 404:
raise LookupError(
f"Anaconda API returned unexpected response code `{response.status_code}` for: "
f"{anaconda_api_url}\n{response}"
)
elif response.status_code == 404:
log.debug(f"Could not find `{dep}` in conda channel `{ch}`")
# response.status_code == 404
log.debug(f"Could not find `{dep}` in conda channel `{ch}`")

# We have looped through each channel and had a 404 response code on everything
raise ValueError(f"Could not find Conda dependency using the Anaconda API: '{dep}'")
Expand Down Expand Up @@ -657,15 +656,14 @@ def pip_package(dep):
pip_api_url = f"https://pypi.python.org/pypi/{pip_depname}/json"
try:
response = requests.get(pip_api_url, timeout=10)
except (requests.exceptions.Timeout):
except requests.exceptions.Timeout:
raise LookupError(f"PyPI API timed out: {pip_api_url}")
except (requests.exceptions.ConnectionError):
except requests.exceptions.ConnectionError:
raise LookupError(f"PyPI API Connection error: {pip_api_url}")
else:
if response.status_code == 200:
return response.json()
else:
raise ValueError(f"Could not find pip dependency using the PyPI API: `{dep}`")
raise ValueError(f"Could not find pip dependency using the PyPI API: `{dep}`")


def get_biocontainer_tag(package, version):
Expand Down

0 comments on commit cd0e5a4

Please sign in to comment.