Skip to content

Commit

Permalink
Merge branch 'fix-module-template-org' of github.com:awgymer/nf-core-…
Browse files Browse the repository at this point in the history
…tools into fix-module-template-org
  • Loading branch information
awgymer committed Nov 28, 2022
2 parents 3c83495 + 1a111d7 commit a545a5a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `nextflow run <pipeline> --version` will now print the workflow version from the manifest and exit ([#1951](https://github.com/nf-core/tools/pull/1951))
- Add profile for running `docker` with the ARM chips (including Apple silicon) ([#1942](https://github.com/nf-core/tools/pull/1942) and [#2034](https://github.com/nf-core/tools/pull/2034))
- Flip execution order of parameter summary printing and parameter validation to prevent 'hiding' of parameter errors.
- Remove `CITATION.cff` file from pipeline template, to avoid that pipeline Zenodo entries reference the nf-core publication instead of the pipeline.

### Linting

Expand Down
4 changes: 2 additions & 2 deletions nf_core/components/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ def install(self, component, silent=False):
log.info(f"Use the following statement to include this {self.component_type[:-1]}:")
Console().print(
Syntax(
f"include {{ {component_name} }} from '.{os.path.join(install_folder, component)}/main'",
f"include {{ {component_name} }} from '../{Path(install_folder, component).relative_to(self.dir)}/main'",
"groovy",
theme="ansi_dark",
padding=1,
)
)
if self.component_type == "subworkflows":
subworkflow_config = os.path.join(install_folder, component, "nextflow.config")
subworkflow_config = Path(install_folder, component, "nextflow.config").relative_to(self.dir)
if os.path.isfile(subworkflow_config):
log.info("Add the following config statement to use this subworkflow:")
Console().print(
Expand Down
28 changes: 20 additions & 8 deletions nf_core/components/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ class ComponentRemove(ComponentCommand):
def __init__(self, component_type, pipeline_dir, remote_url=None, branch=None, no_pull=False):
super().__init__(component_type, pipeline_dir, remote_url, branch, no_pull)

def remove(self, component, removed_by=None, force=False):
def remove(self, component, removed_by=None, removed_components=None, force=False):
"""
Remove an already installed module/subworkflow
This command only works for modules/subworkflows that are installed from 'nf-core/modules'
Args:
component (str): Name of the component to remove
removed_by (str): Name of the component that is removing the current component
(a subworkflow name if the component is a dependency or "modules" or "subworkflows" if it is not a dependency)
removed_components (list[str]): list of components that have been removed during a recursive remove of subworkflows
force (bool): Force removal of component, even if there is still an include statement in a workflow file
Returns:
Expand All @@ -51,6 +54,9 @@ def remove(self, component, removed_by=None, force=False):
style=nf_core.utils.nfcore_question_style,
).unsafe_ask()

if removed_components is None:
removed_components = []

# Get the module/subworkflow directory
component_dir = Path(self.dir, self.component_type, repo_path, component)

Expand Down Expand Up @@ -85,7 +91,7 @@ def remove(self, component, removed_by=None, force=False):
include_stmts = self.check_if_in_include_stmts(str(removed_component_dir))
if include_stmts:
# print the include statements
log.warn(
log.warning(
f"The {self.component_type[:-1]} '{component}' is still included in the following workflow file{nf_core.utils.plural_s(include_stmts)}:"
)
console = Console()
Expand Down Expand Up @@ -120,14 +126,16 @@ def remove(self, component, removed_by=None, force=False):
if not ComponentInstall(self.dir, self.component_type, force=True).install(
component, silent=True
):
log.warn(
log.warning(
f"Could not install the {self.component_type[:-1]} '{component}', please install it manually with 'nf-core {component_type} install {component}'."
)
removed_components.append(component)
return removed
# Remove the component files of all entries removed from modules.json
removed = (
True if self.clear_component_dir(component, Path(self.dir, removed_component_dir)) or removed else False
)
removed_components.append(component)

if removed:
if self.component_type == "subworkflows":
Expand All @@ -136,10 +144,14 @@ def remove(self, component, removed_by=None, force=False):
self.component_type, component, self.modules_repo.remote_url, repo_path, {}
)
for component_name, component_type in dependent_components.items():
original_component_tyoe = self.component_type
if component_name in removed_components:
continue
original_component_type = self.component_type
self.component_type = component_type
dependency_removed = self.remove(component_name, removed_by=removed_by)
self.component_type = original_component_tyoe
dependency_removed = self.remove(
component_name, removed_by=removed_by, removed_components=removed_components
)
self.component_type = original_component_type
# remember removed dependencies
if dependency_removed:
removed_components.append(component_name.replace("/", "_"))
Expand All @@ -154,9 +166,9 @@ def remove(self, component, removed_by=None, force=False):
][component]["installed_by"]
if installed_by == self.component_type:
log.error(
f"Did not remove '{component}', because it was also manually installed. Only updated 'installed_by' in modules.json."
f"Did not remove '{component}', because it was also manually installed. Only updated 'installed_by' entry in modules.json."
)
log.info(
f"""Did not remove {self.component_type[:-1]} '{component}', because it was also installed by {', '.join(f"'{d}'" for d in installed_by)}."""
f"""Did not remove {self.component_type[:-1]} '{component}', because it was also installed by {', '.join(f"'{d}'" for d in installed_by)}. Only updated the 'installed_by' entry in modules.json."""
)
return removed
9 changes: 0 additions & 9 deletions nf_core/modules/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,15 +705,6 @@ def remove_entry(self, component_type, name, repo_url, install_dir, removed_by=N
# write the updated modules.json file
self.dump()
return True
# write the updated modules.json file
if removed_by == component_type:
log.info(
f"""Updated the 'installed_by' list for '{name}', but it is still installed, because it is required by {", ".join(f"'{d}'" for d in repo_entry[component_type][install_dir][name]['installed_by'])}."""
)
else:
log.info(
f"Removed {removed_by} from the 'installed_by' list of {name}, but it was also installed by other modules/subworkflows."
)
self.dump()
return False
else:
Expand Down
56 changes: 0 additions & 56 deletions nf_core/pipeline-template/CITATION.cff

This file was deleted.

4 changes: 2 additions & 2 deletions nf_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,13 +965,13 @@ def load_tools_config(directory="."):


def determine_base_dir(directory="."):
base_dir = Path(directory).absolute()
base_dir = start_dir = Path(directory).absolute()
while not get_first_available_path(base_dir, CONFIG_PATHS) and base_dir != base_dir.parent:
base_dir = base_dir.parent
config_fn = get_first_available_path(base_dir, CONFIG_PATHS)
if config_fn:
break
return base_dir
return directory if base_dir == start_dir else base_dir


def get_first_available_path(directory, paths):
Expand Down

0 comments on commit a545a5a

Please sign in to comment.