diff --git a/setup.py b/setup.py index ea3b02c3..44049f9e 100644 --- a/setup.py +++ b/setup.py @@ -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="edb-devops@enterprisedb.com", - 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="edb-devops@enterprisedb.com", + 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/*', + ], + } + )