Revamp the setup script's install command

Previously, the Hy files would be bytecode compiled before the
compiler's dependencies were installed. In additon, the revamped
version properly propogates the optimization level and generally is a
bit cleaner.

Fixes #1864.
This commit is contained in:
Ryan Gonzalez 2020-01-07 01:57:23 -06:00
parent 653ea064e5
commit 03e2ac3531
2 changed files with 41 additions and 10 deletions

View File

@ -1,4 +1,5 @@
Copyright 2020 the authors. Copyright 2020 the authors.
Portions of setup.py, copyright 2016 Jason R Coombs <jaraco@jaraco.com>.
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),

View File

@ -3,7 +3,11 @@
# This file is part of Hy, which is free software licensed under the Expat # This file is part of Hy, which is free software licensed under the Expat
# license. See the LICENSE. # license. See the LICENSE.
import sys, os import glob
import importlib
import inspect
import os
import sys
from setuptools import find_packages, setup from setuptools import find_packages, setup
from setuptools.command.install import install from setuptools.command.install import install
@ -20,16 +24,42 @@ make things work nicer, and lets Python and the Hy lisp variant play
nice together. """ nice together. """
class Install(install): class Install(install):
def __compile_hy_bytecode(self):
for path in sorted(glob.iglob('hy/**.hy', recursive=True)):
importlib.util.cache_from_source(path, optimize=self.optimize)
def run(self): def run(self):
# Import each Hy module to ensure it's compiled. # Don't bother messing around with deps if they wouldn't be installed anyway.
import os, importlib # Code is based on setuptools's install.py.
for dirpath, _, filenames in sorted(os.walk("hy")): if not (self.old_and_unmanageable or self.single_version_externally_managed
for filename in sorted(filenames): or not self._called_from_setup(inspect.currentframe())):
if filename.endswith(".hy"): easy_install = self.distribution.get_command_class('easy_install')
importlib.import_module(
dirpath.replace("/", ".").replace("\\", ".") + cmd = easy_install(
"." + filename[:-len(".hy")]) self.distribution, args="x", root=self.root, record=self.record,
install.run(self) )
cmd.ensure_finalized()
cmd.always_copy_from = '.'
cmd.package_index.scan(glob.glob('*.egg'))
cmd.args = self.distribution.install_requires
# Avoid deprecation warnings on new setuptools versions.
if 'show_deprecation' in inspect.signature(cmd.run).parameters:
cmd.run(show_deprecation=False)
else:
cmd.run()
# Make sure any new packages get picked up.
import site
importlib.reload(site)
importlib.invalidate_caches()
self.__compile_hy_bytecode()
# The deps won't be reinstalled because of:
# https://github.com/pypa/setuptools/issues/456
return install.run(self)
install_requires = [ install_requires = [
'rply>=0.7.7', 'rply>=0.7.7',