diff --git a/.gitignore b/.gitignore index 1ebb4077d..3ce9b5104 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ dist build/ /.cache /.pytest_cache +/.eggs diff --git a/NEWS.rst b/NEWS.rst index 3bf277e86..ebc2e8ef3 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -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 ------------------------------ diff --git a/setup.py b/setup.py index b71667410..f737bf86d 100755 --- a/setup.py +++ b/setup.py @@ -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]) @@ -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": [ @@ -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", @@ -69,4 +87,7 @@ "Documentation": "https://docs.hylang.org/", "Source": "https://github.com/hylang/hy", }, + cmdclass={ + "install": install, + }, )