Skip to content

Commit 4d2bb91

Browse files
authored
Merge pull request #51 from NNPDF/folder_prefix
Add folder_prefix option
2 parents 44b1ce7 + eaea8c6 commit 4d2bb91

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/reportengine/app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ def argparser(self):
192192
parallel.add_argument('--no-parallel', dest='parallel',
193193
action='store_false')
194194

195+
parser.add_argument(
196+
'--folder-prefix',
197+
action='store_true',
198+
help="add a prefix derived from the runcard name to output resources.",
199+
)
200+
195201
parser.add_argument('-h', '--help', action=ArgumentHelpAction,
196202
app=self)
197203

src/reportengine/environment.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Environment:
3333
def __init__(self, *, output=None, formats=('pdf',),
3434
default_figure_format=None, loglevel=logging.DEBUG,
3535
config_yml = None,
36+
folder_prefix=False,
3637
**kwargs):
3738
if output:
3839
self.output_path = pathlib.Path(output).absolute()
@@ -43,6 +44,11 @@ def __init__(self, *, output=None, formats=('pdf',),
4344
self.loglevel = loglevel
4445
self.extra_args = kwargs
4546
self.config_yml = config_yml
47+
if folder_prefix and config_yml:
48+
self.filename_prefix = pathlib.Path(config_yml).stem
49+
else:
50+
self.filename_prefix = None
51+
4652

4753
@property
4854
def figure_formats(self):
@@ -116,7 +122,7 @@ def ns_dump_description(cls):
116122
return dict(
117123
output_path = "Folder where the results are to be written.",
118124
config_rel_path = cls.config_rel_path.__doc__,
119-
125+
filename_prefix = "Prefix prepended to filenames",
120126
)
121127

122128
def ns_dump(self):

src/reportengine/formattingtools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def get_nice_name(ns, nsspec, suffix=None):
2727
(see the ``namespaces`` documentation for more details)"""
2828
parts = []
2929
currspec = []
30+
prefix = ns.get("filename_prefix", None)
31+
if prefix:
32+
parts.append(prefix)
3033
currns = ns
3134
for ele in nsspec:
3235
currspec.append(ele)

0 commit comments

Comments
 (0)