cslug.building
Tools for integrating with setuptools.
Integration with setuptools is a somewhat messy affair. By putting a
cslug.CSlug in a package, we now have to coerce our package setup to do
the following 5 things:
(Re)build all
cslug.CSlugs onsetup.py build.Include C source code in sdists but exclude them from wheels.
Include cslug type jsons and binariesNick-name for shared library. of the correct OS in wheels but exclude them from sdists.
Mark cslug as a build-time dependency to be installed before trying to run
setup.py build.Mark wheels as platform dependent but Python version independent.
- class cslug.building.bdist_wheel(dist: Distribution, **kw)[source]
wheel.bdist_wheelwith platform dependent but Python independent tags.In addition to setting the tags, also prevent setuptools's build cache from leaking binaries for the wrong platform into the wheel. See
run()for details.- finalize_options()[source]
Set platform dependent wheel tag.
cslug packages contain binaries but they don't use
#include <Python.h>like traditional Python extensions do. This makes wheels dependent OS but not Python version dependent.
- run()[source]
Additionally run
setup.py clean --allbefore building the wheel.Setuptools's caching can cause files for the wrong platform to be collected if you build wheels for the two platforms on the same filesystem. This can happen by switching from 64 to 32 bit Python, using Docker, dual booting or any kind of cross compiling.
Forcing a clean will ensure that no files are included in wheels which they shouldn't be.
Changed in version v0.4.0: Add this force-cleaning step.
- cslug.building.build_slugs(*names, base=<class 'distutils.command.build.build'>)[source]
Overload the
run()method of a distutils build class to additionally callcslug.building.make.- Parameters:
names – Names to be passed to
cslug.building.make.base – An alternative base class to inherit from.
- Returns:
A modified subclass of base.
- cslug.building.copy_requirements(path='pyproject.toml', exclude=())[source]
Parse the build-system: requires list from a PEP518 pyproject.toml.
- Parameters:
path (str or os.PathLike or io.TextIOBase) – Specify an alternative toml file to parse from, defaults to
'pyproject.toml'.exclude (Iterable[str]) – Requirements to exclude, use to remove build only requirements.
- Returns:
- Return type:
Note
This function requires toml. To use, you must mark
'toml'as a build dependency, or if you use the--no-build-isolationoption with pip, have toml installed.Note
toml wheel and setuptools are always excluded. If you want to re-add them then append them after:
copy_requirements() + ["toml"]
- cslug.building.make(*names)[source]
Import and call
cslug.CSlug.make.- Parameters:
names (str) – Names of
cslug.CSlugs.
The syntax for a
cslug.CSlugname is "module_name:attribute_name". For example,make("foo.bar:pop.my_slug")is equivalent to:from foo.bar import pop pop.my_slug.make()
Of course,
foo.barmust be importable for this to work.Multiple strings may be passed as arguments - this is just a lazy for loop.
make("foo.slug", "bar.other_slug")is equivalent to:make("foo.slug") make("bar.other_slug")