Skip to content

Commit a6cb09c

Browse files
committed
added cache files to package and building during setup
1 parent 9d2ea86 commit a6cb09c

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ include README.rst
22
include LICENSE
33
include tox.ini
44
recursive-include osaca/data/ *.yml
5+
recursive-include osaca/data/ *.pickle
6+
include osaca/data/_build_cache.py
57
include examples/*
68
recursive-include tests *.py *.out
79
recursive-include tests/testfiles/ *

osaca/data/_build_cache.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
from glob import glob
3+
import os.path
4+
import sys
5+
sys.path[0:0] = ['../..']
6+
7+
from osaca.semantics.hw_model import MachineModel
8+
9+
print('Building cache: ', end='')
10+
sys.stdout.flush()
11+
12+
# Iterating architectures
13+
for f in glob(os.path.join(os.path.dirname(__file__), '*.yml')):
14+
MachineModel(path_to_yaml=f)
15+
print('.', end='')
16+
sys.stdout.flush()
17+
18+
# Iterating ISAs
19+
for f in glob(os.path.join(os.path.dirname(__file__), 'isa/*.yml')):
20+
MachineModel(path_to_yaml=f)
21+
print('+', end='')
22+
sys.stdout.flush()
23+
24+
print()

setup.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
# Always prefer setuptools over distutils
44
from setuptools import setup, find_packages
5+
from setuptools.command.install import install as _install
6+
from setuptools.command.sdist import sdist as _sdist
57
# To use a consistent encoding
68
from codecs import open
79
import os
810
import io
911
import re
12+
import sys
1013

1114
here = os.path.abspath(os.path.dirname(__file__))
1215

@@ -27,6 +30,27 @@ def find_version(*file_paths):
2730
raise RuntimeError("Unable to find version string.")
2831

2932

33+
def _run_build_cache(dir):
34+
from subprocess import check_call
35+
# This is run inside the install staging directory (that had no .pyc files)
36+
# We don't want to generate any.
37+
# https://github.com/eliben/pycparser/pull/135
38+
check_call([sys.executable, '-B', '_build_cache.py'],
39+
cwd=os.path.join(dir, 'osaca', 'data'))
40+
41+
42+
class install(_install):
43+
def run(self):
44+
_install.run(self)
45+
self.execute(_run_build_cache, (self.install_lib,), msg="Build ISA and architecture cache")
46+
47+
48+
class sdist(_sdist):
49+
def make_release_tree(self, basedir, files):
50+
_sdist.make_release_tree(self, basedir, files)
51+
self.execute(_run_build_cache, (basedir,), msg="Build ISA and architecture cache")
52+
53+
3054
# Get the long description from the README file
3155
with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
3256
long_description = f.read()
@@ -124,4 +148,7 @@ def find_version(*file_paths):
124148
'osaca=osaca.osaca:main',
125149
],
126150
},
151+
152+
# Overwriting install and sdist to enforce cache distribution with package
153+
cmdclass={'install': install, 'sdist': sdist},
127154
)

0 commit comments

Comments
 (0)