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

Update modules install to support version control #1116

Merged
merged 39 commits into from
Jun 23, 2021
Merged
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4765d9a
Added support for modules.json for modules install commandq
ErikDanielsson Jun 16, 2021
916911c
Merge branch 'dev' of github.com:ErikDanielsson/tools into update-mod…
ErikDanielsson Jun 16, 2021
bb62ddb
Remove redundant code
ErikDanielsson Jun 16, 2021
8af92af
Implement suggestions from code review
ErikDanielsson Jun 16, 2021
db39da3
Implement suggestions from code review
ErikDanielsson Jun 16, 2021
3351841
Apply changes from code review
ErikDanielsson Jun 16, 2021
199216f
Added API call for full git log
ErikDanielsson Jun 18, 2021
ca5cb84
Rewrote code for module.json creation
ErikDanielsson Jun 18, 2021
2c9a39e
Moved ModulesRepo to separate file
ErikDanielsson Jun 18, 2021
770b595
Resolve merge conflict
ErikDanielsson Jun 18, 2021
278fe86
Apply suggestions from code review
ErikDanielsson Jun 18, 2021
a353a43
Bug fixes after testing with rnaseq pipeline
ErikDanielsson Jun 19, 2021
a9a8d17
Added support for pagination of commits
ErikDanielsson Jun 20, 2021
e04cf4e
Update function descriptions
ErikDanielsson Jun 20, 2021
0dbe865
Implemented installation of different pipeline versions
ErikDanielsson Jun 21, 2021
ef73868
Added new flag '--latest' to install the latest version of module wit…
ErikDanielsson Jun 21, 2021
1ee746d
Update module test to handle versioning
ErikDanielsson Jun 21, 2021
116f65b
Update nf_core/modules/module_utils.py
ErikDanielsson Jun 21, 2021
bfa93e4
Update test with new flag for install command
ErikDanielsson Jun 21, 2021
db8b81c
Merge branch 'update-modules-install' of github.com:ErikDanielsson/to…
ErikDanielsson Jun 21, 2021
38b314d
Only display 'older commits' if there are any
ErikDanielsson Jun 21, 2021
cfad229
Remove redundant code
ErikDanielsson Jun 21, 2021
1a5c215
Restriced commit log to only be shown from given date
ErikDanielsson Jun 21, 2021
bc6366e
Minor fixes
ErikDanielsson Jun 22, 2021
ad7482d
Fix index of out range error
ErikDanielsson Jun 22, 2021
2a07d52
Updated CHANGELOG.md
ErikDanielsson Jun 22, 2021
ee5bbea
Fix CHANGELOG.md
ErikDanielsson Jun 22, 2021
1ea9be8
Add '--force' option
ErikDanielsson Jun 22, 2021
286724d
Remove duplicated code
ErikDanielsson Jun 22, 2021
d033d3d
Added commit SHA to message, and bug fix of '--force'
ErikDanielsson Jun 22, 2021
dabdc64
Bug fixes for '--force'
ErikDanielsson Jun 22, 2021
a9a769e
Added '--sha' flag to specify tool version
ErikDanielsson Jun 22, 2021
0c4cda5
Refactor modules install
ErikDanielsson Jun 22, 2021
89339e1
Update tests with new flags
ErikDanielsson Jun 22, 2021
5087619
Make questionary select show installed version
ErikDanielsson Jun 22, 2021
e39ff09
Apply suggestions from code review
ErikDanielsson Jun 23, 2021
2586097
Apply changes from code review
ErikDanielsson Jun 23, 2021
4dce523
Merge branch 'update-modules-install' of github.com:ErikDanielsson/to…
ErikDanielsson Jun 23, 2021
5b7c79b
Black
ErikDanielsson Jun 23, 2021
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
70 changes: 70 additions & 0 deletions nf_core/modules/pipeline_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,36 @@ def install(self, module=None):
self.modules_repo.download_gh_file(dl_filename, api_url)
log.info("Downloaded {} files to {}".format(len(files), module_dir))

# Update module.json with new module
modules_json_path = os.path.join(self.pipeline_dir, "modules.json")
with open(modules_json_path, "r") as fh:
modules_json = json.load(fh)
try:
commit_sha = self.get_module_commit_sha(module)
except SystemError as e:
log.error(e)
log.error(f"Will remove module '{module}'")
ErikDanielsson marked this conversation as resolved.
Show resolved Hide resolved
# Remove the module
try:
shutil.rmtree(module_dir)
# Try cleaning up empty parent if tool/subtool and tool/ is empty
if module.count("/") > 0:
parent_dir = os.path.dirname(module_dir)
try:
os.rmdir(parent_dir)
except OSError:
log.debug(f"Parent directory not empty: '{parent_dir}'")
else:
log.debug(f"Deleted orphan tool directory: '{parent_dir}'")
return False
except OSError as e:
log.error("Could not remove module: {}".format(e))
return False

modules_json["modules"][module] = {"git_sha": commit_sha}
with open(modules_json_path, "w") as fh:
json.dump(modules_json, fh, indent=4)

def update(self, module, force=False):
log.error("This command is not yet implemented")
pass
Expand Down Expand Up @@ -317,3 +347,43 @@ def has_valid_pipeline(self):
nf_config = os.path.join(self.pipeline_dir, "nextflow.config")
if not os.path.exists(main_nf) and not os.path.exists(nf_config):
raise UserWarning(f"Could not find a 'main.nf' or 'nextflow.config' file in '{self.pipeline_dir}'")
self.has_modules_file()
return True

def has_modules_file(self):
"""Checks whether a module.json file has been created and creates one if it is missing"""
modules_json_path = os.path.join(self.pipeline_dir, "modules.json")
if not os.path.exists(modules_json_path):
log.info("Creating missing 'modules.json' file.")
pipeline_config = nf_core.utils.fetch_wf_config(self.pipeline_dir)
pipeline_name = pipeline_config["manifest.name"]
pipeline_url = pipeline_config["manifest.homePage"]
modules_json = {"name": pipeline_name.strip("'"), "homePage": pipeline_url.strip("'"), "modules": {}}
module_names = [
path.replace(f"{self.pipeline_dir}/modules/nf-core/software/", "")
for path in glob.glob(f"{self.pipeline_dir}/modules/nf-core/software/*")
]
for module_name in module_names:
try:
commit_sha = self.get_module_commit_sha(module_name)
modules_json["modules"][module_name] = {"git_sha": commit_sha}
except SystemError as e:
log.error(e)
log.error("Will not create 'modules.json' file")
KevinMenden marked this conversation as resolved.
Show resolved Hide resolved
sys.exit(1)
modules_json_path = os.path.join(self.pipeline_dir, "modules.json")
ErikDanielsson marked this conversation as resolved.
Show resolved Hide resolved
with open(modules_json_path, "w") as fh:
json.dump(modules_json, fh, indent=4)

def get_module_commit_sha(self, module_name):
"""Fetches the latests commit SHA for the requested module"""
api_url = f'https://api.github.com/repos/nf-core/modules/commits/master?q={{path="software/{module_name}"}}'
response = requests.get(api_url, auth=nf_core.utils.github_api_auto_auth())
if response.status_code == 200:
json_response = response.json()
return json_response["sha"]
elif response.status_code == 404:
log.error(f"Module '{module_name}' not found in 'nf-core/modules/'\n{api_url}")
sys.exit(1)
else:
raise SystemError(f"Unable to fetch commit SHA for module {module_name}")