gstlal
1.13.0
Toggle main menu visibility
Loading...
Searching...
No Matches
python
workflows
__init__.py
1
# Copyright (C) 2021 Patrick Godwin (patrick.godwin@ligo.org)
2
#
3
# This program is free software; you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License as published by the
5
# Free Software Foundation; either version 2 of the License, or (at your
6
# option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11
# Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License along
14
# with this program; if not, write to the Free Software Foundation, Inc.,
15
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17
import
os
18
from
typing
import
Optional
19
20
import
jinja2
21
22
from
gstlal.config
import
Config
23
24
25
def
write_makefile(config: Config, template: str, config_filename=
"config.yml"
, path: Optional[str] =
None
, **kwargs) ->
None
:
26
"""Generate a Makefile based on a configuration and template.
27
28
Args:
29
config:
30
Config, a configuration to use to fill in Makefile template
31
template:
32
str, name of the Makefile template
33
path:
34
str, default $PWD, the path to write the Makefile to
35
**kwargs:
36
any extra key-value pairs used for the template
37
38
"""
39
if
not
path:
40
path = os.getcwd()
41
42
template_loader = jinja2.PackageLoader(
"gstlal.workflows"
,
"templates"
)
43
template_env = jinja2.Environment(loader=template_loader, trim_blocks=
True
, lstrip_blocks=
True
)
44
template = template_env.get_template(template)
45
46
makefile = template.render(config=config, **kwargs)
47
makefile = makefile.replace(
"config.yml"
, config_filename)
48
with
open(os.path.join(path,
"Makefile"
),
"w"
)
as
f:
49
f.write(makefile)
Generated by
1.17.0