-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for new version snapshotting #7098
base: master
Are you sure you want to change the base?
Changes from all commits
e71334d
372c260
3d87140
35ada8c
1e88c21
5ef0c99
df36cac
ce2aab5
8e4537e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python3 | ||
# /// script | ||
# requires-python = ">=3.10" | ||
# dependencies = [] | ||
# /// | ||
|
||
"""Check that versions are captured not hashed.""" | ||
|
||
import argparse | ||
import re | ||
from pathlib import Path | ||
from typing import Optional, Sequence | ||
|
||
|
||
def check_snapshotting(lines: list[str], path: Path) -> None: | ||
"""Check each line for proper snapshotting.""" | ||
good_pattern = re.compile( | ||
r'snapshot\(path\(process\.out\.versions\.get\(0\)\)\.yaml\)\.match\("versions"\)|path\(process\.out\.versions\.get\(0\)\)\.yaml' | ||
) | ||
bad_pattern = re.compile(r"process\.out\.versions|snapshot\(process\.out\)\.match\(\)") | ||
|
||
for line_number, line in enumerate(lines, start=1): | ||
if bad_pattern.search(line) and not good_pattern.search(line): | ||
print(f"Improper snapshotting in {path} at line {line_number}: {line.strip()}") | ||
|
||
|
||
def main(argv: Optional[Sequence[str]] = None) -> None: | ||
"""Check that versions are captured not hashed.""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("paths", nargs="*", type=Path) | ||
args = parser.parse_args(argv) | ||
for path in args.paths: | ||
with path.open() as f: | ||
lines = f.readlines() | ||
check_snapshotting(lines, path) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python3 | ||
# /// script | ||
# requires-python = ">=3.10" | ||
# dependencies = [ | ||
# "ruamel.yaml", | ||
# ] | ||
# /// | ||
|
||
"""Sort dependencies in conda environment files.""" | ||
|
||
import argparse | ||
from pathlib import Path | ||
from typing import Optional, Sequence | ||
|
||
import ruamel.yaml | ||
|
||
yaml = ruamel.yaml.YAML() | ||
yaml.indent(mapping=2, sequence=2, offset=2) # Set indentation to 2 spaces | ||
|
||
|
||
def main(argv: Optional[Sequence[str]] = None) -> None: | ||
"""Sort dependencies in conda environment files.""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("paths", nargs="*", type=Path) | ||
args = parser.parse_args(argv) | ||
for path in args.paths: | ||
with path.open() as f: | ||
lines = f.readlines() | ||
|
||
# Define the schema lines to be added if missing | ||
schema_lines = [ | ||
"---\n", | ||
"# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json\n", | ||
] | ||
|
||
# Check if the first two lines match the expected schema lines | ||
if lines[:2] == schema_lines: | ||
header = lines[:2] | ||
content = lines[2:] | ||
else: | ||
# Add schema lines if they are missing | ||
header = schema_lines | ||
content = lines | ||
|
||
doc = yaml.load("".join(content)) | ||
dicts = [] | ||
others = [] | ||
|
||
for term in doc["dependencies"]: | ||
if isinstance(term, dict): | ||
dicts.append(term) | ||
else: | ||
others.append(term) | ||
others.sort(key=str) | ||
for dict_term in dicts: | ||
for value in dict_term.values(): | ||
if isinstance(value, list): | ||
value.sort(key=str) | ||
dicts.sort(key=str) | ||
doc["dependencies"].clear() | ||
doc["dependencies"].extend(others) | ||
doc["dependencies"].extend(dicts) | ||
|
||
with path.open("w") as f: | ||
f.writelines(header) | ||
yaml.dump(doc, f) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
channels: | ||
- conda-forge | ||
- bioconda | ||
dependencies: | ||
- bioconda::hla-la=1.0.4 |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json | ||
channels: | ||
- conda-forge | ||
- bioconda | ||
dependencies: | ||
- "bioconda::regtools=1.0.0" | ||
- bioconda::regtools=1.0.0 |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be part of
nf-core modules lint
and not here, no?