From 26bb482918d8ed8e67cb5ba3ce6554eb37152e60 Mon Sep 17 00:00:00 2001 From: Christopher Tomkins-Tinch Date: Tue, 28 Mar 2023 15:20:08 -0400 Subject: [PATCH 1/3] attempt at resolving existing-repo collisions only clone viral-core if a directory for it does not exist, otherwise git pull the latest. Also, only add the viral-core containing directory (parent dir) to the Python sys.path [module search] list if it is not already present in the list. --- docs/conf.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index a656dd4a..f552d8dc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -46,9 +46,17 @@ def _git_version(): # -- Obtain upstream viral-core module: this is super hacky and not pinned to any version def _get_viral_core(): - cmd = ['git', 'clone', '--depth=1', 'https://github.com/broadinstitute/viral-core.git'] - subprocess.check_call(cmd) - sys.path.insert(0, os.path.dirname(os.path.abspath('viral-core'))) + viral_core_dir = os.path.abspath('viral-core') + if not os.path.isdir(viral_core_dir): + cmd = ['git', 'clone', '--depth=1', 'https://github.com/broadinstitute/viral-core.git'] + subprocess.check_call(cmd) + else: # else fetch latest + cmd = ['git', '-C', viral_core_dir, 'pull', '--depth=1', 'https://github.com/broadinstitute/viral-core.git'] + subprocess.check_call(cmd) + + viral_core_parent_dir = os.path.dirname(os.path.abspath('viral-core')) + if viral_core_parent_dir not in sys.path: + sys.path.insert(0, viral_core_parent_dir) _get_viral_core() From 7179ecafab75a67a49e3a998a0caf7fce6844aa6 Mon Sep 17 00:00:00 2001 From: Christopher Tomkins-Tinch Date: Tue, 28 Mar 2023 15:55:24 -0400 Subject: [PATCH 2/3] move subprocess import --- docs/conf.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f552d8dc..c1170aaf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,6 +15,7 @@ import sys import os +import subprocess # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -30,8 +31,6 @@ sys.modules[mod_name] = mock.Mock() # -- Obtain GIT version -- -import subprocess - def _git_version(): cmd = ['git', 'describe', '--tags', '--always'] # omit "--dirty" from doc build @@ -39,8 +38,6 @@ def _git_version(): if type(out) != str: out = out.decode('utf-8') return out.strip() - - __version__ = _git_version() From 140f3d00c170fcd04486fbbdeda608281c386cbb Mon Sep 17 00:00:00 2001 From: Christopher Tomkins-Tinch Date: Tue, 28 Mar 2023 16:18:25 -0400 Subject: [PATCH 3/3] also check for presence of assembly.py before waiving clone of viral-core --- docs/conf.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index c1170aaf..477f12cf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -44,12 +44,17 @@ def _git_version(): # -- Obtain upstream viral-core module: this is super hacky and not pinned to any version def _get_viral_core(): viral_core_dir = os.path.abspath('viral-core') - if not os.path.isdir(viral_core_dir): - cmd = ['git', 'clone', '--depth=1', 'https://github.com/broadinstitute/viral-core.git'] - subprocess.check_call(cmd) - else: # else fetch latest + + # if the viral-core dir and its file exist, pull the latest + if os.path.exists(os.path.join(viral_core_dir,"assembly.py")): # ToDo: check if empty instead cmd = ['git', '-C', viral_core_dir, 'pull', '--depth=1', 'https://github.com/broadinstitute/viral-core.git'] subprocess.check_call(cmd) + # otherwise clone viral-core, removing the viral-core directory if present + else: + if os.path.isdir(viral_core_dir): + os.remove(viral_core_dir, missing_ok=True) + cmd = ['git', 'clone', '--depth=1', 'https://github.com/broadinstitute/viral-core.git'] + subprocess.check_call(cmd) viral_core_parent_dir = os.path.dirname(os.path.abspath('viral-core')) if viral_core_parent_dir not in sys.path: