Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/scripts/check_version_snapshot.py
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I just imagined a world where the linting was always up to date in modules because the code for the lints lived in modules.

But that wouldn't work for local modules.

Maybe for new rules that we're just starting to introduce while we're still catching the rough edges?

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()
70 changes: 70 additions & 0 deletions .github/scripts/conda_env_sorter.py
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()
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
repos:
- repo: local
hooks:
- id: conda-env-sorter
name: Sort dependencies in conda environment files.
entry: ./.github/scripts/conda_env_sorter.py
language: python
files: environment
types: [yaml]
additional_dependencies: ["ruamel.yaml"]
- repo: local
hooks:
- id: check-version-snapshot
name: Versions are captured not hashed
entry: ./.github/scripts/check_version_snapshot.py
language: python
files: \.nf\.test$
types: [file]
additional_dependencies: []
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.1.0"
hooks:
Expand Down
3 changes: 0 additions & 3 deletions modules/nf-core/basicpy/environment.yml

This file was deleted.

4 changes: 2 additions & 2 deletions modules/nf-core/bowtie/align/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ channels:
- conda-forge
- bioconda
dependencies:
# renovate: datasource=conda depName=bioconda/bowtie
- bioconda::bowtie=1.3.1
# renovate: datasource=conda depName=bioconda/samtools
- bioconda::samtools=1.20
# renovate: datasource=conda depName=bioconda/bowtie
- bioconda::bowtie=1.3.1
3 changes: 0 additions & 3 deletions modules/nf-core/cellrangeratac/count/environment.yml

This file was deleted.

3 changes: 0 additions & 3 deletions modules/nf-core/cellrangeratac/mkfastq/environment.yml

This file was deleted.

3 changes: 0 additions & 3 deletions modules/nf-core/cellrangeratac/mkref/environment.yml

This file was deleted.

3 changes: 0 additions & 3 deletions modules/nf-core/coreograph/environment.yml

This file was deleted.

2 changes: 0 additions & 2 deletions modules/nf-core/ensemblvep/environment.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# You can use this file to create a conda environment for this module:
# conda env create -f environment.yml
channels:
- conda-forge
- bioconda
Expand Down
3 changes: 0 additions & 3 deletions modules/nf-core/fastk/histex/environment.yml

This file was deleted.

3 changes: 0 additions & 3 deletions modules/nf-core/fastk/merge/environment.yml

This file was deleted.

3 changes: 0 additions & 3 deletions modules/nf-core/fcs/fcsgx/environment.yml

This file was deleted.

2 changes: 1 addition & 1 deletion modules/nf-core/gatk4/variantstotable/environment.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json

---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json
channels:
- conda-forge
- bioconda
Expand Down
3 changes: 0 additions & 3 deletions modules/nf-core/genescopefk/environment.yml

This file was deleted.

2 changes: 2 additions & 0 deletions modules/nf-core/hlala/preparegraph/environment.yml
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
3 changes: 0 additions & 3 deletions modules/nf-core/ilastik/multicut/environment.yml

This file was deleted.

3 changes: 0 additions & 3 deletions modules/nf-core/ilastik/pixelclassification/environment.yml

This file was deleted.

3 changes: 0 additions & 3 deletions modules/nf-core/merquryfk/katcomp/environment.yml

This file was deleted.

3 changes: 0 additions & 3 deletions modules/nf-core/merquryfk/katgc/environment.yml

This file was deleted.

3 changes: 1 addition & 2 deletions modules/nf-core/regtools/junctionsextract/environment.yml
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
5 changes: 3 additions & 2 deletions modules/nf-core/snpeff/environment.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# You can use this file to create a conda environment for this module:
# conda env create -f environment.yml
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json

---
channels:
- conda-forge
- bioconda
Expand Down
2 changes: 2 additions & 0 deletions modules/nf-core/trgt/merge/environment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json

---
channels:
- conda-forge
- bioconda
Expand Down
2 changes: 2 additions & 0 deletions modules/nf-core/trgt/plot/environment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json

---
channels:
- conda-forge
- bioconda
Expand Down
3 changes: 0 additions & 3 deletions modules/nf-core/universc/environment.yml

This file was deleted.

Loading