Skip to content

Commit

Permalink
generate .pyc files from .hy files on install
Browse files Browse the repository at this point in the history
  • Loading branch information
scauligi authored and Kodiologist committed Jun 7, 2022
1 parent bdd5d1f commit c84fb12
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist
build/
/.cache
/.pytest_cache
/.eggs
1 change: 1 addition & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Bug Fixes
in string and bytes literals.
* ``defmacro`` no longer allows arguments after ``#* args``
* Tracebacks from code parsed with `hy.read` now show source positions.
* Hy now pre-compiles .hy files during setup/installation.

New Features
------------------------------
Expand Down
39 changes: 30 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fastentrypoints # Monkey-patches setuptools.
from get_version import __version__
from setuptools import find_packages, setup
from setuptools.command.install import install

os.chdir(os.path.split(os.path.abspath(__file__))[0])

Expand All @@ -14,14 +15,34 @@
make things work nicer, and lets Python and the Hy lisp variant play
nice together. """


class install(install):
def run(self):
super().run()
import py_compile
from glob import glob

import hy # for compile hooks

for path in glob(os.path.join(self.install_lib, "**/*.hy"), recursive=True):
py_compile.compile(
path, invalidation_mode=py_compile.PycInvalidationMode.CHECKED_HASH
)


# both setup_requires and install_requires
# since we need to compile .hy files during setup
requires = [
"funcparserlib ~= 1.0",
"colorama",
'astor>=0.8 ; python_version < "3.9"',
]

setup(
name=PKG,
version=__version__,
install_requires=[
"funcparserlib ~= 1.0",
"colorama",
'astor>=0.8 ; python_version < "3.9"',
],
setup_requires=requires,
install_requires=requires,
python_requires=">= 3.7, < 3.11",
entry_points={
"console_scripts": [
Expand All @@ -35,10 +56,7 @@
},
packages=find_packages(exclude=["tests*"]),
package_data={
"hy": ["*.hy", "__pycache__/*"],
"hy.contrib": ["*.hy", "__pycache__/*"],
"hy.core": ["*.hy", "__pycache__/*"],
"hy.extra": ["*.hy", "__pycache__/*"],
"": ["*.hy"],
},
data_files=[("get_version", ["get_version.py"])],
author="Paul Tagliamonte",
Expand Down Expand Up @@ -69,4 +87,7 @@
"Documentation": "https://docs.hylang.org/",
"Source": "https://github.com/hylang/hy",
},
cmdclass={
"install": install,
},
)

0 comments on commit c84fb12

Please sign in to comment.