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

Refactor passing of command line arguments to nf-core commands #1145

Merged
Merged
Changes from 1 commit
Commits
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
Next Next commit
Added '--dir' to 'bump-version' and 'sync'
ErikDanielsson committed Jul 1, 2021
commit 48f3cb47fc08eaa976ff8217b9e1e5a75fcc42f8
32 changes: 18 additions & 14 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
@@ -619,12 +619,12 @@ def lint(schema_path):


@nf_core_cli.command("bump-version", help_priority=9)
@click.argument("pipeline_dir", type=click.Path(exists=True), required=True, metavar="<pipeline directory>")
@click.argument("new_version", required=True, metavar="<new version>")
@click.option("-d", "--dir", type=click.Path(exists=True), default=".", help="Pipeline directory. Defaults to CWD")
@click.option(
"-n", "--nextflow", is_flag=True, default=False, help="Bump required nextflow version instead of pipeline version"
)
def bump_version(pipeline_dir, new_version, nextflow):
def bump_version(new_version, dir, nextflow):
"""
Update nf-core pipeline version number.

@@ -637,24 +637,28 @@ def bump_version(pipeline_dir, new_version, nextflow):

As well as the pipeline version, you can also change the required version of Nextflow.
"""
# Make a pipeline object and load config etc
pipeline_obj = nf_core.utils.Pipeline(pipeline_dir)
pipeline_obj._load()

# Bump the pipeline version number
if not nextflow:
nf_core.bump_version.bump_pipeline_version(pipeline_obj, new_version)
else:
nf_core.bump_version.bump_nextflow_version(pipeline_obj, new_version)
try:
# Make a pipeline object and load config etc
pipeline_obj = nf_core.utils.Pipeline(dir)
pipeline_obj._load()

# Bump the pipeline version number
if not nextflow:
nf_core.bump_version.bump_pipeline_version(pipeline_obj, new_version)
else:
nf_core.bump_version.bump_nextflow_version(pipeline_obj, new_version)
except UserWarning as e:
log.error(e)
sys.exit(1)


@nf_core_cli.command("sync", help_priority=10)
@click.argument("pipeline_dir", required=True, type=click.Path(exists=True), metavar="<pipeline directory>")
@click.option("-d", "--dir", type=click.Path(exists=True), default=".", help="Pipeline directory. Defaults to CWD")
@click.option("-b", "--from-branch", type=str, help="The git branch to use to fetch workflow vars.")
@click.option("-p", "--pull-request", is_flag=True, default=False, help="Make a GitHub pull-request with the changes.")
@click.option("-r", "--repository", type=str, help="GitHub PR: target repository.")
@click.option("-u", "--username", type=str, help="GitHub PR: auth username.")
def sync(pipeline_dir, from_branch, pull_request, repository, username):
def sync(dir, from_branch, pull_request, repository, username):
"""
Sync a pipeline TEMPLATE branch with the nf-core template.

@@ -669,7 +673,7 @@ def sync(pipeline_dir, from_branch, pull_request, repository, username):
"""

# Sync the given pipeline dir
sync_obj = nf_core.sync.PipelineSync(pipeline_dir, from_branch, pull_request, repository, username)
sync_obj = nf_core.sync.PipelineSync(dir, from_branch, pull_request, repository, username)
try:
sync_obj.sync()
except (nf_core.sync.SyncException, nf_core.sync.PullRequestException) as e:
7 changes: 3 additions & 4 deletions nf_core/bump_version.py
Original file line number Diff line number Diff line change
@@ -29,8 +29,8 @@ def bump_pipeline_version(pipeline_obj, new_version):
log.warning("Stripping leading 'v' from new version number")
new_version = new_version[1:]
if not current_version:
log.error("Could not find config variable 'manifest.version'")
sys.exit(1)
raise UserWarning("Could not find config variable 'manifest.version'")

log.info("Changing version number from '{}' to '{}'".format(current_version, new_version))

# nextflow.config - workflow manifest version
@@ -60,8 +60,7 @@ def bump_nextflow_version(pipeline_obj, new_version):
current_version = re.sub(r"^[^0-9\.]*", "", current_version)
new_version = re.sub(r"^[^0-9\.]*", "", new_version)
if not current_version:
log.error("Could not find config variable 'manifest.nextflowVersion'")
sys.exit(1)
raise UserWarning("Could not find config variable 'manifest.nextflowVersion'")
log.info("Changing Nextlow version number from '{}' to '{}'".format(current_version, new_version))

# nextflow.config - manifest minimum nextflowVersion
6 changes: 6 additions & 0 deletions nf_core/sync.py
Original file line number Diff line number Diff line change
@@ -66,6 +66,12 @@ def __init__(
):
"""Initialise syncing object"""

# Check if 'pipeline_dir' is a pipeline directory
try:
nf_core.utils.is_pipeline_directory(pipeline_dir)
except UserWarning:
raise

self.pipeline_dir = os.path.abspath(pipeline_dir)
self.from_branch = from_branch
self.original_branch = None
23 changes: 23 additions & 0 deletions nf_core/utils.py
Original file line number Diff line number Diff line change
@@ -121,6 +121,12 @@ def __init__(self, wf_path):
self.pipeline_name = None
self.schema_obj = None

# Check if 'wf_path' is a pipeline directory
try:
is_pipeline_directory(self.wf_path)
except UserWarning:
raise

try:
repo = git.Repo(self.wf_path)
self.git_sha = repo.head.object.hexsha
@@ -183,6 +189,23 @@ def _fp(self, fn):
return os.path.join(self.wf_path, fn)


def is_pipeline_directory(wf_path):
"""
Checks if the specified directory have the minimum required files
('main.nf', 'nextflow.config') for a pipeline directory

Args:
wf_path (str): The directory to be inspected

Raises:
UserWarning: If one of the files are missing
"""
for fn in ["main.nf", "nextflow.config"]:
path = os.path.join(wf_path, fn)
if not os.path.isfile(path):
raise UserWarning(f"'{wf_path}' is not a pipeline - '{fn}' is missing")


def fetch_wf_config(wf_path):
"""Uses Nextflow to retrieve the the configuration variables
from a Nextflow workflow.