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:

  1. (Re)build all cslug.CSlugs on setup.py build.

  2. Include C source code in sdists but exclude them from wheels.

  3. Include cslug type jsons and binariesNick-name for shared library. of the correct OS in wheels but exclude them from sdists.

  4. Mark cslug as a build-time dependency to be installed before trying to run setup.py build.

  5. Mark wheels as platform dependent but Python version independent.

class cslug.building.bdist_wheel(dist: Distribution, **kw)[source]

wheel.bdist_wheel with 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 --all before 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 call cslug.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:

list[str]

Note

This function requires toml. To use, you must mark 'toml' as a build dependency, or if you use the --no-build-isolation option 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.CSlug name 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.bar must 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")