Skip to content

Commit 82d9ad3

Browse files
Patches for P013, P016, W001, W003 and W005. Updated path of tests and all pass. Bumped SoMEF version to 0.10.3
1 parent 2c980b1 commit 82d9ad3

40 files changed

Lines changed: 388 additions & 355 deletions

poetry.lock

Lines changed: 185 additions & 159 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ readme = "README.md"
77
packages = [{include = "rsmetacheck", from = "src"}]
88

99
[tool.poetry.dependencies]
10-
python = ">=3.11,<3.13"
11-
requests = "*"
12-
somef = "0.10.1"
10+
python = ">=3.11,<3.13"
11+
requests = "*"
12+
somef = "0.10.3"
1313

1414
[tool.poetry.scripts]
1515
rsmetacheck = "rsmetacheck.cli:cli"

src/rsmetacheck/scripts/pitfalls/p013.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def detect_license_no_version_pitfall(somef_data: Dict, file_name: str) -> Dict:
2626
"requirements.txt", "setup.py"]
2727

2828
versioned_patterns = {
29-
"GPL": r"\bGPL[-\s]?\d+(\.\d+)?",
30-
"LGPL": r"\bLGPL[-\s]?\d+(\.\d+)?",
31-
"AGPL": r"\bAGPL[-\s]?\d+(\.\d+)?",
32-
"Apache": r"\bApache[-\s]?\d+(\.\d+)?",
33-
"CC": r"\bCC[- ]BY[-\s]?\d+(\.\d+)?",
29+
"GPL": r"\bGPL[-\s]?\(?\s*(?:>=?|<=?|>|<|=)?\s*\d+(\.\d+)?\)?",
30+
"LGPL": r"\bLGPL[-\s]?\(?\s*(?:>=?|<=?|>|<|=)?\s*\d+(\.\d+)?\)?",
31+
"AGPL": r"\bAGPL[-\s]?\(?\s*(?:>=?|<=?|>|<|=)?\s*\d+(\.\d+)?\)?",
32+
"Apache": r"\bApache[-\s]?\(?\s*(?:>=?|<=?|>|<|=)?\s*\d+(\.\d+)?\)?",
33+
"CC": r"\bCC[- ]BY[-\s]?\(?\s*(?:>=?|<=?|>|<|=)?\s*\d+(\.\d+)?\)?",
3434
"BSD": r"\bBSD[-\s]\d+[-\s]Clause"
3535
}
3636

src/rsmetacheck/scripts/pitfalls/p016.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ def normalize_repository_url(url: str) -> str:
1111
url = url.lower().strip()
1212

1313
url = re.sub(r'^git\+', '', url) # Remove git+ prefix
14+
url = re.sub(r'^http://', 'https://', url) # Normalize http to https
15+
url = url.replace('www.github.com', 'github.com')
1416

1517
url = re.sub(r'/$', '', url) # Remove trailing slash
1618
url = re.sub(r'\.git$', '', url) # Remove .git suffix
19+
url = re.sub(r'/$', '', url) # Remove trailing slash again if it was .git/
1720

1821
if url.startswith('git@'):
1922
url = re.sub(r'^git@([^:]+):', r'https://\1/', url)

src/rsmetacheck/scripts/warnings/w001.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Dict, List, Tuple, Optional
2+
import re
23
from rsmetacheck.utils.pitfall_utils import extract_metadata_source_filename
34

45

@@ -31,25 +32,14 @@ def extract_requirements_from_metadata(somef_data: Dict) -> List[Dict]:
3132
return results
3233

3334

34-
def check_requirement_has_version(requirement: Dict) -> bool:
35+
def check_requirement_has_version(req_name: str) -> bool:
3536
"""
3637
Check if a single requirement has version information.
3738
Returns True if version is present and non-empty, False otherwise.
3839
"""
39-
if "version" in requirement:
40-
version = requirement["version"]
41-
# Version should be non-empty string
42-
if isinstance(version, str) and version.strip():
43-
return True
44-
45-
if "value" in requirement:
46-
value = requirement["value"]
47-
if isinstance(value, str):
48-
49-
version_operators = ["==", ">=", "<=", ">", "<", "~=", "!=", "^", "~"]
50-
if any(op in value for op in version_operators):
51-
return True
52-
40+
version_operators = ["==", ">=", "<=", ">", "<", "~=", "!=", "^", "~"]
41+
if any(op in req_name for op in version_operators) or re.search(r'\bv?\d+(\.\d+)+\b', req_name):
42+
return True
5343
return False
5444

5545

@@ -67,17 +57,30 @@ def analyze_requirements_versions(requirements_data: Dict) -> Tuple[int, int, Li
6757
else:
6858
return 0, 0, []
6959

70-
total_requirements = len(requirements_list)
60+
total_requirements = 0
7161
unversioned_count = 0
7262
unversioned_names = []
7363

7464
for req in requirements_list:
7565
if isinstance(req, dict):
76-
has_version = check_requirement_has_version(req)
77-
if not has_version:
78-
unversioned_count += 1
79-
req_name = req.get("name", req.get("value", "unknown"))
80-
unversioned_names.append(req_name)
66+
req_name = req.get("name", req.get("value", "unknown"))
67+
if isinstance(req_name, str) and bool(re.search(r'\b(npm|bash|cd|pip|install)\b', req_name.lower())):
68+
continue
69+
70+
if isinstance(req_name, str) and ',' in req_name:
71+
parts = [p.strip() for p in req_name.split(',')]
72+
else:
73+
parts = [req_name]
74+
75+
for part in parts:
76+
if not part: continue
77+
total_requirements += 1
78+
has_version_field = "version" in req and bool(req["version"])
79+
has_version_str = isinstance(part, str) and check_requirement_has_version(part)
80+
81+
if not (has_version_field or has_version_str):
82+
unversioned_count += 1
83+
unversioned_names.append(part)
8184

8285
return total_requirements, unversioned_count, unversioned_names
8386

src/rsmetacheck/scripts/warnings/w003.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def detect_dual_license_missing_codemeta_pitfall(somef_data: Dict, file_name: st
2525
r"dual[\s-]?licen[cs]ed?",
2626
r"dually[\s-]?licen[cs]ed?",
2727
r"multiple[\s-]?licen[cs]es?",
28-
r"(?:is|are)\s+licen[cs]ed?\s+under.*(?:and|or).*licen[cs]e",
29-
r"choose.*(?:between|from|your).*licen[cs]e",
30-
r"either.*or.*licen[cs]e",
28+
r"(?:is|are)\s+licen[cs]ed?\s+under.*\b(?:and|or)\b.*licen[cs]e",
29+
r"choose.*\b(?:between|from|your)\b.*licen[cs]e",
30+
r"\beither\b.*\bor\b.*licen[cs]e",
3131
r"\d+\..*licen[cs]e.*\n.*\d+\..*licen[cs]e",
3232
r"licen[cs]e.*options?",
33-
r"available\s+under.*(?:two|multiple|either).*licen[cs]es?",
34-
r"licen[cs]ed? under.*(?:and|or)"
33+
r"available\s+under.*\b(?:two|multiple|either)\b.*licen[cs]es?",
34+
r"licen[cs]ed?\s+under.*\b(?:and|or)\b"
3535
]
3636

3737
has_dual_license_indicator = False

src/rsmetacheck/scripts/warnings/w005.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,28 @@ def detect_multiple_requirements_in_string(requirement_string: str) -> List[str]
1515
req_str = requirement_string.strip()
1616

1717
# Patterns that might indicate multiple requirements
18-
# Split by common separators but be careful not to split version specifiers
19-
potential_separators = [
20-
r'\s{2,}', # Multiple spaces
21-
r'\s+(?=[A-Za-z])', # Space followed by letter (new requirement)
22-
r',\s*', # Comma separation
23-
r';\s*', # Semicolon separation
24-
]
18+
if bool(re.search(r'\b(npm|bash|cd|pip|install)\b', req_str.lower())):
19+
return []
2520

2621
detected_requirements = []
2722

28-
if re.search(r'\s{2,}', req_str):
23+
if re.search(r',\s*', req_str):
24+
parts = re.split(r',\s*', req_str)
25+
if len(parts) > 1:
26+
detected_requirements = [part.strip() for part in parts if part.strip()]
27+
elif re.search(r';\s*', req_str):
28+
parts = re.split(r';\s*', req_str)
29+
if len(parts) > 1:
30+
detected_requirements = [part.strip() for part in parts if part.strip()]
31+
elif re.match(r'^([A-Z][a-zA-Z0-9]*(\s+|$)){2,}$', req_str):
32+
parts = re.split(r'\s+', req_str)
33+
if len(parts) > 1:
34+
detected_requirements = [part.strip() for part in parts if part.strip()]
35+
elif re.search(r'\s{2,}', req_str):
2936
parts = re.split(r'\s{2,}', req_str)
3037
if len(parts) > 1:
3138
detected_requirements = [part.strip() for part in parts if part.strip()]
3239

33-
if not detected_requirements:
34-
if re.search(r'\s+[A-Z][A-Za-z]', req_str):
35-
parts = re.split(r'\s+(?=[A-Z])', req_str)
36-
if len(parts) > 1:
37-
detected_requirements = [part.strip() for part in parts if part.strip()]
38-
3940
return detected_requirements if len(detected_requirements) > 1 else []
4041

4142

src/rsmetacheck/utils/json_ld_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,11 @@ def format_evidence_text(pitfall_code: str, pitfall_result: Dict) -> str:
328328
if different_urls and isinstance(different_urls, list) and len(different_urls) > 0:
329329
source_path = different_urls[0].get("source", "")
330330
metadata_source = extract_metadata_source_filename(source_path)
331+
mismatched_url = different_urls[0].get("url", "unknown URL")
332+
return f"{evidence_base}the correct URL is {github_api_url}, and the one found in {metadata_source} is {mismatched_url}"
331333
elif "source" in pitfall_result:
332334
metadata_source = extract_metadata_source(pitfall_result)
333-
return f"{evidence_base}{metadata_source} codeRepository points to different repository: {github_api_url}"
335+
return f"{evidence_base}the correct URL is {github_api_url}, and the one found in {metadata_source} is unknown"
334336

335337
elif pitfall_code == "P017":
336338
if "codemeta_version" in pitfall_result:

src/rsmetacheck/scripts/tests/log_verbose.txt renamed to tests/log_verbose.txt

File renamed without changes.

0 commit comments

Comments
 (0)