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

Fix pre commit template #3358

Merged
merged 12 commits into from
Dec 16, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Template

- Use outputs instead of the environment to pass around values between steps in the Download Test Action ([#3351](https://github.com/nf-core/tools/pull/3351))
- Fix pre commit template ([#3358](https://github.com/nf-core/tools/pull/3358))

### Download

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ body:
- [nf-core website: troubleshooting](https://nf-co.re/usage/troubleshooting)
- [{{ name }} pipeline documentation](https://nf-co.re/{{ short_name }}/usage)
{%- endif %}

- type: textarea
id: description
attributes:
Expand Down
2 changes: 1 addition & 1 deletion nf_core/pipeline-template/.gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tasks:
- name: Update Nextflow and setup pre-commit
command: |
pre-commit install --install-hooks
nextflow self-update {% if code_linters %}
nextflow self-update {%- if code_linters %}

vscode:
extensions:
Expand Down
3 changes: 3 additions & 0 deletions nf_core/pipeline-template/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ testing/
testing*
*.pyc
bin/
{%- if rocrate %}
ro-crate-metadata.json
{%- endif %}
2 changes: 1 addition & 1 deletion nf_core/pipeline-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</picture>
</h1>

{% else %}
{%- else -%}

# {{ name }}

Expand Down
2 changes: 1 addition & 1 deletion nf_core/pipeline-template/nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ validation {
command = "nextflow run {{ name }} -profile <docker/singularity/.../institute> --input samplesheet.csv --outdir <OUTDIR>"
fullParameter = "help_full"
showHiddenParameter = "show_hidden"
{% if is_nfcore -%}
{%- if is_nfcore %}
beforeText = """
-\033[2m----------------------------------------------------\033[0m-
\033[0;32m,--.\033[0;30m/\033[0;32m,-.\033[0m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ workflow PIPELINE_COMPLETION {
{%- if multiqc %}
def multiqc_reports = multiqc_report.toList()
{%- endif %}

//
// Completion email and summary
//
Expand Down
4 changes: 2 additions & 2 deletions nf_core/pipelines/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import nf_core.utils
from nf_core.pipelines.rocrate import ROCrate
from nf_core.utils import Pipeline
from nf_core.utils import Pipeline, custom_yaml_dumper

log = logging.getLogger(__name__)
stderr = rich.console.Console(stderr=True, force_terminal=nf_core.utils.rich_force_colors())
Expand Down Expand Up @@ -257,7 +257,7 @@ def update_yaml_file(fn: Path, patterns: List[Tuple[str, str]], yaml_key: List[s
if new_value != current_value:
target[last_key] = new_value
with open(fn, "w") as file:
yaml.dump(yaml_content, file)
yaml.dump(yaml_content, file, Dumper=custom_yaml_dumper())
log.info(f"Updated version in YAML file '{fn}'")
log_change(str(current_value), str(new_value))
except KeyError as e:
Expand Down
14 changes: 8 additions & 6 deletions nf_core/pipelines/create/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from nf_core.pipelines.create_logo import create_logo
from nf_core.pipelines.lint_utils import run_prettier_on_file
from nf_core.pipelines.rocrate import ROCrate
from nf_core.utils import NFCoreTemplateConfig, NFCoreYamlLintConfig
from nf_core.utils import NFCoreTemplateConfig, NFCoreYamlLintConfig, custom_yaml_dumper

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -266,6 +266,11 @@ def init_pipeline(self):
# Init the git repository and make the first commit
if not self.no_git:
self.git_init_pipeline()
# Run prettier on files
current_dir = Path.cwd()
os.chdir(self.outdir)
run_prettier_on_file([str(f) for f in self.outdir.glob("**/*")])
os.chdir(current_dir)

if self.config.is_nfcore and not self.is_interactive:
log.info(
Expand Down Expand Up @@ -375,12 +380,9 @@ def render_template(self) -> None:
if config_fn is not None and config_yml is not None:
with open(str(config_fn), "w") as fh:
config_yml.template = NFCoreTemplateConfig(**self.config.model_dump(exclude_none=True))
yaml.safe_dump(config_yml.model_dump(exclude_none=True), fh)
yaml.dump(config_yml.model_dump(exclude_none=True), fh, Dumper=custom_yaml_dumper())
log.debug(f"Dumping pipeline template yml to pipeline config file '{config_fn.name}'")

# Run prettier on files
run_prettier_on_file([str(f) for f in self.outdir.glob("**/*")])

def fix_linting(self):
"""
Updates the .nf-core.yml with linting configurations
Expand Down Expand Up @@ -408,7 +410,7 @@ def fix_linting(self):
if config_fn is not None and nf_core_yml is not None:
nf_core_yml.lint = NFCoreYamlLintConfig(**lint_config)
with open(self.outdir / config_fn, "w") as fh:
yaml.dump(nf_core_yml.model_dump(exclude_none=True), fh, default_flow_style=False, sort_keys=False)
yaml.dump(nf_core_yml.model_dump(exclude_none=True), fh, Dumper=custom_yaml_dumper())

def make_pipeline_logo(self):
"""Fetch a logo for the new pipeline from the nf-core website"""
Expand Down
2 changes: 1 addition & 1 deletion nf_core/pipelines/lint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def run_prettier_on_file(file: Union[Path, str, List[str]]) -> None:
all_lines = [line for line in e.stdout.decode().split("\n")]
files = "\n".join(all_lines[3:])
log.debug(f"The following files were modified by prettier:\n {files}")
elif e.stderr.decode():
else:
log.warning(
"There was an error running the prettier pre-commit hook.\n"
f"STDOUT: {e.stdout.decode()}\nSTDERR: {e.stderr.decode()}"
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import nf_core.modules
import nf_core.pipelines.create.create
from nf_core import __version__
from nf_core.utils import NFCoreTemplateConfig, NFCoreYamlConfig
from nf_core.utils import NFCoreTemplateConfig, NFCoreYamlConfig, custom_yaml_dumper

TEST_DATA_DIR = Path(__file__).parent / "data"
OLD_TRIMGALORE_SHA = "9b7a3bdefeaad5d42324aa7dd50f87bea1b04386"
Expand Down Expand Up @@ -136,7 +136,7 @@ def create_tmp_pipeline(no_git: bool = False) -> Tuple[Path, Path, str, Path]:
bump_version=None,
)
with open(str(Path(pipeline_dir, ".nf-core.yml")), "w") as fh:
yaml.dump(nf_core_yml.model_dump(), fh)
yaml.dump(nf_core_yml.model_dump(), fh, Dumper=custom_yaml_dumper())

nf_core.pipelines.create.create.PipelineCreate(
pipeline_name, "it is mine", "me", no_git=no_git, outdir=pipeline_dir, force=True
Expand Down
Loading