Skip to main content

drain-swamp

Python build backend with build plugins and dependency lock switch

PyPI status drain-swamp coverage percentage License
last commit to gauge activity Quality check status Documentation
platforms Test suite status Python versions supported
implementations black
downloads GitHub stars
msftcangoblowme on Mastodon

drain-swamp features build plugins and dependency lock switch

* Python 3.11 through 3.15, pypy-3.11

new in 2.1.x

fork dependency fixing into separate package; add wreck support; add pytest-logging-strict support; vcs_versioning support;

new in 2.0.x

approach for requirements organize by venvs rather than folders; new implementation for pipenv-unlock commands;

What swamp?

Code in Makefile or python scripts should be reduced or removed entirely, in favor of packaged, unittested, and well documented code.

These files are the favorite target for those placing obfuscated code triggering malware.

Lets call this hiding place, the swamp

Boilerplate

Authors and maintainers deal with many packages. Boilerplate code is copy+paste into multiple packages.

  • an eye sore

  • completely untested code

  • small variations leak in

  • code quality and feature improvements are less likely to happen

drain-swamp started out to reduce this

Generated files

For Python packages, which contain generated files, UX is improved by generating those files during the build process.

These batteries are included:

  • setuptools-scm version file

  • dependency lock switch

    .lock, .unlock, and .lnk files

Micro services use message queues for inter-process communications. The messages use protobuf message protocol which produces a generated file. That must be part of the build process.

Would be a good fit for a build plugin

version file

The build plugin for interacting with version file, it’s about having flexibility on which version str to use.

Different circumstances calls for different version str

  • CI tagged release workflow needs tag version from the version file

  • CI on push workflows need the current version

  • python -m build provide the new version str

This flexibility allows to test building a package before git push or a tagged release.

Get scm (source control management) version

scm-version get

0.5.2.dev0+g2988c13.d20240724

Get from version file

drain-swamp tag

0.5.2

Write a semantic version str to version file. drain-swamp pretag to check/fix semantic version str

scm-version write "0.5.2post0.dev1"

Features

Updating docs

Before a commit, update the date and version str in several locations

updates

  • Sphinx docs/conf.py

  • CHANGES.rst

  • NOTICE.txt

This Sphinx conf.py contains a snippet. The entire contents of the snippet is replaced. This technique is now a separate package, drain-swamp-snippet

Dependency lock switch

Authors disappear or die. Unfunded projects quickly become abandonware. Packages with locked dependencies do not age well.

Lets check the license. Hmmm Apache2.0 abandonware, that’s a great reason to turn the dependency lock off.

pipenv-unlock is a light switch to turn on/off dependency locking.

On your repo, set a CI variable and that is the switch.

When the repo is inactive, turn off the switch and make a release without dependency locking.

How it works

A snippet in pyproject.toml containing both dependencies and optional-dependencies. There is additional meta data as well.

Refresh both .unlock and .lock files. During build time, .lnk shortcut is created.

Create dependency files with the .in extension. These include the dependencies and lines with -r and -c to include other dependency files.

Then

Create both lock and unlock dependency files. Fix both.

req fix

Deprecated. Create .unlock files

req unlock

build config settings

The Python packages build process occurs within a subprocess. The hottest trending topic is how to pass config settings to this subprocess?

Right before python -m build, depending on context, use whichever method is most appropriate.

custom build backend

This would only work for a custom build backend. Will see it’s use only in drain-swamp howto.txt

python -m build -C--kind="0.5.1a4.dev6"

Unless authoring a custom build backend, can safely ignore.

cli

Use bash-workaround

tox

Similar to cli. During pre_command, the TOML file and environment variable DS_CONFIG_SETTINGS are created.

tox test – drain-swamp-tox-test

tox – drain-swamp-tox

github workflows

drain-swamp-action creates the TOML file and environment variable, DS_CONFIG_SETTINGS.

Immediately after this gh action, there is fair bit of:

upload and download artifacts, between step communication, and maybe between jobs communication.

There is one job. Communication is only between steps. e.g. ubuntu-latest-3.10

There are several jobs. A parent job occurs once. Constraining artifact upload to only occur once.

See also gh workflows folder – drain-swamp-gh-workflows

Metadata

Release files for drain-swamp 2.1.2

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

Source distribution (sdist)

Source distribution for drain-swamp 2.1.2
File Size Uploaded Provenance Actions
drain_swamp-2.1.2.tar.gz 508.0 kB With provenance Details for drain_swamp-2.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drain-swamp 2.1.2
File Interpreter ABI Platform Actions
drain_swamp-2.1.2-py3-none-any.whl Python 3 none any Details for drain_swamp-2.1.2-py3-none-any.whl

Total release size: 598.6 kB

Release files / drain_swamp-2.1.2.tar.gz

Download URL drain_swamp-2.1.2.tar.gz
Size 508.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e04dc70471ec881c30d58976324e9a47f2b6f3061f58de0322443b64d3e66c4a
BLAKE2b-256 checksum
How to use checksums
916a7746b9e23a0eca832a2ece36f1fda0a34e9d3be7ff4cd1a77588d36c47ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / drain_swamp-2.1.2-py3-none-any.whl

Download URL drain_swamp-2.1.2-py3-none-any.whl
Size 90.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63c89c724e889b59c1b7604c86f0364da27d9ed51b1c91f26b73523769da8ab6
BLAKE2b-256 checksum
How to use checksums
199f5038a0b619b582693499cf6f2367117ce9aa7745246e34efd2d1b13c45aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for drain-swamp 2.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for drain_swamp-2.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files Full provenance

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