Contributing
Setup
python -m venv .venv
. .venv/bin/activate
pip install -e '.[dev]'
The dev extra installs pytest, black and build. Datapy itself has no runtime
dependencies, and that should stay true: anything a change needs at run time
has to come from the Python standard library.
Before you commit
black . # format
python tools/gendocs.py # rebuild the generated docs
pytest # tests, formatting check and docs checks
pytest fails if any file is not black-formatted, if a generated doc is out of
date, or if an example in the hand-written docs no longer produces the output
shown. To have black run on every commit, pip install pre-commit and run
pre-commit install.
AI coding agents should read AGENTS.md first: it lists the decisions that are settled and the process to follow.
How the code is laid out
| Path | Role |
|---|---|
datapy/__init__.py |
the entry point for Python code: the public names and nothing else |
datapy/cli.py |
the entry point for the command line |
datapy/__main__.py |
lets python -m datapy reach the command line |
datapy/_*.py |
internals, free to change |
tests/ |
the test suite |
docs/ |
markdown documentation |
tools/gendocs.py |
builds the generated docs |
tools/benchmark.py |
times datapy against awk on a large generated file |
tools/ci.py |
the rules the workflows apply: what a change deploys, which version may follow |
site/ |
Eleventy project that renders the markdown as the documentation site |
.github/workflows/ |
pull request checks, and publishing on merge |
Two rules, both enforced by tests/test_entry_points.py:
cli.pyand__init__.pyare the only modules without a leading underscore.cli.pyimports only from the publicdatapypackage, so the command line can never do something a script cannot.
Documentation
- A docstring on a public name is its documentation.
docs/python-api.mdis generated from the docstrings, so write them in markdown. - The help text of a flag in
cli.pyis its documentation.docs/cli.mdis generated from the argument parser. docs/sql-support.mdis written by hand. Its>>>examples are run as tests, againstdocs/people.csv.- Add a line to
CHANGELOG.mdfor anything a user would notice.
Command line conventions
Flags follow the tar pattern: exactly one operation flag (-s select) plus
modifiers that combine with it (-sa). A new operation gets its own letter; a
new option that changes how an operation behaves is a modifier. Every flag has
a long form.
The file is always its own argument. Each part of a query is its own flag
followed by one value (-w 'age > 40'), and those flags work in any order, so
someone who does not know SQL never has to get clause order right. Anything
containing SQL is a single quoted string; datapy never stitches loose words
into SQL, so the shell cannot reinterpret >, * or $1 halfway through a
query. -q and the whole-statement form are the escape hatches for SQL the
flags do not cover.
Results go to standard output and errors to standard error. Exit status 1 means the query or file was invalid, 2 means the command itself was used wrongly.
Versions
Versions are MAJOR.MINOR.PATCH, with no suffixes:
- patch (
0.2.0to0.2.1): a fix that changes no documented behaviour; - minor (
0.2.1to0.3.0): something new that does not break existing commands or scripts; - major (
0.3.0to1.0.0): a change that can break them.
The version lives in one place, __version__ in datapy/__init__.py, and
moves one step at a time.
What happens to a pull request
There is one long-lived branch, master. Work happens on a short-lived
branch and reaches master through a pull request.
When a pull request is opened or updated:
| Check | Runs when | What it does |
|---|---|---|
| Checks | always | black, the generated docs check, the tests on every supported Python, and a build of the package whose wheel is installed and tested |
| Version is raised | the package changed | fails unless the version went up by one step, is not on PyPI yet, and has a section in CHANGELOG.md |
| Site | docs or site changed | builds the documentation site |
| Labels | always | labels the pull request by what it touches; release means merging it will publish to PyPI, site that it will redeploy the docs |
When it is merged:
| What changed | What happens |
|---|---|
the package: datapy/, pyproject.toml, MANIFEST.in, LICENSE.txt |
the wheel built and tested by the checks is published to PyPI, and a vX.Y.Z tag and GitHub release are created |
the docs: docs/, site/, README.md, CHANGELOG.md, CONTRIBUTING.md |
the site is rebuilt and deployed to GitHub Pages |
| anything else: tests, tools, workflows | the checks run and nothing is deployed |
So a pull request that changes the package must raise the version, and a
docs-only pull request neither needs a version nor publishes anything. The
path lists live in tools/ci.py (and are mirrored in .github/labeler.yml);
python tools/ci.py changes master HEAD shows what a branch would trigger.
If a publish or deploy fails part-way, run the Main workflow by hand from the Actions tab: it publishes the current version if PyPI does not have it yet, and redeploys the site.
The documentation site
site/ holds a small Eleventy project that renders
the markdown already in the repository: README.md, docs/*.md,
CHANGELOG.md and this file. Nothing is written separately for the site.
To add a page, write the markdown in docs/ and list it in PAGES in
site/eleventy.config.js.
The site is styled with Tailwind CSS and shares
the amber terminal theme of coreydmccarty.dev.
The colours and font are theme tokens at the top of site/styles/site.css.
Those are a fallback: every page also loads the main site's
https://coreydmccarty.dev/css/theme.css, and any token that file sets on
:root replaces the local value, so a theme change on the main site reaches
these docs without a rebuild. If that file is missing or unreachable, the
local values apply. The token names (--color-night, --color-raised,
--color-inset, --color-edge, --color-fg, --color-muted,
--color-amber, --color-amber-dim, --color-cyan, --color-green,
--font-mono) are therefore shared with the main site and must not be
renamed on one side only. To preview against a different theme file, set
SITE_THEME_URL before npm run serve.
The layout in site/_includes/page.njk uses Tailwind classes, and the
rendered markdown is styled by the .prose rules in the stylesheet. The
header and footer link to the repository, the PyPI page and the main site;
those addresses are LINKS in site/eleventy.config.js.
cd site
npm ci
npm run serve
One-time repository setup
These are settings on GitHub and PyPI, not files in the repository:
- PyPI: on the
datapyproject, add a trusted publisher for this repository with workflowmain.ymland environmentpypi. - GitHub environments: create
pypi(add yourself as a required reviewer to approve each upload).github-pagesis created automatically. - GitHub Pages: set the source to "GitHub Actions".
- Branch protection on
master: require a pull request, and require the checks to pass, including "Version is raised".