Skip to content

Commit ebfcedd

Browse files
fix linter errors
and restore lint_urls for lint_tool_dependencies_urls
1 parent 7aca51a commit ebfcedd

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

planemo/linters/biocontainer_registered.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Ensure best-practice biocontainer registered for this tool."""
22

33
from typing import (
4+
List,
45
Optional,
56
TYPE_CHECKING,
67
)
@@ -42,7 +43,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
4243
name = mulled_container_name("biocontainers", targets)
4344
if not name:
4445
requirements_node = xml_node_from_toolsource(tool_source, "requirements")
45-
lint_ctx.warn(MESSAGE_WARN_NO_CONTAINER, linter=cls.name(), node=requirements)
46+
lint_ctx.warn(MESSAGE_WARN_NO_CONTAINER, linter=cls.name(), node=requirements_node)
4647

4748

4849
def mulled_container_name(namespace: str, targets: List[CondaTarget]) -> Optional[str]:

planemo/linters/conda_requirements.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616

1717
if TYPE_CHECKING:
18+
from galaxy.tool_util.deps.conda_util import CondaTarget
1819
from galaxy.tool_util.lint import LintContext
1920
from galaxy.tool_util.parser.interface import ToolSource
2021

@@ -32,7 +33,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
3233
if best_hit and exact:
3334
message = f"Requirement [{conda_target_str}] matches target in best practice Conda channel [{best_hit.get('channel')}]."
3435
requirements_node = xml_node_from_toolsource(tool_source, "requirements")
35-
lint_ctx.info(message, linter=cls.name(), node=requirements_nodes)
36+
lint_ctx.info(message, linter=cls.name(), node=requirements_node)
3637

3738

3839
class CondaRequirementInexact(Linter):
@@ -63,7 +64,7 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"):
6364
lint_ctx.warn(message, linter=cls.name(), node=requirements_node)
6465

6566

66-
def _requirements_conda_targets(tool_source: "ToolSource") -> Generator[CondaTarget]:
67+
def _requirements_conda_targets(tool_source: "ToolSource") -> Generator["CondaTarget"]:
6768
requirements, *_ = tool_source.parse_requirements_and_containers()
6869
for requirement in requirements:
6970
conda_target = requirement_to_conda_targets(requirement)

planemo/shed_lint.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import os
44
import xml.etree.ElementTree as ET
55
from typing import TYPE_CHECKING
6+
from urllib.request import urlopen
67

8+
import requests
79
import yaml
810
from galaxy.tool_util.lint import lint_tool_source_with
911
from galaxy.tool_util.linters.help import rst_invalid
@@ -17,6 +19,7 @@
1719
)
1820
from planemo.shed import (
1921
CURRENT_CATEGORIES,
22+
find_urls_for_xml,
2023
REPO_TYPE_SUITE,
2124
REPO_TYPE_TOOL_DEP,
2225
REPO_TYPE_UNRESTRICTED,
@@ -188,8 +191,43 @@ def lint_readme(realized_repository, lint_ctx):
188191

189192

190193
def lint_tool_dependencies_urls(realized_repository, lint_ctx):
191-
192-
194+
195+
def lint_urls(root, lint_ctx):
196+
"""Find referenced URLs and verify they are valid.
197+
198+
note this function was used previously for tools (URLs in help) and tool dependency files
199+
the former has been rewritten and therefore the function has been moved here
200+
"""
201+
urls, _ = find_urls_for_xml(root)
202+
for url in urls:
203+
is_valid = True
204+
if url.startswith("http://") or url.startswith("https://"):
205+
headers = None
206+
r = None
207+
try:
208+
r = requests.get(url, headers=headers, stream=True)
209+
r.raise_for_status()
210+
next(r.iter_content(1000))
211+
except Exception as e:
212+
if r is not None and r.status_code == 429:
213+
# too many requests
214+
pass
215+
if r is not None and r.status_code in [403, 503] and "cloudflare" in r.text:
216+
# CloudFlare protection block
217+
pass
218+
else:
219+
is_valid = False
220+
lint_ctx.error(f"Error '{e}' accessing {url}")
221+
else:
222+
try:
223+
with urlopen(url) as handle:
224+
handle.read(100)
225+
except Exception as e:
226+
is_valid = False
227+
lint_ctx.error(f"Error '{e}' accessing {url}")
228+
if is_valid:
229+
lint_ctx.info("URL OK %s" % url)
230+
193231
path = realized_repository.real_path
194232
tool_dependencies = os.path.join(path, "tool_dependencies.xml")
195233
if not os.path.exists(tool_dependencies):

0 commit comments

Comments
 (0)