-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
64 lines (51 loc) · 2.09 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import configparser
import json
import os
import setuptools
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.sdist import sdist as _sdist
class sdist(_sdist):
"""An extension to the `sdist` command that generates a `pyproject.toml`.
"""
def run(self):
# build `pyproject.toml` from `setup.cfg`
c = configparser.ConfigParser()
c.add_section("build-system")
c.set("build-system", "requires", str(self.distribution.setup_requires))
c.set("build-system", 'build-backend', '"setuptools.build_meta"')
with open("pyproject.toml", "w") as pyproject:
c.write(pyproject)
# run the rest of the packaging
_sdist.run(self)
class build_py(_build_py):
def run(self):
# generate `smatrix/templates/header.sh.j2` using sbatch CLI data
in_ = os.path.join(__file__, "..", "smatrix", "data", "sbatch.json")
with open(os.path.realpath(in_)) as f:
cli = json.load(f)
out = os.path.join(__file__, "..", "smatrix", "templates", "header.sh.j2")
with open(os.path.realpath(out), "w") as f:
f.write("#!/bin/sh\n")
for option in (option for section in cli for option in section['options']):
if not option.get("transmit", True):
continue
kebab, snake = option["name"], option["name"].replace("-", "_")
if "meta" in option:
f.write("{{%- if not args.{} is none %}}\n".format(snake))
f.write("#SBATCH --{} {{{{ args.{} }}}}\n".format(kebab, snake))
f.write("{%- endif %}\n")
else:
f.write("{{%- if args.{} %}}\n".format(snake))
f.write("#SBATCH --{}\n".format(kebab))
f.write("{%- endif %}\n")
# run the rest of the build
_build_py.run(self)
if __name__ == "__main__":
setuptools.setup(
cmdclass={
"build_py": build_py,
"sdist": sdist,
},
)