From a42888de673602e6971b800a2ad9e99c92ba502b Mon Sep 17 00:00:00 2001 From: Mario Ostieri <107915956+mariostieriansys@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:19:43 +0100 Subject: [PATCH] Create archive during build and use new ansys action option to only create archive (#23) --- .github/workflows/ci.yml | 6 +++++ .pre-commit-config.yaml | 2 +- post_build_cleanup.py | 12 +++++++++ pyproject.toml | 4 +++ setup.py | 56 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 post_build_cleanup.py create mode 100644 setup.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e656d8..a806c65 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,11 @@ jobs: with: library-name: ${{ env.PACKAGE_NAME }} python-version: ${{ env.MAIN_PYTHON_VERSION }} + - name: Remove Dummy Wheel + run: | + python post_build_cleanup.py + + release: name: Release @@ -88,3 +93,4 @@ jobs: uses: ansys/actions/release-github@v8 with: library-name: ${{ env.PACKAGE_NAME }} + only-code: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7751357..791150b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,7 +20,7 @@ repos: - id: numpydoc-validation exclude: | (?x)( - tests/ | __init__.py + tests/ | __init__.py | post_build_cleanup.py | setup.py ) - repo: https://github.com/codespell-project/codespell diff --git a/post_build_cleanup.py b/post_build_cleanup.py new file mode 100644 index 0000000..f8a76d1 --- /dev/null +++ b/post_build_cleanup.py @@ -0,0 +1,12 @@ +import glob +import os + + +def clean_dist(): + for file in glob.glob("dist/*.whl"): + os.remove(file) + print(f"Removed {file}") + + +if __name__ == "__main__": + clean_dist() diff --git a/pyproject.toml b/pyproject.toml index 1eff2ad..aec1d46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,7 @@ +[build-system] +requires = ["setuptools >= 42.0.0", "wheel"] +build-backend = "setuptools.build_meta" + [project] name = "ansys-tools-omniverse" version = "1.0.0.dev0" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d65135a --- /dev/null +++ b/setup.py @@ -0,0 +1,56 @@ +import os + +from setuptools import find_packages, setup +from setuptools.command.bdist_wheel import bdist_wheel as _bdist_wheel +from setuptools.command.sdist import sdist as _sdist + +description = "Ansys Tools Ominverse Extension" +HERE = os.path.abspath(os.path.dirname(__file__)) +with open(os.path.join(HERE, "README.rst"), encoding="utf-8") as f: + long_description = f.read() + + +class CustomSdist(_sdist): + def make_distribution(self): + # Ensure the 'exts' folder is included in the tar archive + self.filelist.files = [ + f + for f in self.filelist.files + if f.startswith("exts") or f in ["setup.py", "pyproject.toml", "README.rst"] + ] + for root, dirs, files in os.walk("exts"): + for file in files: + self.filelist.files.append(os.path.join(root, file)) + super().make_distribution() + + +class CustomBdistWheel(_bdist_wheel): + def run(self): + # Create a dummy wheel file to satisfy the build process + dist_dir = os.path.join( + self.dist_dir, + f"{self.distribution.get_name()}-{self.distribution.get_version()}-py3-none-any.whl", + ) + with open(dist_dir, "w") as f: + f.write("") + print(f"Created dummy wheel file at {dist_dir}") + # Call the original run method to ensure any other necessary steps are completed + super().run() + + # Remove the dummy wheel file + if os.path.exists(dist_dir): + os.remove(dist_dir) + print(f"Removed dummy wheel file at {dist_dir}") + + +setup( + name="ansys-tools-omniverse", + packages=find_packages(), + cmdclass={ + "sdist": CustomSdist, + "bdist_wheel": CustomBdistWheel, + }, + include_package_data=True, + long_description=long_description, + long_description_content_type="text/x-rst", # This is the key line +)