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 bug with creating .nf-core.yml file when it can't be found #2562

Merged
merged 4 commits into from
Dec 14, 2023

Conversation

krokicki
Copy link
Contributor

@krokicki krokicki commented Dec 8, 2023

This PR fixes a bug (#2237) that occurs if you run nf-core modules install in a directory which does not yet have a .nf-core.yml file. The user is promoted if they want to create the file, but then it walks up the tree searching for an .nf-core.yml file and ends up at the root of the filesystem where it tries to create the file (/.nf-core.yml) and fails:

WARNING  'repository_type' not defined in .nf-core.yml
? Is this repository an nf-core pipeline or a fork of nf-core/modules? Pipeline
INFO     To avoid this prompt in the future, add the 'repository_type' key to your .nf-core.yml file.
? Would you like me to add this config now? [y/n] (y):
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
...

│ mponents/components_utils.py:45 in get_repo_info                                                 │
│                                                                                                  │
│    42 │   │   # Save the choice in the config file                                               │
│    43 │   │   log.info(f"To avoid this prompt in the future, add the 'repository_type' key to    │
│    44 │   │   if rich.prompt.Confirm.ask("[bold][blue]?[/] Would you like me to add this confi   │
│ ❱  45 │   │   │   with open(config_fn, "a+") as fh:                                              │
│    46 │   │   │   │   fh.write(f"repository_type: {repo_type}\n")                                │
│    47 │   │   │   │   log.info(f"Config added to '{config_fn.name}'")                            │
│    48                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
PermissionError: [Errno 13] Permission denied: '/.nf-core.yml'

The fixed algorithm works in this case, and is also optimized to do fewer file existence checks (the current algorithm calls get_first_available_path twice for each directory which is not necessary).

PR checklist

  • [ X ] This comment contains a description of changes (with reason)
  • [ X ] CHANGELOG.md is updated
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

Copy link
Member

@mirpedrol mirpedrol left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix :)

Copy link

codecov bot commented Dec 14, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (2c9ccec) 74.93% compared to head (9f5a7d8) 74.96%.
Report is 19 commits behind head on dev.

Files Patch % Lines
nf_core/utils.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2562      +/-   ##
==========================================
+ Coverage   74.93%   74.96%   +0.03%     
==========================================
  Files          85       85              
  Lines        9356     9356              
==========================================
+ Hits         7011     7014       +3     
+ Misses       2345     2342       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants