Skip to main content

setuptools-build-subpackage v1.0.0

Package a subfolder as a python distribution

  • Free software: Apache Software License 2.0

https://img.shields.io/badge/code%20style-black-000000.svg

Installation

pip install setuptools-build-subpackage

You can also install the in-development version with:

pip install https://github.com/ashb/setuptools-build-subpackage/archive/master.zip

Usage

This distribution contains a subclass of setuptools’s Distribution, designed to build a “sub-module” as a stand alone distribution.

It is designed to be used with setuptools’s declrative config – i.e. where everything is defined in setup.cfg, not in setup.py

For example, take the following layout:

├── example
│   ├── __init__.py
│   ├── sub_module_a
│   │   ├── __init__.py
│   │   ├── setup.cfg
│   │   └── where.py
│   └── sub_module_b
│       ├── __init__.py
│       ├── setup.cfg
│       └── where.py
└── setup.cfg

This assumes we want example.sub_module_a and example.sub_module_b not included in the main distribution, but instead released as separate dists to PyPI.

This set of classes ensures the following:

  • That the top level setup.cfg is not loaded, instead only the one specified from the sub-package

  • That the build/ folder for each sub-package is kept clean, so files from one build don’t leak in to another

  • That the setup.cfg from the sub-folder is present in the built sdist at the top level, meaning it can be installed normally.

  • That a stub setup.py file is included for compatibility with older installers

Configure your main dist

First you should exclude the sub-packages from being included in your main dist:

setup(
    ...
    packages=find_packages(exclude=['example.sub_module_*'])
)

or

[options.packages.find]
exclude =
  example.sub_module_*

Create a setup.cfg for your sub-dist

The requirements and information for the subdist are all driven off a setup.cfg – right now a sub-setup.py is not supported. (The setup.py included in the sdist will always be generated. PRs welcome if you need something else here.)

See example/sub_module_a/setup.cfg in the source code for a minimal example.

All file paths and module names are absolute, not relative to the location of the setup.cfg file

Build the sdist/bdist

Run the following command:

python -m setuptools_build_subpackage \
  --subpackage-folder example/sub_module_b \
  sdist \
  bdist_wheel

This will create a .tar.ga and .whl file in dist

Including a license comment

If you need a license comment in the generated setup.py, pass the --license-template option to sdist

python -m setuptools_build_subpackage \
  --subpackage-folder example/sub_module_b \
  sdist --license-template ./LICENSE \
  bdist_wheel

This argument should be a path to a plain-text license file, that will be included at the top of the generated file, each line prefixed with a python comment.

Development

To run all the tests run:

pip install -e '.[devel]' && pytest

It is also recommended that you install pre-commit to check style rules

Changelog

1.0.0 (2021-04-23)

  • First release on PyPI.

Release files for setuptools-build-subpackage 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for setuptools-build-subpackage 1.0.0
File Size Uploaded
setuptools-build-subpackage-1.0.0.tar.gz 14.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for setuptools-build-subpackage 1.0.0
File Interpreter ABI Platform
setuptools_build_subpackage-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.4 kB

Release files / setuptools-build-subpackage-1.0.0.tar.gz

Download URL setuptools-build-subpackage-1.0.0.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2f09fd5b5b543d5c063151439d845cd3fb4f67b3426204625301d6f28ca8f26a
BLAKE2b-256 checksum
How to use checksums
2f26c454a7b72563ce362a9ff5d29aa8b809154ec19cf45f792cc261acec0012
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.3

Release files / setuptools_build_subpackage-1.0.0-py3-none-any.whl

Download URL setuptools_build_subpackage-1.0.0-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5bc5b58769bc91b785ae9bd9e660859843736633703f771bbdc064f660232770
BLAKE2b-256 checksum
How to use checksums
02b38d13066de3e54ea9282bc8c8c6abf10ed49d3632a9c537966037a2d543f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page