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

Add support for generic git remotes #1641

Merged
merged 58 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
fb6d3c2
Rewriting intialisation of ModulesRepo
ErikDanielsson Jun 16, 2022
63beb2c
Setup should be done
ErikDanielsson Jun 16, 2022
b0b640f
Rationalize variables
ErikDanielsson Jun 16, 2022
babf143
Update module file download
ErikDanielsson Jun 16, 2022
e55ab0a
Downloading at different refs
ErikDanielsson Jun 16, 2022
2a47e79
Merge branch 'dev' of github.com:nf-core/tools into get-generic-git
ErikDanielsson Jun 16, 2022
112b103
Fix get_module_git_log
ErikDanielsson Jun 16, 2022
6953cf9
Update file comparision functionality
ErikDanielsson Jun 17, 2022
bc1c067
add comment to prompt func
ErikDanielsson Jun 17, 2022
3186292
Update prompt function
ErikDanielsson Jun 17, 2022
9c61c72
Update sha_exists
ErikDanielsson Jun 17, 2022
a31870e
Bugfixing - starting to work now
ErikDanielsson Jun 17, 2022
ee2f8d6
Update git commit info
ErikDanielsson Jun 17, 2022
b7a7ce4
Add no-pull option
ErikDanielsson Jun 17, 2022
23aefc9
Start updating modules.json functionality
ErikDanielsson Jun 17, 2022
948a4db
Update remaining modules.json functionality. Add new entry for git URL
ErikDanielsson Jun 17, 2022
ff4a6ee
Remove gh api functions
ErikDanielsson Jun 17, 2022
b85c212
Remove more api stuff
ErikDanielsson Jun 17, 2022
c251e74
Remove verify_pipeline. We cannot provide this functionality with the…
ErikDanielsson Jun 17, 2022
458e6bc
Remove gh api
ErikDanielsson Jun 17, 2022
0c99465
Misc bugfix
ErikDanielsson Jun 17, 2022
6379992
Fix bugs in create mod json and init of ModulesRepo
ErikDanielsson Jun 18, 2022
b093fc9
Remove old functions
ErikDanielsson Jun 18, 2022
4b405fd
Update module names functionality
ErikDanielsson Jun 18, 2022
d7e8e8b
ask -> unsafe_ask
ErikDanielsson Jun 18, 2022
928c905
Remove print statements
ErikDanielsson Jun 18, 2022
cc6ccef
Fix get_avail_modules
ErikDanielsson Jun 18, 2022
829f09f
Fix module name selection
ErikDanielsson Jun 18, 2022
1a69c4e
Make update work
ErikDanielsson Jun 18, 2022
a9eaf14
Add progress bars when cloning and pulling remote
ErikDanielsson Jun 18, 2022
99f581d
Add static variables for keeping track of pull status
ErikDanielsson Jun 18, 2022
6824918
Use @staticmethod method instead of @classmethod...
ErikDanielsson Jun 18, 2022
770e4e1
Fix modules list
ErikDanielsson Jun 18, 2022
ab09a58
Fix info
ErikDanielsson Jun 19, 2022
b698585
Update main function
ErikDanielsson Jun 19, 2022
632fc67
Bug fix, user info and new option --no-pull
ErikDanielsson Jun 19, 2022
fdfde82
Remove unused function and update comments
ErikDanielsson Jun 19, 2022
d7c46bb
Update CHANGELOG.md
ErikDanielsson Jun 19, 2022
a6b6521
Update docs
ErikDanielsson Jun 19, 2022
91d7bf8
Fix docs
ErikDanielsson Jun 19, 2022
ae05e73
Fix dry run bug
ErikDanielsson Jun 20, 2022
c973783
Remove double creation of ModulesRepo
ErikDanielsson Jun 20, 2022
1bf1db7
Fix list local
ErikDanielsson Jun 20, 2022
76374e3
Fix no-pull
ErikDanielsson Jun 20, 2022
c166aa1
Update tests
ErikDanielsson Jun 20, 2022
e97d30c
Fix the last bugs
ErikDanielsson Jun 20, 2022
7c70169
Remove sneaky api calls
ErikDanielsson Jun 20, 2022
08b92d8
make work with https
ErikDanielsson Jun 20, 2022
305ead8
isort
ErikDanielsson Jun 20, 2022
5e7c1a3
Don't fail horribly due to LookupError
ErikDanielsson Jun 20, 2022
228973a
black
ErikDanielsson Jun 20, 2022
b30007e
Fix lookup bug
ErikDanielsson Jun 21, 2022
80c6c20
General cleanup. Change where files are cloned
ErikDanielsson Jun 21, 2022
0bee100
Apply suggestions from code review
ErikDanielsson Jun 21, 2022
f994bd3
Use .config
ErikDanielsson Jun 21, 2022
b4d4b89
Update docs
ErikDanielsson Jun 21, 2022
1b1b7e3
Merge branch 'dev' of github.com:nf-core/tools into get-generic-git
ErikDanielsson Jun 21, 2022
c558fd3
Merge branch 'get-generic-git' of github.com:ErikDanielsson/tools int…
ErikDanielsson Jun 21, 2022
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

- Add `--fix-version` flag to `nf-core modules lint` command to update modules to the latest version ([#1588](https://github.com/nf-core/tools/pull/1588))
- Fix a bug in the regex extracting the version from biocontainers URLs ([#1598](https://github.com/nf-core/tools/pull/1598))
- Update how we interface with git remotes. ([#1626](https://github.com/nf-core/tools/issues/1626))

## [v2.4.1 - Cobolt Koala Patch](https://github.com/nf-core/tools/releases/tag/2.4) - [2022-05-16]

Expand Down Expand Up @@ -59,7 +60,7 @@
- Add a new command `nf-core modules test` which runs pytests locally.
- Print include statement to terminal when `modules install` ([#1520](https://github.com/nf-core/tools/pull/1520))
- Allow follow links when generating `test.yml` file with `nf-core modules create-test-yml` ([1570](https://github.com/nf-core/tools/pull/1570))
- Escaped test run output before logging it, to avoid a rich ` MarkupError`
- Escaped test run output before logging it, to avoid a rich `MarkupError`

### Linting

Expand Down
43 changes: 13 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -907,42 +907,25 @@ This allows multiple pipelines to use the same code for share tools and gives a

The nf-core DSL2 modules repository is at <https://github.com/nf-core/modules>

### Running the module commands

The `nf-core/tools` package contains a suite of commands for working DSL2 modules in your pipeline. The modules commands use `git` to interface
with the `nf-core/modules` repository. Therefore you need to have have `git` installed to use the modules commands. You can then use the
the modules commands for a variety of tasks such as creating new DSL2 modules, viewing and getting metadata about the modules in your pipeline,
and installing and updating modules from a remote git repository.

ErikDanielsson marked this conversation as resolved.
Show resolved Hide resolved
### Custom remote modules

The modules supercommand comes with two flags for specifying a custom remote:

- `--github-repository <github repo>`: Specify the repository from which the modules should be fetched. Defaults to `nf-core/modules`.
- `--branch <branch name>`: Specify the branch from which the modules shoudl be fetched. Defaults to `master`.
- `--git-remote <git remote url>`: Specify the repository from which the modules should be fetched as a git URL. Defaults to the github repository of `nf-core/modules`.
ErikDanielsson marked this conversation as resolved.
Show resolved Hide resolved
- `--branch <branch name>`: Specify the branch from which the modules should be fetched. Defaults to the default branch of your repository
ErikDanielsson marked this conversation as resolved.
Show resolved Hide resolved

Note that a custom remote must follow a similar directory structure to that of `nf-core/moduleś` for the `nf-core modules` commands to work properly.

### Private remote modules
ErikDanielsson marked this conversation as resolved.
Show resolved Hide resolved

In order to get access to your private modules repo, you need to create
the `~/.config/gh/hosts.yml` file, which is the same file required by
[GitHub CLI](https://cli.github.com/) to deal with private repositories.
Such file is structured as follow:

```conf
github.com:
oauth_token: <your github access token>
user: <your github user>
git_protocol: <ssh or https are valid choices>
```

The easiest way to create this configuration file is through _GitHub CLI_: follow
its [installation instructions](https://cli.github.com/manual/installation)
and then call:

```bash
gh auth login
```

After that, you will be able to list and install your private modules without
providing your github credentials through command line, by using `--github-repository`
and `--branch` options properly.
See the documentation on [gh auth login](https://cli.github.com/manual/gh_auth_login>)
to get more information.
The modules commands will during initalisation try to pull changes from the remote repositories. If you want to disable this, for example
due to performance reason or if you want to run the commands offline, you can use the flag `--no-pull`. Note however that the commands will
still need to clone repositories that have previously not been used.

### List modules

Expand Down Expand Up @@ -1079,7 +1062,7 @@ There are three additional flags that you can use when installing a module:

- `--force`: Overwrite a previously installed version of the module.
- `--prompt`: Select the module version using a cli prompt.
- `--sha <commit_sha>`: Install the module at a specific commit from the `nf-core/modules` repository.
- `--sha <commit_sha>`: Install the module at a specific commit.

### Update modules in a pipeline

Expand Down
113 changes: 88 additions & 25 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# Submodules should all traverse back to this
log = logging.getLogger()

# Set up .nfcore directory for storing files between sessions
nf_core.utils.setup_nfcore_dir()

# Set up nicer formatting of click cli help messages
click.rich_click.MAX_WIDTH = 100
click.rich_click.USE_RICH_MARKUP = True
Expand Down Expand Up @@ -342,27 +345,31 @@ def lint(dir, release, fix, key, show_passed, fail_ignored, fail_warned, markdow
@nf_core_cli.group()
@click.option(
"-g",
"--github-repository",
"--git-remote",
type=str,
default="nf-core/modules",
help="GitHub repository hosting modules.",
default=nf_core.modules.modules_repo.NF_CORE_MODULES_REMOTE,
help="Remote git repo to fetch files from",
)
@click.option("-b", "--branch", type=str, default=None, help="Branch of git repository hosting modules.")
@click.option(
"--no-pull",
is_flag=True,
default=False,
help="Use this option for faster commands if you know there have been no recent changes to the repository",
ErikDanielsson marked this conversation as resolved.
Show resolved Hide resolved
)
@click.option("-b", "--branch", type=str, default="master", help="Branch of GitHub repository hosting modules.")
@click.pass_context
def modules(ctx, github_repository, branch):
def modules(ctx, git_remote, branch, no_pull):
"""
Commands to manage Nextflow DSL2 modules (tool wrappers).
"""
# ensure that ctx.obj exists and is a dict (in case `cli()` is called
# by means other than the `if` block below)
ctx.ensure_object(dict)

# Make repository object to pass to subcommands
try:
ctx.obj["modules_repo_obj"] = nf_core.modules.ModulesRepo(github_repository, branch)
except LookupError as e:
log.critical(e)
sys.exit(1)
# Place the arguments in a context object
ctx.obj["modules_repo_url"] = git_remote
ctx.obj["modules_repo_branch"] = branch
ctx.obj["modules_repo_no_pull"] = no_pull


# nf-core modules list subcommands
Expand All @@ -385,12 +392,17 @@ def remote(ctx, keywords, json):
List modules in a remote GitHub repo [dim i](e.g [link=https://github.com/nf-core/modules]nf-core/modules[/])[/].
"""
try:
module_list = nf_core.modules.ModuleList(None, remote=True)
module_list = nf_core.modules.ModuleList(
None, True, ctx.obj["modules_repo_url"], ctx.obj["modules_repo_branch"], ctx.obj["modules_repo_no_pull"]
)
module_list.modules_repo = ctx.obj["modules_repo_obj"]
print(module_list.list_modules(keywords, json))
except UserWarning as e:
log.critical(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)
ErikDanielsson marked this conversation as resolved.
Show resolved Hide resolved


# nf-core modules list local
Expand All @@ -410,12 +422,16 @@ def local(ctx, keywords, json, dir):
List modules installed locally in a pipeline
"""
try:
module_list = nf_core.modules.ModuleList(dir, remote=False)
module_list.modules_repo = ctx.obj["modules_repo_obj"]
module_list = nf_core.modules.ModuleList(
dir, False, ctx.obj["modules_repo_url"], ctx.obj["modules_repo_branch"], ctx.obj["modules_repo_no_pull"]
)
print(module_list.list_modules(keywords, json))
except UserWarning as e:
log.critical(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core modules install
Expand All @@ -439,14 +455,24 @@ def install(ctx, tool, dir, prompt, force, sha):
Fetches and installs module files from a remote repo e.g. nf-core/modules.
"""
try:
module_install = nf_core.modules.ModuleInstall(dir, force=force, prompt=prompt, sha=sha)
module_install.modules_repo = ctx.obj["modules_repo_obj"]
module_install = nf_core.modules.ModuleInstall(
dir,
force,
prompt,
sha,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
exit_status = module_install.install(tool)
if not exit_status and all:
sys.exit(1)
except UserWarning as e:
log.error(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core modules update
Expand Down Expand Up @@ -487,15 +513,26 @@ def update(ctx, tool, dir, force, prompt, sha, all, preview, save_diff):
"""
try:
module_install = nf_core.modules.ModuleUpdate(
dir, force=force, prompt=prompt, sha=sha, update_all=all, show_diff=preview, save_diff_fn=save_diff
dir,
force,
prompt,
sha,
all,
preview,
save_diff,
ctx.obj["modules_repo_url"],
ctx.obj["modules_repo_branch"],
ctx.obj["modules_repo_no_pull"],
)
module_install.modules_repo = ctx.obj["modules_repo_obj"]
exit_status = module_install.update(tool)
if not exit_status and all:
sys.exit(1)
except UserWarning as e:
log.error(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core modules remove
Expand All @@ -514,12 +551,16 @@ def remove(ctx, dir, tool):
Remove a module from a pipeline.
"""
try:
module_remove = nf_core.modules.ModuleRemove(dir)
module_remove.modules_repo = ctx.obj["modules_repo_obj"]
module_remove = nf_core.modules.ModuleRemove(
dir, ctx.obj["modules_repo_url"], ctx.obj["modules_repo_branch"], ctx.obj["modules_repo_no_pull"]
)
module_remove.remove(tool)
except UserWarning as e:
log.critical(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core modules create
Expand Down Expand Up @@ -562,6 +603,9 @@ def create_module(ctx, tool, dir, author, label, meta, no_meta, force, conda_nam
except UserWarning as e:
log.critical(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core modules create-test-yml
Expand All @@ -585,6 +629,9 @@ def create_test_yml(ctx, tool, run_tests, output, force, no_prompts):
except UserWarning as e:
log.critical(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core modules lint
Expand All @@ -608,8 +655,9 @@ def lint(ctx, tool, dir, key, all, local, passed, fix_version):
nf-core/modules repository.
"""
try:
module_lint = nf_core.modules.ModuleLint(dir=dir)
module_lint.modules_repo = ctx.obj["modules_repo_obj"]
module_lint = nf_core.modules.ModuleLint(
dir, ctx.obj["modules_repo_url"], ctx.obj["modules_repo_branch"], ctx.obj["modules_repo_no_pull"]
)
module_lint.lint(
module=tool,
key=key,
Expand All @@ -627,6 +675,9 @@ def lint(ctx, tool, dir, key, all, local, passed, fix_version):
except UserWarning as e:
log.critical(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core modules info
Expand All @@ -653,12 +704,16 @@ def info(ctx, tool, dir):
If not, usage from the remote modules repo will be shown.
"""
try:
module_info = nf_core.modules.ModuleInfo(dir, tool)
module_info.modules_repo = ctx.obj["modules_repo_obj"]
module_info = nf_core.modules.ModuleInfo(
dir, tool, ctx.obj["modules_repo_url"], ctx.obj["modules_repo_branch"], ctx.obj["modules_repo_no_pull"]
)
print(module_info.get_module_info())
except UserWarning as e:
log.error(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core modules bump-versions
Expand All @@ -674,14 +729,19 @@ def bump_versions(ctx, tool, dir, all, show_all):
the nf-core/modules repo.
"""
try:
version_bumper = nf_core.modules.bump_versions.ModuleVersionBumper(pipeline_dir=dir)
version_bumper = nf_core.modules.bump_versions.ModuleVersionBumper(
dir, ctx.obj["modules_repo_url"], ctx.obj["modules_repo_branch"], ctx.obj["modules_repo_no_pull"]
)
version_bumper.bump_versions(module=tool, all_modules=all, show_uptodate=show_all)
except nf_core.modules.module_utils.ModuleException as e:
log.error(e)
sys.exit(1)
except UserWarning as e:
log.critical(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core modules mulled
Expand Down Expand Up @@ -745,6 +805,9 @@ def test_module(ctx, tool, no_prompts, pytest_args):
except UserWarning as e:
log.critical(e)
sys.exit(1)
except LookupError as e:
log.error(e)
sys.exit(1)


# nf-core schema subcommands
Expand Down
9 changes: 8 additions & 1 deletion nf_core/lint/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ def modules_json(self):
all_modules_passed = True

for repo in modules_json["repos"].keys():
for key in modules_json["repos"][repo].keys():
# Check if the modules.json has been updated to keep the
if "modules" not in modules_json["repos"][repo] or "git_url" not in modules_json["repos"][repo]:
failed.append(
f"Your `modules.json` file is outdated. Please remove it and reinstall it by running any module command"
)
continue

for key in modules_json["repos"][repo]["modules"]:
if not key in modules_command.module_names[repo]:
failed.append(f"Entry for `{key}` found in `modules.json` but module is not installed in pipeline.")
all_modules_passed = False
Expand Down
4 changes: 2 additions & 2 deletions nf_core/modules/bump_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@


class ModuleVersionBumper(ModuleCommand):
def __init__(self, pipeline_dir):
super().__init__(pipeline_dir)
def __init__(self, pipeline_dir, remote_url=None, branch=None, no_pull=False):
super().__init__(pipeline_dir, remote_url, branch, no_pull)

self.up_to_date = None
self.updated = None
Expand Down
Loading