Skip to content

Commit

Permalink
Build parsetab.dat generation to build_py step instead of post-install
Browse files Browse the repository at this point in the history
- Fixes #3
  • Loading branch information
virtuald committed Oct 4, 2015
1 parent 82b01cc commit d94bc26
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,6 +5,7 @@ __pycache__
.coverage
*.egg-info
*.egg
*.eggs

.project
.pydevproject
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
0.1.12 (2015-10-04)
-------------------
* Move parsetab.dat to build_py step instead of post-install

0.1.11 (2015-04-24)
-------------------
* ply version requirement is now == 3.4
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Expand Up @@ -4,5 +4,7 @@ include README.rst
include LICENSE
include CHANGELOG.md

include src/hcl/parsetab.dat

recursive-include tests *.py *.hcl *.json *.sh

29 changes: 21 additions & 8 deletions setup.py
Expand Up @@ -6,27 +6,38 @@
from distutils.core import setup

try:
from setuptools.command.install import install as _install
from setuptools.command.build_py import build_py as _build_py
except ImportError:
from distutils.command.install import install as _install
from distutils.command.build_py import build_py as _build_py

import sys
import subprocess

setup_dir = abspath(dirname(__file__))
version_file = join(setup_dir, 'src', 'hcl', 'version.py')

def _post_install():
def _pre_install():
'''Initialize the parse table at install time'''

# Generate the parsetab.dat file at setup time
dat = join(setup_dir, 'src', 'hcl', 'parsetab.dat')
if exists(dat):
os.unlink(dat)

sys.path.insert(0, join(setup_dir, 'src'))

import hcl
from hcl.parser import HclParser
parser = HclParser()

print('exists', dat)


class install(_install):
class build_py(_build_py):
def run(self):
_install.run(self)
self.execute(_post_install, (), msg="Generating parse table...")
self.execute(_pre_install, (), msg="Generating parse table...")
_build_py.run(self)


# Automatically generate a version.py based on the git version
if exists(join(setup_dir, '.git')):
Expand All @@ -49,7 +60,7 @@ def run(self):
with open(version_file, 'w') as fp:
fp.write("# Autogenerated by setup.py\n__version__ = '{0}'".format(v))

with open(join(dirname(__file__), 'README.rst'), 'r') as readme_file:
with open(join(setup_dir, 'README.rst'), 'r') as readme_file:
long_description = readme_file.read()

with open(version_file) as fp:
Expand All @@ -65,11 +76,13 @@ def run(self):
author_email='dustin@virtualroadside.com',
url='https://github.com/virtuald/pyhcl',
package_dir={'': 'src'},
package_data={'hcl': ['src/hcl/parsetab.dat']},
packages=['hcl'],
scripts=["scripts/hcltool"],
include_package_data=True,
setup_requires=install_requires,
install_requires=install_requires,
cmdclass={'install': install},
cmdclass={'build_py': build_py},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
Expand Down

0 comments on commit d94bc26

Please sign in to comment.