12
12
import logging
13
13
import hashlib
14
14
from pathlib import Path
15
- from distutils import filelist , log
15
+ from distutils import filelist
16
+
17
+ # Determine default staging area, used in help
18
+ default_staging = "/tmp/{0}-lcdb-wf-staging" .format (os .getenv ('USER' ))
19
+
20
+ usage = f"""
21
+ This script assists in the deployment of relevant code from the lcdb-wf
22
+ repository to a new deployment directory for running an analysis. It is
23
+ intended to be run in a standalone fashion such that with just the script you
24
+ can download and deploy a specified version of the workflows.
25
+
26
+ For example, the following command will clone the GitHub repo to { default_staging } ,
27
+ check out the v9.999 branch, copy the files needed for RNA-seq over to the
28
+ "my_analysis_dir" directory, store a read-only file .lcdb-wf-deployment.yaml
29
+ with the metadata of the repo used for cloning, and build the conda
30
+ environments within "my_analysis_dir":
31
+
32
+ ./deploy.py \\
33
+ --clone \\
34
+ --dest my_analysis_dir \\
35
+ --flavor rnaseq \\
36
+ --build-envs \\
37
+ --branch v9.999
38
+
39
+ Compared to directly cloning the repo, this results in a cleaner deployment
40
+ directory that does not have various test infrastructure or workflows not
41
+ relevant to the project.
42
+ """
16
43
17
44
logging .basicConfig (
18
45
format = "%(asctime)s [%(module)s] %(message)s" ,
31
58
RESET = "\x1b [0m"
32
59
33
60
34
- # Determine default staging area
35
- default_staging = "/tmp/{0}-lcdb-wf-staging" .format (os .getenv ('USER' ))
36
-
37
-
38
61
def debug (s ):
39
62
logging .debug (GRAY + s + RESET )
40
63
@@ -51,28 +74,11 @@ def error(s):
51
74
logging .error (RED + s + RESET )
52
75
53
76
77
+ def write_include_file (source , flavor = 'all' ):
54
78
55
- usage = f"""
56
- This script assists in the deployment of relevant code from the lcdb-wf
57
- repository to a new deployment directory for running an analysis.
58
-
59
- For example, the following command will clone the GitHub repo to { default_staging } ,
60
- check out the v9.999 branch, copy the files needed for RNA-seq over to the
61
- "my_analysis_dir" directory, store a read-only file .lcdb-wf-deployment.yaml
62
- with the metadata of the repo used for cloning, and build the conda
63
- environments within "my_analysis_dir":
64
-
65
- ./deploy.py \\
66
- --clone \\
67
- --dest my_analysis_dir \\
68
- --flavor rnaseq \\
69
- --build-envs \\
70
- --branch v9.999
71
-
72
- """
73
-
74
-
75
- def write_include_file (flavor = None ):
79
+ # Patterns follow that of MANIFEST.in
80
+ # (https://packaging.python.org/en/latest/guides/using-manifest-in/),
81
+ # and distutils.filelist is used below to parse them.
76
82
77
83
PATTERN_DICT = {
78
84
'rnaseq' : [
@@ -107,17 +113,14 @@ def write_include_file(flavor=None):
107
113
}
108
114
109
115
patterns = []
110
- if flavor is None or 'rnaseq' :
116
+ if flavor in ( 'full' , 'rnaseq' ) :
111
117
patterns .extend (PATTERN_DICT ['rnaseq' ])
112
- if flavor is None or 'chipseq' :
118
+ if flavor in ( 'full' , 'chipseq' ) :
113
119
patterns .extend (PATTERN_DICT ['chipseq' ])
114
- if flavor is None or 'full' :
120
+ if flavor == 'full' :
115
121
patterns .extend (PATTERN_DICT ['full' ])
116
122
patterns .extend (PATTERN_DICT ['all' ])
117
123
118
- HERE = Path (__file__ ).resolve ().parent
119
- os .chdir (HERE )
120
-
121
124
def fastwalk (path ):
122
125
"""
123
126
Find all files recursively, but short-circuit if we get to a conda env to
@@ -134,7 +137,7 @@ def fastwalk(path):
134
137
yield os .path .join (root , f ).replace (path + '/' , '' )
135
138
136
139
f = filelist .FileList ()
137
- f .allfiles = list (fastwalk (str ( HERE ) ))
140
+ f .allfiles = list (fastwalk (source ))
138
141
for pattern in patterns :
139
142
f .process_template_line (pattern )
140
143
f .sort ()
@@ -144,7 +147,7 @@ def fastwalk(path):
144
147
sp .check_output (
145
148
["git" , "ls-tree" , "-r" , "HEAD" , "--name-only" ],
146
149
universal_newlines = True ,
147
- cwd = str ( HERE ) ,
150
+ cwd = source ,
148
151
).splitlines (False ),
149
152
)
150
153
@@ -153,6 +156,7 @@ def fastwalk(path):
153
156
with open (include , 'w' ) as fout :
154
157
fout .write ('\n \n ' )
155
158
fout .write ('\n ' .join (to_transfer ))
159
+
156
160
return include
157
161
158
162
@@ -341,7 +345,6 @@ def build_envs(dest, conda_frontend="mamba"):
341
345
342
346
ap .add_argument (
343
347
"--staging" ,
344
- default = default_staging ,
345
348
help = """Only used when --clone is specified. Clone the main git repo to
346
349
this directory and do a diff on the deploy.py script found there to
347
350
ensure this one is up-to-date, and if so then proceed using the new clone as the source.
@@ -384,12 +387,14 @@ def build_envs(dest, conda_frontend="mamba"):
384
387
print ("ERROR: --staging was specified but --clone was not. Did you want to use --clone?" , file = sys .stderr )
385
388
sys .exit (1 )
386
389
if args .clone :
387
- source = args .staging
390
+ if args .staging is None :
391
+ args .staging = default_staging
392
+ source = os .path .abspath (args .staging )
388
393
clone_repo (args .staging , args .branch , mismatch_ok = args .mismatch_ok )
389
394
else :
390
395
source = Path (__file__ ).parent .resolve ()
391
396
392
- include = write_include_file (source )
397
+ include = write_include_file (source , flavor )
393
398
rsync (include , source , dest , args .rsync_args )
394
399
deployment_json (source , dest )
395
400
0 commit comments