Skip to content
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

Give Ruff a try #2174

Closed
wants to merge 9 commits into from
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
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ any code does not adhere to isort formatting.

### pre-commit hooks

This repository comes with [pre-commit](https://pre-commit.com/) hooks for black, isort and Prettier. pre-commit automatically runs checks before a commit is committed into the git history. If all checks pass, the commit is made, if files are changed by the pre-commit hooks, the user is informed and has to stage the changes and attempt the commit again.
This repository comes with [pre-commit](https://pre-commit.com/) hooks for black, ruff and Prettier. pre-commit automatically runs checks before a commit is committed into the git history. If all checks pass, the commit is made, if files are changed by the pre-commit hooks, the user is informed and has to stage the changes and attempt the commit again.

You can use the pre-commit hooks if you like, but you don't have to. The CI on Github will run the same checks as the tools installed with pre-commit. If the pre-commit checks pass, then the same checks in the CI will pass, too.

Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/create-lint-wf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ jobs:
with:
version: ${{ matrix.NXF_VER }}

# Install the Prettier linting tools
# Install the Prettier & Ruff linting tools
- uses: actions/setup-node@v3

- name: Install Prettier
run: npm install -g prettier

- name: Install Ruff
run: |
python -m pip install --upgrade pip
pip install ruff

# Install the editorconfig linting tools
- name: Install editorconfig-checker
run: npm install -g editorconfig-checker
Expand All @@ -76,6 +81,9 @@ jobs:
- name: Run ECLint check
run: editorconfig-checker -exclude README.md $(find nf-core-testpipeline/.* -type f | grep -v '.git\|.py\|md\|json\|yml\|yaml\|html\|css\|work\|.nextflow\|build\|nf_core.egg-info\|log.txt\|Makefile')

- name: Run Ruff
run: ruff .

# Update modules to the latest version
- name: nf-core modules update
run: nf-core --log-file log.txt modules update --dir nf-core-testpipeline --all --no-preview
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/fix-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: python-isort
uses: isort/isort-action@v1.0.0
with:
isortVersion: "latest"
requirementsFiles: "requirements.txt requirements-dev.txt"
- name: Install Ruff
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Run Ruff
run: ruff check --fix .

- name: Commit & push changes
run: |
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/lint-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
allow-repeats: false

isort:
ruff:
runs-on: ubuntu-latest
steps:
- name: Check out source-code repository
Expand All @@ -80,8 +80,9 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: python-isort
uses: isort/isort-action@v1.1.0
with:
isortVersion: "latest"
requirementsFiles: "requirements.txt requirements-dev.txt"
- name: Install Ruff
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Run Ruff
run: ruff .
1 change: 1 addition & 0 deletions .github/workflows/pytest-frozen-ubuntu-20.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:

- name: Downgrade git to the Ubuntu official repository's version
run: |
sudo apt update
sudo apt remove git git-man
sudo add-apt-repository --remove ppa:git-core/ppa
sudo apt install git
Expand Down
1 change: 1 addition & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ vscode:
# - nextflow.nextflow # Nextflow syntax highlighting
- oderwat.indent-rainbow # Highlight indentation level
- streetsidesoftware.code-spell-checker # Spelling checker for source code
- charliermarsh.ruff # Code linter Ruff (v0.0.239)
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ repos:
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
language_version: python3.9
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
hooks:
- id: prettier
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.239"
hooks:
- id: ruff
args: [--fix]
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Linting

- Add Ruff to lint library imports and python code ([#2174](https://github.com/nf-core/tools/pull/2174))

### Modules

- Add an `--empty-template` option to create a module without TODO statements or examples ([#2175](https://github.com/nf-core/tools/pull/2175) & [#2177](https://github.com/nf-core/tools/pull/2177))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![codecov](https://codecov.io/gh/nf-core/tools/branch/master/graph/badge.svg)](https://codecov.io/gh/nf-core/tools)
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![code style: prettier](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

[![install with Bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg)](https://bioconda.github.io/recipes/nf-core/README.html)
Expand Down
1 change: 0 additions & 1 deletion nf_core/components/components_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
import re
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions nf_core/gitpod/gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RUN conda config --add channels defaults && \
nf-test \
black \
prettier \
ruff \
pytest-workflow && \
mamba clean --all -f -y

Expand Down
1 change: 0 additions & 1 deletion nf_core/lint/actions_ci.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re

import yaml

Expand Down
4 changes: 2 additions & 2 deletions nf_core/modules/test_yml_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from nf_core.components.components_command import ComponentCommand

from ..lint_utils import run_prettier_on_file
from .modules_repo import ModulesRepo

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -294,7 +293,8 @@ def get_md5_sums(self, command, results_dir=None, results_dir_repeat=None):
if test_files[i].get("md5sum") and not test_files[i].get("md5sum") == test_files_repeat[i]["md5sum"]:
test_files[i].pop("md5sum")
test_files[i]["contains"] = [
"# TODO nf-core: file md5sum was variable, please replace this text with a string found in the file instead "
"# TODO nf-core: file md5sum was variable, please replace this text with a "
+ "string found in the file instead "
]

if len(test_files) == 0:
Expand Down
17 changes: 13 additions & 4 deletions nf_core/pipeline-template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
line-length = 120
target_version = ["py37", "py38", "py39", "py310"]

[tool.isort]
profile = "black"
known_first_party = ["nf_core"]
multi_line_output = 3
[tool.ruff]
select = [
# Pyflakes
"F401", # imported but unused
"F841", # Local variable is assigned to but never used
# isort
"I001"
]
line-length = 120
target-version = "py37"

[tool.ruff.isort]
known-first-party = ["nf_core"]
20 changes: 16 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ markers = [
testpaths = ["tests"]
norecursedirs = [ ".*", "build", "dist", "*.egg", "data", "__pycache__", ".github", "nf_core", "docs"]

[tool.isort]
profile = "black"
known_first_party = ["nf_core"]
multi_line_output = 3
[tool.ruff]
select = [
# Pyflakes
"F401", # imported but unused
"F841", # Local variable is assigned to but never used
# isort
"I001"
]
line-length = 120
target-version = "py37"

[tool.ruff.isort]
known-first-party = ["nf_core"]

[tool.ruff.per-file-ignores]
"__init__.py" = ["E402", "F401"]
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
black
isort
ruff
myst_parser
pytest-cov
pytest-datafiles
Expand Down
3 changes: 1 addition & 2 deletions tests/modules/create_test_yml.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
from pathlib import Path

import pytest

import nf_core.modules

from ..utils import GITLAB_DEFAULT_BRANCH, GITLAB_URL, with_temporary_folder
from ..utils import with_temporary_folder


@with_temporary_folder
Expand Down
1 change: 0 additions & 1 deletion tests/modules/lint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from pathlib import Path

import pytest
Expand Down
1 change: 0 additions & 1 deletion tests/modules/modules_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test the 'modules test' command which runs module pytests."""
import os
import shutil
from pathlib import Path

Expand Down
4 changes: 1 addition & 3 deletions tests/subworkflows/remove.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from pathlib import Path

from rich.console import Console

from nf_core.modules.modules_json import ModulesJson


Expand All @@ -18,7 +16,7 @@ def test_subworkflows_remove_subworkflow(self):
bam_sort_stats_samtools_path = Path(subworkflow_path, "bam_sort_stats_samtools")
bam_stats_samtools_path = Path(subworkflow_path, "bam_stats_samtools")
samtools_index_path = Path(self.subworkflow_install.dir, "modules", "nf-core", "samtools", "index")
mod_json_obj = ModulesJson(self.pipeline_dir)
ModulesJson(self.pipeline_dir)
mod_json_before = ModulesJson(self.pipeline_dir).get_modules_json()
assert self.subworkflow_remove.remove("bam_sort_stats_samtools")
mod_json_after = ModulesJson(self.pipeline_dir).get_modules_json()
Expand Down
1 change: 0 additions & 1 deletion tests/subworkflows/subworkflows_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test the 'subworkflows test' command which runs module pytests."""
import os
import shutil
from pathlib import Path

Expand Down
1 change: 0 additions & 1 deletion tests/subworkflows/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import nf_core.utils
from nf_core.modules.modules_json import ModulesJson
from nf_core.modules.modules_repo import NF_CORE_MODULES_NAME, NF_CORE_MODULES_REMOTE
from nf_core.modules.remove import ModuleRemove
from nf_core.modules.update import ModuleUpdate
from nf_core.subworkflows.update import SubworkflowUpdate

Expand Down
3 changes: 1 addition & 2 deletions tests/test_download.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tests for the download subcommand of nf-core tools
"""

import hashlib
import os
import shutil
import tempfile
Expand All @@ -14,7 +13,7 @@
import nf_core.utils
from nf_core.download import DownloadWorkflow

from .utils import with_temporary_file, with_temporary_folder
from .utils import with_temporary_folder


class DownloadTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_run_linting_function(self):

We don't really check any of this code as it's just a series of function calls
and we're testing each of those individually. This is mostly to check for syntax errors."""
lint_obj = nf_core.lint.run_linting(self.test_pipeline_dir, False)
nf_core.lint.run_linting(self.test_pipeline_dir, False)

def test_init_PipelineLint(self):
"""Simply create a PipelineLint object.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def test_build_schema(self):
Build a new schema param from a pipeline
Run code to ensure it doesn't crash. Individual functions tested separately.
"""
param = self.schema_obj.build_schema(self.template_dir, True, False, None)
self.schema_obj.build_schema(self.template_dir, True, False, None)

@with_temporary_folder
def test_build_schema_from_scratch(self, tmp_dir):
Expand All @@ -319,7 +319,7 @@ def test_build_schema_from_scratch(self, tmp_dir):
shutil.copytree(self.template_dir, test_pipeline_dir)
os.remove(os.path.join(test_pipeline_dir, "nextflow_schema.json"))

param = self.schema_obj.build_schema(test_pipeline_dir, True, False, None)
self.schema_obj.build_schema(test_pipeline_dir, True, False, None)

@mock.patch("requests.post")
def test_launch_web_builder_timeout(self, mock_post):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_subworkflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_modules_repo_dummy(tmp_dir):
with open(os.path.join(root_dir, ".nf-core.yml"), "w") as fh:
fh.writelines(["repository_type: modules", "\n", "org_path: nf-core", "\n"])

with requests_mock.Mocker() as mock:
with requests_mock.Mocker():
subworkflow_create = nf_core.subworkflows.SubworkflowCreate(root_dir, "test_subworkflow", "@author", True)
subworkflow_create.create()

Expand Down