-
Notifications
You must be signed in to change notification settings - Fork 18
/
setup.py
46 lines (36 loc) · 1.59 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
import logging
import os
from shutil import which
from subprocess import PIPE, STDOUT # nosec B404
from subprocess import run as sub_run
from setuptools import setup
from setuptools.command.build_py import build_py
class BuildPyCommand(build_py):
"""Custom build command to pyccelise _kernels files in the build directory."""
# Rewrite the build_module function to copy each module in the build
# repository and pyccelise the modules ending with _kernels
def build_module(self, module, module_file, package):
outfile, copied = super().build_module(module, module_file, package)
# This part check if the module is pyccelisable and pyccelise it in
# case
if module.endswith('_kernels'):
self.announce(f"\nPyccelising [{module}] ...", level=logging.INFO)
pyccel = sub_run([which('pyccel'), outfile, '--language', 'fortran', '--openmp'],
stdout=PIPE, stderr=STDOUT,
text=True, shell=False, check=True) # nosec B603
self.announce(pyccel.stdout, level=logging.INFO)
return outfile, copied
def run(self):
super().run()
# Remove __pyccel__ directories
sub_run([which('pyccel-clean'), self.build_lib], shell=False, check=True) # nosec B603, B607
# Remove useless .lock files
for path, subdirs, files in os.walk(self.build_lib):
for name in files:
if name == '.lock_acquisition.lock':
os.remove(os.path.join(path, name))
setup(
cmdclass={
'build_py': BuildPyCommand,
},
)