diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index b3f88970df..c4927d8a07 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -33,7 +33,9 @@ Then install your local fork of nf-core/tools: pip install -e . ``` -## Code formatting with Black +## Code formatting + +### Black All Python code in nf-core/tools must be passed through the [Black Python code formatter](https://black.readthedocs.io/en/stable/). This ensures a harmonised code formatting style throughout the package, from all contributors. @@ -51,6 +53,24 @@ You can also set it up to run when you [make a commit](https://black.readthedocs There is an automated CI check that runs when you open a pull-request to nf-core/tools that will fail if any code does not adhere to Black formatting. +### isort + +All Python code must also be passed through [isort](https://pycqa.github.io/isort/index.html). +This ensures a harmonised imports throughout the package, from all contributors. + +To run isort on the command line recursively on the whole repository you can use: + +```bash +isort . +``` + +isort also has [plugins for most common editors](https://github.com/pycqa/isort/wiki/isort-Plugins) +to automatically format code when you hit save. +Or [version control integration](https://pycqa.github.io/isort/docs/configuration/pre-commit.html) to set it up to run when you make a commit. + +There is an automated CI check that runs when you open a pull-request to nf-core/tools that will fail if +any code does not adhere to isort formatting. + ## API Documentation We aim to write function docstrings according to the [Google Python style-guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings). These are used to automatically generate package documentation on the nf-core website using Sphinx. diff --git a/.github/workflows/fix-linting.yml b/.github/workflows/fix-linting.yml index 44ca255e2b..4409f1903b 100644 --- a/.github/workflows/fix-linting.yml +++ b/.github/workflows/fix-linting.yml @@ -38,6 +38,16 @@ jobs: # Override to remove the default --check flag so that we make changes options: "--color" + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: python-isort + uses: isort/isort-action@v0.1.0 + with: + isortVersion: "latest" + requirementsFiles: "requirements.txt requirements-dev.txt" + - name: Commit & push changes run: | git config user.email "core@nf-co.re" diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml index 2f6f046cbf..52e042b5bc 100644 --- a/.github/workflows/lint-code.yml +++ b/.github/workflows/lint-code.yml @@ -58,3 +58,19 @@ jobs: Thanks again for your contribution! repo-token: ${{ secrets.GITHUB_TOKEN }} allow-repeats: false + + isort: + runs-on: ubuntu-latest + steps: + - name: Check out source-code repository + uses: actions/checkout@v2 + + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: python-isort + uses: isort/isort-action@v0.1.0 + with: + isortVersion: "latest" + requirementsFiles: "requirements.txt requirements-dev.txt" diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eca220231..1d62b371aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ - Fix a bug in the regex extracting the version from biocontainers URLs [#1596](https://github.com/nf-core/tools/pull/1596) +### Linting + +- Add isort configuration and GitHub workflow ([#1538](https://github.com/nf-core/tools/pull/1538)) + ## [v2.4.1 - Cobolt Koala Patch](https://github.com/nf-core/tools/releases/tag/2.4) - [2022-05-16] - Patch release to try to fix the template sync ([#1585](https://github.com/nf-core/tools/pull/1585)) diff --git a/README.md b/README.md index 949a11b424..806561ed9b 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Python tests](https://github.com/nf-core/tools/workflows/Python%20tests/badge.svg?branch=master&event=push)](https://github.com/nf-core/tools/actions?query=workflow%3A%22Python+tests%22+branch%3Amaster) [![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) +[![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) [![install with PyPI](https://img.shields.io/badge/install%20with-PyPI-blue.svg)](https://pypi.org/project/nf-core/) diff --git a/docs/api/make_lint_md.py b/docs/api/make_lint_md.py index a1dc53e37b..c3362b7f6e 100644 --- a/docs/api/make_lint_md.py +++ b/docs/api/make_lint_md.py @@ -2,6 +2,7 @@ import fnmatch import os + import nf_core.lint import nf_core.modules.lint diff --git a/nf_core/__main__.py b/nf_core/__main__.py index dceb623586..97a269abb2 100755 --- a/nf_core/__main__.py +++ b/nf_core/__main__.py @@ -1,14 +1,15 @@ #!/usr/bin/env python """ nf-core: Helper tools for use with nf-core Nextflow pipelines. """ -from rich import print import logging import os import re +import sys + import rich.console import rich.logging import rich.traceback import rich_click as click -import sys +from rich import print import nf_core import nf_core.bump_version diff --git a/nf_core/bump_version.py b/nf_core/bump_version.py index 41cf3d6353..04acb6834c 100644 --- a/nf_core/bump_version.py +++ b/nf_core/bump_version.py @@ -6,8 +6,10 @@ import logging import os import re -import rich.console import sys + +import rich.console + import nf_core.utils log = logging.getLogger(__name__) diff --git a/nf_core/create.py b/nf_core/create.py index f1614f4da0..1605709720 100644 --- a/nf_core/create.py +++ b/nf_core/create.py @@ -2,19 +2,20 @@ """Creates a nf-core pipeline matching the current organization's specification based on a template. """ -from genericpath import exists -import git import imghdr -import jinja2 import logging import os import pathlib import random -import requests import shutil import sys import time +import git +import jinja2 +import requests +from genericpath import exists + import nf_core log = logging.getLogger(__name__) diff --git a/nf_core/download.py b/nf_core/download.py index db3baad8e2..12817e959e 100644 --- a/nf_core/download.py +++ b/nf_core/download.py @@ -3,22 +3,23 @@ from __future__ import print_function -from io import BytesIO -import logging +import concurrent.futures import hashlib +import logging import os -import questionary import re -import requests -import requests_cache import shutil import subprocess import sys import tarfile -import concurrent.futures +from io import BytesIO +from zipfile import ZipFile + +import questionary +import requests +import requests_cache import rich import rich.progress -from zipfile import ZipFile import nf_core import nf_core.list diff --git a/nf_core/launch.py b/nf_core/launch.py index 5a0104d493..f5f5145aa2 100644 --- a/nf_core/launch.py +++ b/nf_core/launch.py @@ -2,21 +2,23 @@ """ Launch a pipeline, interactively collecting params """ from __future__ import print_function -from rich.console import Console -from rich.markdown import Markdown -from rich.prompt import Confirm import copy import json import logging import os -import questionary import re import subprocess import webbrowser + +import questionary import requests +from rich.console import Console +from rich.markdown import Markdown +from rich.prompt import Confirm -import nf_core.schema, nf_core.utils +import nf_core.schema +import nf_core.utils log = logging.getLogger(__name__) diff --git a/nf_core/licences.py b/nf_core/licences.py index e44ad14d40..bc001f32d2 100644 --- a/nf_core/licences.py +++ b/nf_core/licences.py @@ -3,14 +3,15 @@ from __future__ import print_function -import logging import json +import logging import os import re + import requests -import yaml import rich.console import rich.table +import yaml import nf_core.utils diff --git a/nf_core/lint/__init__.py b/nf_core/lint/__init__.py index d1e79736f5..eee4be683b 100644 --- a/nf_core/lint/__init__.py +++ b/nf_core/lint/__init__.py @@ -5,21 +5,22 @@ the nf-core community guidelines. """ -from rich.markdown import Markdown -from rich.table import Table -from rich.panel import Panel -from rich.console import group import datetime -import git import json import logging import re + +import git import rich import rich.progress +from rich.console import group +from rich.markdown import Markdown +from rich.panel import Panel +from rich.table import Table -import nf_core.utils import nf_core.lint_utils import nf_core.modules.lint +import nf_core.utils from nf_core import __version__ from nf_core.lint_utils import console from nf_core.utils import plural_s as _s @@ -160,9 +161,9 @@ class PipelineLint(nf_core.utils.Pipeline): from .pipeline_name_conventions import pipeline_name_conventions from .pipeline_todos import pipeline_todos from .readme import readme + from .schema_description import schema_description from .schema_lint import schema_lint from .schema_params import schema_params - from .schema_description import schema_description from .template_strings import template_strings from .version_consistency import version_consistency diff --git a/nf_core/lint/actions_awsfulltest.py b/nf_core/lint/actions_awsfulltest.py index 6b5cdae641..353004f50c 100644 --- a/nf_core/lint/actions_awsfulltest.py +++ b/nf_core/lint/actions_awsfulltest.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os + import yaml diff --git a/nf_core/lint/actions_awstest.py b/nf_core/lint/actions_awstest.py index 9062542b78..d04fde67c4 100644 --- a/nf_core/lint/actions_awstest.py +++ b/nf_core/lint/actions_awstest.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os + import yaml diff --git a/nf_core/lint/actions_ci.py b/nf_core/lint/actions_ci.py index bb0bdc6108..c84a296f57 100644 --- a/nf_core/lint/actions_ci.py +++ b/nf_core/lint/actions_ci.py @@ -2,6 +2,7 @@ import os import re + import yaml diff --git a/nf_core/lint/actions_schema_validation.py b/nf_core/lint/actions_schema_validation.py index b8a1c12ec6..103e545a43 100644 --- a/nf_core/lint/actions_schema_validation.py +++ b/nf_core/lint/actions_schema_validation.py @@ -1,12 +1,13 @@ #!/usr/bin/env python -import logging -import yaml +import glob import json -import jsonschema +import logging import os -import glob + +import jsonschema import requests +import yaml def actions_schema_validation(self): diff --git a/nf_core/lint/merge_markers.py b/nf_core/lint/merge_markers.py index fe1c6e2a14..75fbf931bf 100644 --- a/nf_core/lint/merge_markers.py +++ b/nf_core/lint/merge_markers.py @@ -1,9 +1,9 @@ #!/usr/bin/env python +import fnmatch +import io import logging import os -import io -import fnmatch import nf_core.utils diff --git a/nf_core/lint/modules_json.py b/nf_core/lint/modules_json.py index 4c5923d508..6e6ddd6d17 100644 --- a/nf_core/lint/modules_json.py +++ b/nf_core/lint/modules_json.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from logging import warn + from nf_core.modules.modules_command import ModuleCommand diff --git a/nf_core/lint/multiqc_config.py b/nf_core/lint/multiqc_config.py index b55aeb5101..92a9279eae 100644 --- a/nf_core/lint/multiqc_config.py +++ b/nf_core/lint/multiqc_config.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os + import yaml diff --git a/nf_core/lint/nextflow_config.py b/nf_core/lint/nextflow_config.py index b85fc78a98..8dda99e6e5 100644 --- a/nf_core/lint/nextflow_config.py +++ b/nf_core/lint/nextflow_config.py @@ -1,8 +1,8 @@ #!/usr/bin/env python -import re -import os import logging +import os +import re log = logging.getLogger(__name__) diff --git a/nf_core/lint/pipeline_todos.py b/nf_core/lint/pipeline_todos.py index c7fde0996f..91a7cf6307 100644 --- a/nf_core/lint/pipeline_todos.py +++ b/nf_core/lint/pipeline_todos.py @@ -1,9 +1,9 @@ #!/usr/bin/env python +import fnmatch +import io import logging import os -import io -import fnmatch log = logging.getLogger(__name__) diff --git a/nf_core/lint/schema_description.py b/nf_core/lint/schema_description.py index f1377053e2..ccf78f3c62 100644 --- a/nf_core/lint/schema_description.py +++ b/nf_core/lint/schema_description.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from logging import warn + import nf_core.schema diff --git a/nf_core/lint/schema_lint.py b/nf_core/lint/schema_lint.py index ab9cc7e56c..a1f3f799a2 100644 --- a/nf_core/lint/schema_lint.py +++ b/nf_core/lint/schema_lint.py @@ -1,9 +1,11 @@ #!/usr/bin/env python import logging -import nf_core.schema + import jsonschema +import nf_core.schema + def schema_lint(self): """Pipeline schema syntax diff --git a/nf_core/lint_utils.py b/nf_core/lint_utils.py index 29fe042c74..ffb3bdf7b3 100644 --- a/nf_core/lint_utils.py +++ b/nf_core/lint_utils.py @@ -1,7 +1,8 @@ +import logging + import rich from rich.console import Console from rich.table import Table -import logging import nf_core.utils from nf_core.utils import plural_s as _s diff --git a/nf_core/list.py b/nf_core/list.py index e9623dcd96..ae9d974388 100644 --- a/nf_core/list.py +++ b/nf_core/list.py @@ -3,12 +3,13 @@ from __future__ import print_function -from datetime import datetime -import git import json import logging import os import re +from datetime import datetime + +import git import requests import rich.console import rich.table diff --git a/nf_core/modules/__init__.py b/nf_core/modules/__init__.py index 29110461b5..3dd49e3a41 100644 --- a/nf_core/modules/__init__.py +++ b/nf_core/modules/__init__.py @@ -1,13 +1,13 @@ -from .modules_repo import ModulesRepo +from .bump_versions import ModuleVersionBumper from .create import ModuleCreate -from .test_yml_builder import ModulesTestYmlBuilder +from .info import ModuleInfo +from .install import ModuleInstall from .lint import ModuleLint -from .bump_versions import ModuleVersionBumper -from .module_utils import ModuleException from .list import ModuleList -from .install import ModuleInstall -from .update import ModuleUpdate -from .remove import ModuleRemove -from .info import ModuleInfo -from .mulled import MulledImageNameGenerator from .module_test import ModulesTest +from .module_utils import ModuleException +from .modules_repo import ModulesRepo +from .mulled import MulledImageNameGenerator +from .remove import ModuleRemove +from .test_yml_builder import ModulesTestYmlBuilder +from .update import ModuleUpdate diff --git a/nf_core/modules/bump_versions.py b/nf_core/modules/bump_versions.py index 18006b4ddb..0da96c72d4 100644 --- a/nf_core/modules/bump_versions.py +++ b/nf_core/modules/bump_versions.py @@ -5,21 +5,23 @@ from __future__ import print_function + import logging -import questionary import os import re + +import questionary import rich from rich.console import Console -from rich.table import Table from rich.markdown import Markdown -import rich -from nf_core.utils import rich_force_colors +from rich.table import Table -import nf_core.utils -from nf_core.utils import plural_s as _s import nf_core.modules.module_utils +import nf_core.utils from nf_core.modules.nfcore_module import NFCoreModule +from nf_core.utils import plural_s as _s +from nf_core.utils import rich_force_colors + from .modules_command import ModuleCommand log = logging.getLogger(__name__) diff --git a/nf_core/modules/create.py b/nf_core/modules/create.py index 7503769780..9ea80cc7c5 100644 --- a/nf_core/modules/create.py +++ b/nf_core/modules/create.py @@ -4,22 +4,23 @@ """ from __future__ import print_function -from packaging.version import parse as parse_version import glob -import jinja2 import json import logging -import nf_core import os -import questionary import re -import rich import subprocess + +import jinja2 +import questionary +import rich import yaml +from packaging.version import parse as parse_version -import nf_core.utils +import nf_core import nf_core.modules.module_utils +import nf_core.utils log = logging.getLogger(__name__) diff --git a/nf_core/modules/info.py b/nf_core/modules/info.py index 88a178546f..6d33c091ff 100644 --- a/nf_core/modules/info.py +++ b/nf_core/modules/info.py @@ -1,18 +1,23 @@ import base64 import logging import os + import requests import yaml - from rich import box -from rich.text import Text from rich.console import Group from rich.markdown import Markdown from rich.panel import Panel from rich.table import Table +from rich.text import Text +from .module_utils import ( + get_installed_modules, + get_module_git_log, + get_repo_type, + module_exist_in_repo, +) from .modules_command import ModuleCommand -from .module_utils import get_repo_type, get_installed_modules, get_module_git_log, module_exist_in_repo from .modules_repo import ModulesRepo log = logging.getLogger(__name__) diff --git a/nf_core/modules/install.py b/nf_core/modules/install.py index f1c058dea6..843943805a 100644 --- a/nf_core/modules/install.py +++ b/nf_core/modules/install.py @@ -1,12 +1,13 @@ +import logging import os + import questionary -import logging -import nf_core.utils import nf_core.modules.module_utils +import nf_core.utils -from .modules_command import ModuleCommand from .module_utils import get_module_git_log, module_exist_in_repo +from .modules_command import ModuleCommand log = logging.getLogger(__name__) diff --git a/nf_core/modules/lint/__init__.py b/nf_core/modules/lint/__init__.py index 822fe5d650..ed9db99371 100644 --- a/nf_core/modules/lint/__init__.py +++ b/nf_core/modules/lint/__init__.py @@ -8,31 +8,31 @@ """ from __future__ import print_function + +import json import logging -from nf_core.modules.modules_command import ModuleCommand import operator import os -import questionary import re +import sys + +import questionary import requests import rich import yaml -import json -from rich.table import Table from rich.markdown import Markdown from rich.panel import Panel -import rich -from nf_core.utils import rich_force_colors -from nf_core.lint.pipeline_todos import pipeline_todos -import sys +from rich.table import Table -import nf_core.utils import nf_core.modules.module_utils - -from nf_core.utils import plural_s as _s +import nf_core.utils +from nf_core.lint.pipeline_todos import pipeline_todos +from nf_core.lint_utils import console +from nf_core.modules.modules_command import ModuleCommand from nf_core.modules.modules_repo import ModulesRepo from nf_core.modules.nfcore_module import NFCoreModule -from nf_core.lint_utils import console +from nf_core.utils import plural_s as _s +from nf_core.utils import rich_force_colors log = logging.getLogger(__name__) @@ -64,9 +64,9 @@ class ModuleLint(ModuleCommand): from .main_nf import main_nf from .meta_yml import meta_yml from .module_changes import module_changes + from .module_deprecations import module_deprecations from .module_tests import module_tests from .module_todos import module_todos - from .module_deprecations import module_deprecations from .module_version import module_version def __init__(self, dir): diff --git a/nf_core/modules/lint/main_nf.py b/nf_core/modules/lint/main_nf.py index b6432a2cb8..8d745cd186 100644 --- a/nf_core/modules/lint/main_nf.py +++ b/nf_core/modules/lint/main_nf.py @@ -4,6 +4,7 @@ """ import re + import nf_core diff --git a/nf_core/modules/lint/meta_yml.py b/nf_core/modules/lint/meta_yml.py index f665f64094..87597efbd5 100644 --- a/nf_core/modules/lint/meta_yml.py +++ b/nf_core/modules/lint/meta_yml.py @@ -2,7 +2,6 @@ from operator import imod - import yaml diff --git a/nf_core/modules/lint/module_changes.py b/nf_core/modules/lint/module_changes.py index 9382222155..9676481b43 100644 --- a/nf_core/modules/lint/module_changes.py +++ b/nf_core/modules/lint/module_changes.py @@ -2,8 +2,10 @@ Check whether the content of a module has changed compared to the original repository """ import os + import requests import rich + from nf_core.modules.lint import LintResult diff --git a/nf_core/modules/lint/module_tests.py b/nf_core/modules/lint/module_tests.py index b89958de18..caa29ba887 100644 --- a/nf_core/modules/lint/module_tests.py +++ b/nf_core/modules/lint/module_tests.py @@ -1,8 +1,9 @@ """ Lint the tests of a module in nf-core/modules """ -import os import logging +import os + import yaml log = logging.getLogger(__name__) diff --git a/nf_core/modules/lint/module_todos.py b/nf_core/modules/lint/module_todos.py index 33b35415b6..90af44987e 100644 --- a/nf_core/modules/lint/module_todos.py +++ b/nf_core/modules/lint/module_todos.py @@ -1,5 +1,6 @@ #!/usr/bin/env python import logging + from nf_core.lint.pipeline_todos import pipeline_todos log = logging.getLogger(__name__) diff --git a/nf_core/modules/lint/module_version.py b/nf_core/modules/lint/module_version.py index 29d7327490..64b4817719 100644 --- a/nf_core/modules/lint/module_version.py +++ b/nf_core/modules/lint/module_version.py @@ -3,14 +3,15 @@ Verify that a module has a correct entry in the modules.json file """ +import json import logging import os -import json import re -import questionary -import nf_core import sys +import questionary + +import nf_core import nf_core.modules.module_utils log = logging.getLogger(__name__) diff --git a/nf_core/modules/module_test.py b/nf_core/modules/module_test.py index 35658dd26b..8e137f07a6 100644 --- a/nf_core/modules/module_test.py +++ b/nf_core/modules/module_test.py @@ -4,15 +4,17 @@ """ import logging -import questionary import os -import pytest import sys -import rich from pathlib import Path from shutil import which +import pytest +import questionary +import rich + import nf_core.utils + from .modules_repo import ModulesRepo log = logging.getLogger(__name__) diff --git a/nf_core/modules/module_utils.py b/nf_core/modules/module_utils.py index 048d7aa84a..c1522e2485 100644 --- a/nf_core/modules/module_utils.py +++ b/nf_core/modules/module_utils.py @@ -1,11 +1,11 @@ +import datetime import glob import json -import os import logging -import rich -import datetime -import questionary +import os +import questionary +import rich import nf_core.utils diff --git a/nf_core/modules/modules_command.py b/nf_core/modules/modules_command.py index 4eba633fc6..83dec17b0c 100644 --- a/nf_core/modules/modules_command.py +++ b/nf_core/modules/modules_command.py @@ -1,17 +1,18 @@ -from posixpath import dirname -from nf_core import modules -import os -import glob -import shutil import copy +import glob import json import logging +import os +import shutil +from posixpath import dirname + import yaml import nf_core.modules.module_utils import nf_core.utils -from nf_core.utils import plural_s as _s +from nf_core import modules from nf_core.modules.modules_repo import ModulesRepo +from nf_core.utils import plural_s as _s log = logging.getLogger(__name__) diff --git a/nf_core/modules/modules_repo.py b/nf_core/modules/modules_repo.py index 2f4926bfdc..bf6d7b48c8 100644 --- a/nf_core/modules/modules_repo.py +++ b/nf_core/modules/modules_repo.py @@ -1,6 +1,7 @@ -import os import base64 import logging +import os + from nf_core.utils import gh_api log = logging.getLogger(__name__) diff --git a/nf_core/modules/mulled.py b/nf_core/modules/mulled.py index 9a34ef3355..fc1d1a3555 100644 --- a/nf_core/modules/mulled.py +++ b/nf_core/modules/mulled.py @@ -3,12 +3,11 @@ import logging import re -from packaging.version import Version, InvalidVersion -from typing import Iterable, Tuple, List +from typing import Iterable, List, Tuple import requests from galaxy.tool_util.deps.mulled.util import build_target, v2_image_name - +from packaging.version import InvalidVersion, Version log = logging.getLogger(__name__) diff --git a/nf_core/modules/remove.py b/nf_core/modules/remove.py index b5cbc9a67b..7533b142a5 100644 --- a/nf_core/modules/remove.py +++ b/nf_core/modules/remove.py @@ -1,9 +1,9 @@ -import os -import sys import json -import questionary import logging +import os +import sys +import questionary import nf_core.utils diff --git a/nf_core/modules/test_yml_builder.py b/nf_core/modules/test_yml_builder.py index a0ebec7e20..91767f3f34 100644 --- a/nf_core/modules/test_yml_builder.py +++ b/nf_core/modules/test_yml_builder.py @@ -5,7 +5,6 @@ """ from __future__ import print_function -from rich.syntax import Syntax import errno import gzip @@ -13,19 +12,20 @@ import logging import operator import os -import questionary import re -import rich import shlex import subprocess import tempfile + +import questionary +import rich import yaml +from rich.syntax import Syntax import nf_core.utils from .modules_repo import ModulesRepo - log = logging.getLogger(__name__) diff --git a/nf_core/modules/update.py b/nf_core/modules/update.py index 4538c2a6aa..150e787a74 100644 --- a/nf_core/modules/update.py +++ b/nf_core/modules/update.py @@ -4,18 +4,23 @@ import json import logging import os -import questionary import shutil import tempfile + +import questionary from questionary import question from rich.console import Console from rich.syntax import Syntax -import nf_core.utils import nf_core.modules.module_utils +import nf_core.utils +from .module_utils import ( + get_installed_modules, + get_module_git_log, + module_exist_in_repo, +) from .modules_command import ModuleCommand -from .module_utils import get_installed_modules, get_module_git_log, module_exist_in_repo from .modules_repo import ModulesRepo log = logging.getLogger(__name__) diff --git a/nf_core/pipeline-template/bin/check_samplesheet.py b/nf_core/pipeline-template/bin/check_samplesheet.py index 3652c63c8b..197443ba9b 100755 --- a/nf_core/pipeline-template/bin/check_samplesheet.py +++ b/nf_core/pipeline-template/bin/check_samplesheet.py @@ -11,7 +11,6 @@ from collections import Counter from pathlib import Path - logger = logging.getLogger() diff --git a/nf_core/pipeline-template/modules/nf-core/modules/custom/dumpsoftwareversions/templates/dumpsoftwareversions.py b/nf_core/pipeline-template/modules/nf-core/modules/custom/dumpsoftwareversions/templates/dumpsoftwareversions.py index d139039254..ab8f4f15c6 100644 --- a/nf_core/pipeline-template/modules/nf-core/modules/custom/dumpsoftwareversions/templates/dumpsoftwareversions.py +++ b/nf_core/pipeline-template/modules/nf-core/modules/custom/dumpsoftwareversions/templates/dumpsoftwareversions.py @@ -1,9 +1,10 @@ #!/usr/bin/env python -import yaml import platform from textwrap import dedent +import yaml + def _make_versions_html(versions): html = [ diff --git a/nf_core/schema.py b/nf_core/schema.py index 5ab26dcec9..b376728000 100644 --- a/nf_core/schema.py +++ b/nf_core/schema.py @@ -2,20 +2,21 @@ """ Code to deal with pipeline JSON Schema """ from __future__ import print_function -from rich.prompt import Confirm import copy -import copy -import jinja2 import json -import jsonschema import logging -import markdown import os import webbrowser + +import jinja2 +import jsonschema +import markdown import yaml +from rich.prompt import Confirm -import nf_core.list, nf_core.utils +import nf_core.list +import nf_core.utils log = logging.getLogger(__name__) diff --git a/nf_core/sync.py b/nf_core/sync.py index 7bb6aabb31..83405a4cea 100644 --- a/nf_core/sync.py +++ b/nf_core/sync.py @@ -2,14 +2,15 @@ """Synchronise a pipeline TEMPLATE branch with the template. """ -import git import json import logging import os +import shutil + +import git import requests import requests_cache import rich -import shutil import nf_core import nf_core.create diff --git a/nf_core/utils.py b/nf_core/utils.py index 11b2f297bd..aab00cfcdf 100644 --- a/nf_core/utils.py +++ b/nf_core/utils.py @@ -2,32 +2,33 @@ """ Common utility functions for the nf-core python package. """ -import nf_core - -from distutils import version import datetime import errno -import git import hashlib import json import logging import mimetypes import os -import prompt_toolkit -import questionary import random import re -import requests -import requests_cache -import rich import shlex import subprocess import sys import time +from distutils import version + +import git +import prompt_toolkit +import questionary +import requests +import requests_cache +import rich import yaml from rich.live import Live from rich.spinner import Spinner +import nf_core + log = logging.getLogger(__name__) # Custom style for questionary diff --git a/pyproject.toml b/pyproject.toml index f05ed68402..6a9f51e697 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,3 +15,8 @@ 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 diff --git a/requirements-dev.txt b/requirements-dev.txt index 081e32aea7..7a38e2e51b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,3 +5,4 @@ mock black Sphinx sphinx_rtd_theme +isort diff --git a/setup.py b/setup.py index 3d63298da5..4fdfb7c5a8 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from setuptools import setup, find_packages +from setuptools import find_packages, setup version = "2.5dev" diff --git a/tests/lint/actions_awsfulltest.py b/tests/lint/actions_awsfulltest.py index 293cb08455..234628227d 100644 --- a/tests/lint/actions_awsfulltest.py +++ b/tests/lint/actions_awsfulltest.py @@ -1,7 +1,9 @@ #!/usr/bin/env python import os + import yaml + import nf_core.lint diff --git a/tests/lint/actions_awstest.py b/tests/lint/actions_awstest.py index d42d9b3b5e..45d7e66c3d 100644 --- a/tests/lint/actions_awstest.py +++ b/tests/lint/actions_awstest.py @@ -1,7 +1,9 @@ #!/usr/bin/env python import os + import yaml + import nf_core.lint diff --git a/tests/lint/actions_ci.py b/tests/lint/actions_ci.py index 3329089975..81eb26f22c 100644 --- a/tests/lint/actions_ci.py +++ b/tests/lint/actions_ci.py @@ -1,7 +1,9 @@ #!/usr/bin/env python import os + import yaml + import nf_core.lint diff --git a/tests/lint/actions_schema_validation.py b/tests/lint/actions_schema_validation.py index aa78b4e60d..d71603a56e 100644 --- a/tests/lint/actions_schema_validation.py +++ b/tests/lint/actions_schema_validation.py @@ -1,7 +1,9 @@ #!/usr/bin/env python import os + import yaml + import nf_core.lint diff --git a/tests/lint/files_exist.py b/tests/lint/files_exist.py index 572aeaae4e..338971b003 100644 --- a/tests/lint/files_exist.py +++ b/tests/lint/files_exist.py @@ -1,7 +1,9 @@ #!/usr/bin/env python import os + import yaml + import nf_core.lint diff --git a/tests/lint/files_unchanged.py b/tests/lint/files_unchanged.py index d890c217e7..41949cb37a 100644 --- a/tests/lint/files_unchanged.py +++ b/tests/lint/files_unchanged.py @@ -1,7 +1,8 @@ -import pytest +import os import shutil import tempfile -import os + +import pytest import nf_core.lint diff --git a/tests/lint/merge_markers.py b/tests/lint/merge_markers.py index 939919d7e7..23d5f52a0d 100644 --- a/tests/lint/merge_markers.py +++ b/tests/lint/merge_markers.py @@ -1,7 +1,9 @@ #!/usr/bin/env python import os + import yaml + import nf_core.lint diff --git a/tests/lint/nextflow_config.py b/tests/lint/nextflow_config.py index 229586372d..68e746a5c3 100644 --- a/tests/lint/nextflow_config.py +++ b/tests/lint/nextflow_config.py @@ -1,8 +1,9 @@ -import pytest -import unittest -import tempfile import os import shutil +import tempfile +import unittest + +import pytest import nf_core.create import nf_core.lint diff --git a/tests/modules/bump_versions.py b/tests/modules/bump_versions.py index df891cd4c7..388b6be424 100644 --- a/tests/modules/bump_versions.py +++ b/tests/modules/bump_versions.py @@ -1,5 +1,6 @@ import os import re + import pytest import nf_core.modules diff --git a/tests/modules/create.py b/tests/modules/create.py index b095d825e8..6c1767b138 100644 --- a/tests/modules/create.py +++ b/tests/modules/create.py @@ -1,4 +1,5 @@ import os + import pytest import nf_core.modules diff --git a/tests/modules/create_test_yml.py b/tests/modules/create_test_yml.py index 1666cd7646..dfb5fb5c6c 100644 --- a/tests/modules/create_test_yml.py +++ b/tests/modules/create_test_yml.py @@ -1,4 +1,5 @@ import os + import pytest import nf_core.modules diff --git a/tests/modules/install.py b/tests/modules/install.py index e4c94f6bdb..920aac729b 100644 --- a/tests/modules/install.py +++ b/tests/modules/install.py @@ -1,6 +1,7 @@ -import pytest import os +import pytest + from ..utils import with_temporary_folder diff --git a/tests/modules/list.py b/tests/modules/list.py index 4cf996e82c..43de293904 100644 --- a/tests/modules/list.py +++ b/tests/modules/list.py @@ -1,6 +1,7 @@ -import nf_core.modules from rich.console import Console +import nf_core.modules + def test_modules_list_remote(self): """Test listing available modules""" diff --git a/tests/modules/module_test.py b/tests/modules/module_test.py index a4559ffde5..40035c2724 100644 --- a/tests/modules/module_test.py +++ b/tests/modules/module_test.py @@ -1,5 +1,6 @@ """Test the 'modules test' command which runs module pytests.""" import os + import pytest import nf_core.modules diff --git a/tests/test_bump_version.py b/tests/test_bump_version.py index 9b4290c4e9..d6d38fb570 100644 --- a/tests/test_bump_version.py +++ b/tests/test_bump_version.py @@ -2,6 +2,7 @@ """Some tests covering the bump_version code. """ import os + import yaml import nf_core.bump_version diff --git a/tests/test_cli.py b/tests/test_cli.py index 474314b8eb..4bfc591407 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,11 +2,12 @@ """ Tests covering the command-line code. """ -import nf_core.__main__ +import unittest -from click.testing import CliRunner import mock -import unittest +from click.testing import CliRunner + +import nf_core.__main__ @mock.patch("nf_core.__main__.nf_core_cli") diff --git a/tests/test_create.py b/tests/test_create.py index cce494b523..3660608407 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -2,9 +2,10 @@ """Some tests covering the pipeline creation sub command. """ import os -import nf_core.create import unittest +import nf_core.create + from .utils import with_temporary_folder diff --git a/tests/test_download.py b/tests/test_download.py index 2dcc7b8cc5..95b3cca759 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -2,19 +2,20 @@ """Tests for the download subcommand of nf-core tools """ -import nf_core.create -import nf_core.utils -from nf_core.download import DownloadWorkflow - import hashlib -import mock import os -import pytest import shutil import tempfile import unittest -from .utils import with_temporary_folder, with_temporary_file +import mock +import pytest + +import nf_core.create +import nf_core.utils +from nf_core.download import DownloadWorkflow + +from .utils import with_temporary_file, with_temporary_folder class DownloadTest(unittest.TestCase): diff --git a/tests/test_launch.py b/tests/test_launch.py index 2d81bc5fcd..46ae611e77 100644 --- a/tests/test_launch.py +++ b/tests/test_launch.py @@ -2,16 +2,17 @@ """ Tests covering the pipeline launch code. """ -import nf_core.launch - import json -import mock import os import shutil import tempfile import unittest -from .utils import with_temporary_folder, with_temporary_file +import mock + +import nf_core.launch + +from .utils import with_temporary_file, with_temporary_folder class TestLaunch(unittest.TestCase): diff --git a/tests/test_licenses.py b/tests/test_licenses.py index 59ea08f7f3..0cbead8482 100644 --- a/tests/test_licenses.py +++ b/tests/test_licenses.py @@ -3,9 +3,10 @@ """ import json import os -import pytest import tempfile import unittest + +import pytest from rich.console import Console import nf_core.create diff --git a/tests/test_lint.py b/tests/test_lint.py index dec781e920..919b391961 100644 --- a/tests/test_lint.py +++ b/tests/test_lint.py @@ -3,14 +3,15 @@ """ import fnmatch import json -import mock import os -import pytest -import requests import shutil import subprocess import tempfile import unittest + +import mock +import pytest +import requests import yaml import nf_core.create @@ -188,47 +189,44 @@ def test_sphinx_md_files(self): # SPECIFIC LINT TESTS # ####################### from .lint.actions_awsfulltest import ( - test_actions_awsfulltest_warn, - test_actions_awsfulltest_pass, test_actions_awsfulltest_fail, + test_actions_awsfulltest_pass, + test_actions_awsfulltest_warn, ) - from .lint.actions_awstest import test_actions_awstest_pass, test_actions_awstest_fail - from .lint.files_exist import ( - test_files_exist_missing_config, - test_files_exist_missing_main, - test_files_exist_depreciated_file, - test_files_exist_pass, + from .lint.actions_awstest import ( + test_actions_awstest_fail, + test_actions_awstest_pass, ) from .lint.actions_ci import ( - test_actions_ci_pass, - test_actions_ci_fail_wrong_nf, test_actions_ci_fail_wrong_docker_ver, + test_actions_ci_fail_wrong_nf, test_actions_ci_fail_wrong_trigger, + test_actions_ci_pass, ) - from .lint.actions_schema_validation import ( + test_actions_schema_validation_fails_for_additional_property, test_actions_schema_validation_missing_jobs, test_actions_schema_validation_missing_on, - test_actions_schema_validation_fails_for_additional_property, ) - + from .lint.files_exist import ( + test_files_exist_depreciated_file, + test_files_exist_missing_config, + test_files_exist_missing_main, + test_files_exist_pass, + ) + from .lint.files_unchanged import ( + test_files_unchanged_fail, + test_files_unchanged_pass, + ) from .lint.merge_markers import test_merge_markers_found - + from .lint.modules_json import test_modules_json_pass from .lint.nextflow_config import ( - test_nextflow_config_example_pass, test_nextflow_config_bad_name_fail, test_nextflow_config_dev_in_release_mode_failed, + test_nextflow_config_example_pass, ) - - from .lint.files_unchanged import ( - test_files_unchanged_pass, - test_files_unchanged_fail, - ) - from .lint.version_consistency import test_version_consistency - from .lint.modules_json import test_modules_json_pass - # TODO nf-core: Assess and strip out if no longer required for DSL2 diff --git a/tests/test_modules.py b/tests/test_modules.py index b12333b51d..db04c55302 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -2,13 +2,13 @@ """ Tests covering the modules commands """ -import nf_core.modules - import os import shutil import tempfile import unittest +import nf_core.modules + def create_modules_repo_dummy(tmp_dir): """Create a dummy copy of the nf-core/modules repo""" @@ -71,50 +71,47 @@ def test_modulesrepo_class(self): # Test of the individual modules commands. # ############################################ - from .modules.list import ( - test_modules_list_remote, - test_modules_list_pipeline, - test_modules_install_and_list_pipeline, - ) - - from .modules.install import ( - test_modules_install_nopipeline, - test_modules_install_emptypipeline, - test_modules_install_nomodule, - test_modules_install_trimgalore, - test_modules_install_trimgalore_twice, - ) - - from .modules.remove import ( - test_modules_remove_trimgalore, - test_modules_remove_trimgalore_uninstalled, + from .modules.bump_versions import ( + test_modules_bump_versions_all_modules, + test_modules_bump_versions_fail, + test_modules_bump_versions_fail_unknown_version, + test_modules_bump_versions_single_module, ) - - from .modules.lint import test_modules_lint_trimgalore, test_modules_lint_empty, test_modules_lint_new_modules - from .modules.create import ( - test_modules_create_succeed, test_modules_create_fail_exists, test_modules_create_nfcore_modules, test_modules_create_nfcore_modules_subtool, + test_modules_create_succeed, ) - from .modules.create_test_yml import ( + test_modules_create_test_yml_check_inputs, + test_modules_create_test_yml_entry_points, + test_modules_create_test_yml_get_md5, test_modules_custom_yml_dumper, test_modules_test_file_dict, - test_modules_create_test_yml_get_md5, - test_modules_create_test_yml_entry_points, - test_modules_create_test_yml_check_inputs, ) - - from .modules.bump_versions import ( - test_modules_bump_versions_single_module, - test_modules_bump_versions_all_modules, - test_modules_bump_versions_fail, - test_modules_bump_versions_fail_unknown_version, + from .modules.install import ( + test_modules_install_emptypipeline, + test_modules_install_nomodule, + test_modules_install_nopipeline, + test_modules_install_trimgalore, + test_modules_install_trimgalore_twice, + ) + from .modules.lint import ( + test_modules_lint_empty, + test_modules_lint_new_modules, + test_modules_lint_trimgalore, + ) + from .modules.list import ( + test_modules_install_and_list_pipeline, + test_modules_list_pipeline, + test_modules_list_remote, ) - from .modules.module_test import ( test_modules_test_check_inputs, test_modules_test_no_name_no_prompts, ) + from .modules.remove import ( + test_modules_remove_trimgalore, + test_modules_remove_trimgalore_uninstalled, + ) diff --git a/tests/test_schema.py b/tests/test_schema.py index acda087690..14eb1f32d7 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -2,19 +2,20 @@ """ Tests covering the pipeline schema code. """ -import nf_core.schema - -import click import json -import mock import os -import pytest -import requests import shutil import tempfile import unittest + +import click +import mock +import pytest +import requests import yaml +import nf_core.schema + from .utils import with_temporary_file, with_temporary_folder diff --git a/tests/test_sync.py b/tests/test_sync.py index 66915009b8..57a095f96f 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -2,17 +2,18 @@ """ Tests covering the sync command """ -import nf_core.create -import nf_core.sync - -import git import json -import mock import os import shutil import tempfile import unittest +import git +import mock + +import nf_core.create +import nf_core.sync + from .utils import with_temporary_folder diff --git a/tests/test_utils.py b/tests/test_utils.py index b62a8c979b..dd2d38b566 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,17 +2,18 @@ """ Tests covering for utility functions. """ -import nf_core.create -import nf_core.list -import nf_core.utils +import os +import shutil +import tempfile +import unittest import mock -import os import pytest import requests -import tempfile -import unittest -import shutil + +import nf_core.create +import nf_core.list +import nf_core.utils from .utils import with_temporary_folder