From a029b09cd2a91a5ce752115fc4b85d989bfd50dc Mon Sep 17 00:00:00 2001 From: Jack Lovell Date: Thu, 23 Feb 2023 17:49:59 +0000 Subject: [PATCH 1/3] Package demo scripts and data in sdists and wheels This enables users who haven't cloned the git repository to still run the demos. A few unnecessary entries were removed from MANIFEST.in too. TODO: see whether we can get rid of MANIFEST.in completely and use setuptools' find_packages and package_data instead. --- MANIFEST.in | 7 ++----- setup.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 2f977070..2d850775 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,3 @@ -include README.md CHANGELOG.md LICENSE.txt CITE.md AUTHORS.md MANIFEST.in setup.py requirements.txt .gitignore +include CHANGELOG.md CITE.md AUTHORS.md include cherab/core/VERSION -recursive-include cherab *.py *.pyx *.pxd *.json *.cl *.npy *.obj -prune demos* - - +recursive-include cherab *.pyx *.pxd *.json *.cl *.npy *.obj diff --git a/setup.py b/setup.py index 476697e8..ba84e56e 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,10 @@ from setuptools import setup, find_packages, Extension +from collections import defaultdict import sys import numpy import os import os.path as path +from pathlib import Path import multiprocessing from Cython.Build import cythonize @@ -68,6 +70,16 @@ compiler_directives=cython_directives, ) +# Include demos in a separate directory in the distribution as data_files. +demo_parent_path = Path("share/cherab/demos/core") +data_files = defaultdict(list) +demos_source = Path("demos") +for item in demos_source.rglob("*"): + if item.is_file(): + install_dir = demo_parent_path / item.parent.relative_to(demos_source) + data_files[str(install_dir)].append(str(item)) +data_files = list(data_files.items()) + # parse the package version number with open(path.join(path.dirname(__file__), "cherab/core/VERSION")) as version_file: version = version_file.read().strip() @@ -105,8 +117,9 @@ "matplotlib", "raysect==0.8.1", ], - packages=find_packages(), + packages=find_packages(include=["cherab*"]), include_package_data=True, + data_files=data_files, zip_safe=False, ext_modules=extensions, ) From 3007d558c5af83caf8146af734deaddb39c3a278 Mon Sep 17 00:00:00 2001 From: Jack Lovell Date: Fri, 24 Feb 2023 16:40:56 +0000 Subject: [PATCH 2/3] Remove MANIFEST.in and include_package_data, specify package_data manually This allows finer control over what gets packaged, and fixes a deprecation warning in recent setuptools versions (see https://github.com/pypa/setuptools/issues/3308 for detais). It also prevents Cython-transpiled C source files being included in the wheel distribution, which roughly halves the size of the installed distribution. --- MANIFEST.in | 3 --- pyproject.toml | 2 +- setup.py | 12 ++++++++---- 3 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 2d850775..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include CHANGELOG.md CITE.md AUTHORS.md -include cherab/core/VERSION -recursive-include cherab *.pyx *.pxd *.json *.cl *.npy *.obj diff --git a/pyproject.toml b/pyproject.toml index ce56ed60..a4eabed0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools", "wheel", "oldest-supported-numpy", "cython>=0.28", "raysect==0.8.1"] +requires = ["setuptools>=62.3", "oldest-supported-numpy", "cython>=0.28", "raysect==0.8.1"] build-backend="setuptools.build_meta" diff --git a/setup.py b/setup.py index ba84e56e..58d28075 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,11 @@ -from setuptools import setup, find_packages, Extension from collections import defaultdict import sys -import numpy import os import os.path as path from pathlib import Path import multiprocessing +import numpy +from setuptools import setup, find_packages, Extension from Cython.Build import cythonize multiprocessing.set_start_method('fork') @@ -117,8 +117,12 @@ "matplotlib", "raysect==0.8.1", ], - packages=find_packages(include=["cherab*"]), - include_package_data=True, + packages=find_packages(include=["cherab"]), + package_data={"": [ + "**/*.pyx", "**/*.pxd", # Needed to build Cython extensions. + "**/*.json", "**/*.cl", "**/*.npy", "**/*.obj", # Supplementary data + "cherab/core/VERSION", # Used by cherab.core to determine version at run time + ]}, data_files=data_files, zip_safe=False, ext_modules=extensions, From 6b8b71c2e469c746990ca9123aa4c8364c1e8829 Mon Sep 17 00:00:00 2001 From: Jack Lovell Date: Mon, 27 Feb 2023 04:58:48 -0500 Subject: [PATCH 3/3] Fix find_packages and package_data --- setup.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 58d28075..32588343 100644 --- a/setup.py +++ b/setup.py @@ -117,12 +117,13 @@ "matplotlib", "raysect==0.8.1", ], - packages=find_packages(include=["cherab"]), + packages=find_packages(include=["cherab*"]), package_data={"": [ "**/*.pyx", "**/*.pxd", # Needed to build Cython extensions. "**/*.json", "**/*.cl", "**/*.npy", "**/*.obj", # Supplementary data - "cherab/core/VERSION", # Used by cherab.core to determine version at run time - ]}, + ], + "cherab.core": ["VERSION"], # Used to determine version at run time + }, data_files=data_files, zip_safe=False, ext_modules=extensions,