-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: setuptools - use a context for installation so that all build ar…
…tifacts are cleaned up by default. Pip installation is not cleaning up leftover 'build/' and 'edb_terraform.egg_info/' directories when installing from a local repo and might cause unexpected errors due to old build files being included in the final build. When calling 'pip install . -vvv', logs show that it calls 'python setup.py egg_info' followed by 'python setup.py bdist_wheel'.
- Loading branch information
Showing
1 changed file
with
68 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import os.path | ||
import sys | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
from contextlib import contextmanager | ||
import shutil | ||
|
||
from setuptools import setup | ||
from textwrap import dedent | ||
|
@@ -26,48 +29,67 @@ def get_requirements(): | |
with open(requirements_path) as f: | ||
return f.read().splitlines() | ||
|
||
setup( | ||
name="edb-terraform", | ||
version=get_version(), | ||
author="EDB", | ||
author_email="[email protected]", | ||
packages=[ | ||
"edbterraform", | ||
], | ||
url="https://github.com/EnterpriseDB/edb-terraform/", | ||
entry_points = { | ||
'console_scripts': [ | ||
'edb-terraform = edbterraform.__main__:entry_point', | ||
] | ||
}, | ||
license="BSD", | ||
description=dedent(""" | ||
Terraform templates aimed to provide easy to use YAML configuration file | ||
describing the target cloud infrastrure. | ||
"""), | ||
long_description=get_long_description(), | ||
long_description_content_type="text/markdown", | ||
classifiers=[ | ||
"Development Status :: 5 - Production/Stable", | ||
"Environment :: Console", | ||
"License :: OSI Approved :: BSD License", | ||
"Programming Language :: Python :: 3", | ||
"Topic :: Database", | ||
], | ||
keywords="terraform cloud yaml edb cli aws rds aurora azure aks gcloud gke kubernetes k8s", | ||
python_requires=">=3.8", | ||
install_requires=get_requirements(), | ||
extras_require={}, | ||
data_files=[], | ||
package_data={ | ||
'edbterraform': [ | ||
'data/terraform/*/*', | ||
'data/terraform/*.tf', | ||
'data/terraform/*.tf.json', | ||
'data/terraform/*/modules/*/*', | ||
'data/templates/*/*', | ||
'utils/*', | ||
'parser/*', | ||
] | ||
} | ||
) | ||
@contextmanager | ||
def temp_directory_context(): | ||
''' | ||
Create a temporary directory with the source code. | ||
This is needed to avoid leftover artifacts from the build process. | ||
Ref: https://github.com/pypa/build/issues/455 | ||
Ref: https://github.com/pypa/setuptools/issues/1347 | ||
Ref: https://github.com/pypa/setuptools/issues/1871 | ||
''' | ||
cwd = Path.cwd().resolve() | ||
with TemporaryDirectory(prefix='setuptools-', dir=cwd) as temp_dir: | ||
try: | ||
temp_dir = Path(temp_dir).resolve() | ||
temp_src = temp_dir / 'src' | ||
shutil.copytree(src=cwd, dst=temp_src, symlinks=True, ignore=lambda dir, files: [file for file in files if str(temp_dir) in str((Path(dir) / file).resolve())]) | ||
os.chdir(temp_src) | ||
yield | ||
finally: | ||
os.chdir(cwd) | ||
|
||
with temp_directory_context(): | ||
setup( | ||
name="edb-terraform", | ||
version=get_version(), | ||
author="EDB", | ||
author_email="[email protected]", | ||
packages=[ | ||
"edbterraform", | ||
], | ||
url="https://github.com/EnterpriseDB/edb-terraform/", | ||
entry_points = { | ||
'console_scripts': [ | ||
'edb-terraform = edbterraform.__main__:entry_point', | ||
] | ||
}, | ||
license="BSD", | ||
description=dedent(""" | ||
Terraform templates aimed to provide easy to use YAML configuration file | ||
describing the target cloud infrastrure. | ||
"""), | ||
long_description=get_long_description(), | ||
long_description_content_type="text/markdown", | ||
classifiers=[ | ||
"Development Status :: 5 - Production/Stable", | ||
"Environment :: Console", | ||
"License :: OSI Approved :: BSD License", | ||
"Programming Language :: Python :: 3", | ||
"Topic :: Database", | ||
], | ||
keywords="terraform cloud yaml edb cli aws rds aurora azure aks gcloud gke kubernetes k8s", | ||
python_requires=">=3.8", | ||
install_requires=get_requirements(), | ||
extras_require={}, | ||
data_files=[], # Deprecated | ||
package_data={ | ||
'edbterraform': [ | ||
'data/terraform/*', | ||
'data/terraform/*/modules/*/*', | ||
'data/templates/**/*', | ||
'utils/*', | ||
'parser/*', | ||
], | ||
} | ||
) |