11import argparse
22import os
3+ from importlib .metadata import PackageNotFoundError , version
34
45import logmuse
56from ubiquerg import VersionInHelpParser
67
7- from geofetch ._version import __version__
88
9-
10- def _safe_echo (var ):
11- """Returns an environment variable if it exists, or an empty string if not"""
9+ def _safe_echo (var : str ) -> str :
10+ """Return an environment variable if it exists, or an empty string if not."""
1211 return os .getenv (var , "" )
1312
1413
15- def _parse_cmdl (cmdl ):
16- """
17- parser
18- """
14+ def _get_version () -> str :
15+ """Return the package version, or 'unknown' if not installed."""
16+ try :
17+ return version ("geofetch" )
18+ except PackageNotFoundError :
19+ return "unknown"
20+
21+
22+ def _parse_cmdl (cmdl : list [str ]) -> argparse .Namespace :
23+ """Parse command-line arguments for geofetch."""
1924 parser = VersionInHelpParser (
2025 description = "Automatic GEO and SRA data downloader" ,
2126 usage = """geofetch [<args>]
@@ -27,7 +32,7 @@ def _parse_cmdl(cmdl):
2732 geofetch -i GSE67303 --processed --geo-folder <folder> -m <folder>
2833
2934""" ,
30- version = __version__ ,
35+ version = _get_version () ,
3136 )
3237
3338 processed_group = parser .add_argument_group ("processed" )
@@ -54,7 +59,7 @@ def _parse_cmdl(cmdl):
5459 default = _safe_echo ("SRAMETA" ),
5560 help = "Specify a parent folder location to store metadata. "
5661 "The project name will be added as a subfolder "
57- "[ Default: $SRAMETA:" + _safe_echo ("SRAMETA" ) + "] " ,
62+ "( Default: $SRAMETA:" + _safe_echo ("SRAMETA" ) + ") " ,
5863 )
5964
6065 parser .add_argument (
@@ -87,7 +92,7 @@ def _parse_cmdl(cmdl):
8792 default = None ,
8893 help = "Optional: Specify one or more filepaths to SAMPLES pipeline interface yaml files. "
8994 "These will be added to the project config file to make it immediately "
90- "compatible with looper. [ Default: null] " ,
95+ "compatible with looper. ( Default: null) " ,
9196 )
9297
9398 # Optional
@@ -96,7 +101,7 @@ def _parse_cmdl(cmdl):
96101 default = None ,
97102 help = "Optional: Specify one or more filepaths to PROJECT pipeline interface yaml files. "
98103 "These will be added to the project config file to make it immediately "
99- "compatible with looper. [ Default: null] " ,
104+ "compatible with looper. ( Default: null) " ,
100105 )
101106 # Optional
102107 parser .add_argument (
@@ -111,7 +116,7 @@ def _parse_cmdl(cmdl):
111116 "--skip" ,
112117 default = 0 ,
113118 type = int ,
114- help = "Skip some accessions. [ Default: no skip] ." ,
119+ help = "Skip some accessions. ( Default: no skip) ." ,
115120 )
116121
117122 parser .add_argument (
@@ -132,15 +137,15 @@ def _parse_cmdl(cmdl):
132137 type = int ,
133138 default = 50 ,
134139 help = "Optional: Limit of the number of the constant sample characters "
135- "that should not be in project yaml. [ Default: 50] " ,
140+ "that should not be in project yaml. ( Default: 50) " ,
136141 )
137142
138143 parser .add_argument (
139144 "--const-limit-discard" ,
140145 type = int ,
141146 default = 1000 ,
142147 help = "Optional: Limit of the number of the constant sample characters "
143- "that should not be discarded [ Default: 250] " ,
148+ "that should not be discarded ( Default: 250) " ,
144149 )
145150
146151 parser .add_argument (
@@ -149,7 +154,7 @@ def _parse_cmdl(cmdl):
149154 default = 500 ,
150155 help = "Optional: Limit of the number of sample characters."
151156 "Any attribute with more than X characters will truncate to the first X,"
152- " where X is a number of characters [ Default: 500] " ,
157+ " where X is a number of characters ( Default: 500) " ,
153158 )
154159
155160 parser .add_argument (
@@ -163,7 +168,7 @@ def _parse_cmdl(cmdl):
163168 type = str ,
164169 default = "1GB" ,
165170 help = """Optional: Max size of soft file.
166- [ Default: 1GB] .
171+ ( Default: 1GB) .
167172 Supported input formats : 12B, 12KB, 12MB, 12GB. """ ,
168173 )
169174
@@ -178,7 +183,7 @@ def _parse_cmdl(cmdl):
178183 "--processed" ,
179184 default = False ,
180185 action = "store_true" ,
181- help = "Download processed data [ Default: download raw data] ." ,
186+ help = "Download processed data ( Default: download raw data) ." ,
182187 )
183188
184189 processed_group .add_argument (
@@ -190,13 +195,13 @@ def _parse_cmdl(cmdl):
190195 " to retrieve processed data, which may be attached to the"
191196 " collective series entity, or to individual samples. "
192197 "Allowable values are: samples, series or both (all). "
193- "Ignored unless 'processed' flag is set. [ Default: samples] " ,
198+ "Ignored unless 'processed' flag is set. ( Default: samples) " ,
194199 )
195200
196201 processed_group .add_argument (
197202 "--filter" ,
198203 default = None ,
199- help = "Optional: Filter regex for processed filenames [ Default: None] ."
204+ help = "Optional: Filter regex for processed filenames ( Default: None) ."
200205 "Ignored unless 'processed' flag is set." ,
201206 )
202207
@@ -205,7 +210,7 @@ def _parse_cmdl(cmdl):
205210 dest = "filter_size" ,
206211 default = None ,
207212 help = """Optional: Filter size for processed files
208- that are stored as sample repository [ Default: None] .
213+ that are stored as sample repository ( Default: None) .
209214 Works only for sample data.
210215 Supported input formats : 12B, 12KB, 12MB, 12GB.
211216 Ignored unless 'processed' flag is set.""" ,
@@ -217,7 +222,7 @@ def _parse_cmdl(cmdl):
217222 default = _safe_echo ("GEODATA" ),
218223 help = "Optional: Specify a location to store processed GEO files."
219224 " Ignored unless 'processed' flag is set."
220- "[ Default: $GEODATA:" + _safe_echo ("GEODATA" ) + "] " ,
225+ "( Default: $GEODATA:" + _safe_echo ("GEODATA" ) + ") " ,
221226 )
222227
223228 raw_group .add_argument (
@@ -238,7 +243,9 @@ def _parse_cmdl(cmdl):
238243 default = _safe_echo ("SRABAM" ),
239244 help = """Optional: Specify folder of bam files. Geofetch will not
240245 download sra files when corresponding bam files already exist.
241- [Default: $SRABAM:""" + _safe_echo ("SRABAM" ) + "]" ,
246+ (Default: $SRABAM:"""
247+ + _safe_echo ("SRABAM" )
248+ + ")" ,
242249 )
243250
244251 raw_group .add_argument (
@@ -248,7 +255,9 @@ def _parse_cmdl(cmdl):
248255 default = _safe_echo ("SRAFQ" ),
249256 help = """Optional: Specify folder of fastq files. Geofetch will not
250257 download sra files when corresponding fastq files already exist.
251- [Default: $SRAFQ:""" + _safe_echo ("SRAFQ" ) + "]" ,
258+ (Default: $SRAFQ:"""
259+ + _safe_echo ("SRAFQ" )
260+ + ")" ,
252261 )
253262
254263 # Deprecated; these are for bam conversion which now happens in sra_convert
@@ -260,7 +269,7 @@ def _parse_cmdl(cmdl):
260269 default = _safe_echo ("SRARAW" ),
261270 help = argparse .SUPPRESS ,
262271 # help="Optional: Specify a location to store sra files "
263- # "[ Default: $SRARAW:" + safe_echo("SRARAW") + "] "
272+ # "( Default: $SRARAW:" + safe_echo("SRARAW") + ") "
264273 )
265274 raw_group .add_argument (
266275 "--bam-conversion" ,
@@ -274,7 +283,7 @@ def _parse_cmdl(cmdl):
274283 dest = "picard_path" ,
275284 default = _safe_echo ("PICARD" ),
276285 # help="Specify a path to the picard jar, if you want to convert "
277- # "fastq to bam [ Default: $PICARD:" + safe_echo("PICARD") + "] ",
286+ # "fastq to bam ( Default: $PICARD:" + safe_echo("PICARD") + ") ",
278287 help = argparse .SUPPRESS ,
279288 )
280289
0 commit comments