Skip to content
Snippets Groups Projects
Commit 66f7c9e9 authored by mjbonifa's avatar mjbonifa
Browse files

tidied phen init

parent dd623973
Branches
Tags
No related merge requests found
...@@ -42,9 +42,12 @@ class PhenValidationException(Exception): ...@@ -42,9 +42,12 @@ class PhenValidationException(Exception):
self.validation_errors = validation_errors self.validation_errors = validation_errors
def construct_git_url(remote_url): def construct_git_url(remote_url):
"""Constructs a git url for github or gitlab including a PAT token environment variable"""
# check the url # check the url
parsed_url = urlparse(remote_url) parsed_url = urlparse(remote_url)
# if github in the URL otherwise assume it's gitlab, if we want to use others such as codeberg we'd
# need to update this function if the URL scheme is different.
if "github.com" in parsed_url.netloc: if "github.com" in parsed_url.netloc:
# get GitHub PAT from environment variable # get GitHub PAT from environment variable
auth = os.getenv("ACMC_GITHUB_PAT") auth = os.getenv("ACMC_GITHUB_PAT")
...@@ -78,8 +81,11 @@ def init(phen_dir, remote_url): ...@@ -78,8 +81,11 @@ def init(phen_dir, remote_url):
else: else:
configure=True configure=True
# configure phen directories if not configure:
if configure: print(f"Exiting, phenotype not initiatised")
return
# Initialise repo from local or remote
repo = None repo = None
# if remote then clone the repo otherwise init a local repo # if remote then clone the repo otherwise init a local repo
if remote_url != None: if remote_url != None:
...@@ -127,14 +133,18 @@ def init(phen_dir, remote_url): ...@@ -127,14 +133,18 @@ def init(phen_dir, remote_url):
# if the phen path does not contain the config file then initialise the phen type # if the phen path does not contain the config file then initialise the phen type
config_path = phen_path / CONFIG_FILE config_path = phen_path / CONFIG_FILE
if not config_path.exists(): if config_path.exists():
print("Creating configuration files") print(f"Phenotype configuration files already exist")
return
print("Creating phen directory structure and config files")
# create codes directory # create codes directory
codes_path = phen_path / CODES_DIR codes_path = phen_path / CODES_DIR
codes_path.mkdir(exist_ok=True) codes_path.mkdir(exist_ok=True)
keep_path = codes_path / '.gitkeep' keep_path = codes_path / '.gitkeep'
keep_path.touch(exist_ok=True) keep_path.touch(exist_ok=True)
# create maps directory
# create concept sets directory
output_path = phen_path / OUTPUT_DIR output_path = phen_path / OUTPUT_DIR
output_path.mkdir(exist_ok=True) output_path.mkdir(exist_ok=True)
keep_path = output_path / '.gitkeep' keep_path = output_path / '.gitkeep'
...@@ -164,18 +174,13 @@ def init(phen_dir, remote_url): ...@@ -164,18 +174,13 @@ def init(phen_dir, remote_url):
with open(config_path, "w", encoding="utf-8") as f: with open(config_path, "w", encoding="utf-8") as f:
json.dump(config, f, indent=4) json.dump(config, f, indent=4)
# add to repo and commit # add to git repo and commit
repo.git.add(codes_path) repo.git.add(codes_path)
repo.git.add(output_path) repo.git.add(output_path)
repo.git.add(all=True) repo.git.add(all=True)
msg = "initialised the phen git repo." repo.index.commit("initialised the phen git repo.")
repo.index.commit(msg)
print(msg)
else:
print(f"Phenotype configuration files already exist")
print(f"Phenotype initialised") print(f"Phenotype initialised")
else:
print(f"Phenotype not initiatised")
def validate(phen_dir): def validate(phen_dir):
"""Validates the phenotype directory is a git repo with standard structure""" """Validates the phenotype directory is a git repo with standard structure"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment