Skip to content

Commit

Permalink
add option to skip code linters
Browse files Browse the repository at this point in the history
  • Loading branch information
mirpedrol committed Jul 29, 2024
1 parent baa1a3c commit e2ecfdd
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 263 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/create-test-lint-wf-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- "template_skip_github_badges.yml"
- "template_skip_igenomes.yml"
- "template_skip_ci.yml"
- "template_skip_code_linters.yml"
runner:
# use the runner given by the input if it is dispatched manually, run on github if it is a rerun or on self-hosted by default
- ${{ github.event.inputs.runners || github.run_number > 1 && 'ubuntu-latest' || 'self-hosted' }}
Expand Down Expand Up @@ -102,6 +103,10 @@ jobs:
run: |
printf "org: my-prefix\nskip: nf_core_configs" > create-test-lint-wf/template_skip_nf_core_configs.yml
- name: Create template skip code_linters
run: |
printf "org: my-prefix\nskip: code_linters" > create-test-lint-wf/template_skip_code_linters.yml
# Create a pipeline from the template
- name: create a pipeline from the template ${{ matrix.TEMPLATE }}
run: |
Expand Down
4 changes: 2 additions & 2 deletions nf_core/pipeline-template/.gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ tasks:
vscode:
extensions: # based on nf-core.nf-core-extensionpack
- esbenp.prettier-vscode # Markdown/CommonMark linting and style checking for Visual Studio Code
- EditorConfig.EditorConfig # override user/workspace settings with settings found in .editorconfig files
{%- if code_linters %}- esbenp.prettier-vscode # Markdown/CommonMark linting and style checking for Visual Studio Code
- EditorConfig.EditorConfig # override user/workspace settings with settings found in .editorconfig files{% endif %}
- Gruntfuggly.todo-tree # Display TODO and FIXME in a tree view in the activity bar
- mechatroner.rainbow-csv # Highlight columns in csv files in different colors
# - nextflow.nextflow # Nextflow syntax highlighting
Expand Down
2 changes: 2 additions & 0 deletions nf_core/pipelines/create/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def __init__(
".github/workflows/awstest.yml",
".github/workflows/release-announcements.yml",
],
"code_linters": [".editorconfig", ".pre-commit-config.yaml", ".prettierignore", ".prettierrc.yml", ".github/workflows/fix-linting.yml"]
}
# Get list of files we're skipping with the supplied skip keys
self.skip_paths = set(sp for k in skip_paths for sp in skippable_paths[k])
Expand Down Expand Up @@ -202,6 +203,7 @@ def obtain_jinja_params_dict(self, features_to_skip, pipeline_dir):
"github_badges": {"file": False, "content": True},
"igenomes": {"file": True, "content": True},
"nf_core_configs": {"file": False, "content": True},
"code_linters": {"file": True, "content": True}
}

# Set the parameters for the jinja template
Expand Down
16 changes: 16 additions & 0 deletions nf_core/pipelines/create/custompipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
For more information about nf-core configuration profiles, see the [nf-core/configs repository](https://github.com/nf-core/configs)
"""

markdown_code_linters = """
Pipelines include code linters, these linters will check the formatting of your code.
Linters will check JSON, YAML, Python and others.
The available code linters are:
- pre-commit (https://pre-commit.com/): used to run all code-linters on every PR and on ever commit if you run `pre-commit install` to install it in your local repository.
- editor-config (https://github.com/editorconfig-checker/editorconfig-checker): checks rules such as indentation or trailing spaces.
- prettier (https://github.com/prettier/prettier): enforces a consistent style (indentation, quoting, line length, etc).
"""


class CustomPipeline(Screen):
"""Select if the pipeline will use genomic data."""
Expand Down Expand Up @@ -80,6 +90,12 @@ def compose(self) -> ComposeResult:
"The pipeline will include configuration profiles containing custom parameters requried to run nf-core pipelines at different institutions",
"nf_core_configs",
),
PipelineFeature(
markdown_code_linters,
"Use code linters",
"The pipeline will include code linters and CI tests to lint your code: pre-commit, editor-config and prettier.",
"code_linters",
),
classes="features-container",
)
yield Center(
Expand Down
511 changes: 256 additions & 255 deletions tests/__snapshots__/test_create_app.ambr

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/data/pipeline_create_template_skip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ skip_features:
- github_badges
- igenomes
- nf_core_configs
- code_linters
14 changes: 8 additions & 6 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ def test_pipeline_creation_with_yml_skip(self, tmp_path):
pipeline.init_pipeline()

# Check pipeline template yml has been dumped to `.nf-core.yml` and matches input
assert not os.path.exists(os.path.join(pipeline.outdir, "pipeline_template.yml"))
assert os.path.exists(os.path.join(pipeline.outdir, ".nf-core.yml"))
with open(os.path.join(pipeline.outdir, ".nf-core.yml")) as fh:
assert not os.path.exists(Path(pipeline.outdir / "pipeline_template.yml"))
assert os.path.exists(Path(pipeline.outdir / ".nf-core.yml"))
with open(Path(pipeline.outdir / ".nf-core.yml")) as fh:
nfcore_yml = yaml.safe_load(fh)
assert "template" in nfcore_yml
assert yaml.safe_load(PIPELINE_TEMPLATE_YML.read_text()).items() <= nfcore_yml["template"].items()

# Check that some of the skipped files are not present
assert not os.path.exists(os.path.join(pipeline.outdir, "CODE_OF_CONDUCT.md"))
assert not os.path.exists(os.path.join(pipeline.outdir, ".github"))
assert not os.path.exists(os.path.join(pipeline.outdir, "conf", "igenomes.config"))
assert not os.path.exists(Path(pipeline.outdir / "CODE_OF_CONDUCT.md"))
assert not os.path.exists(Path(pipeline.outdir / ".github"))
assert not os.path.exists(Path(pipeline.outdir / "conf" / "igenomes.config"))
assert not os.path.exists(Path(pipeline.outdir / ".editorconfig"))
assert not os.path.exists(Path(pipeline.outdir / ".editorconfig"))

0 comments on commit e2ecfdd

Please sign in to comment.