~/datapy v0.2.0 on pypi

corey@mccarty.dev:~/datapy$

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:

  1. cli.py and __init__.py are the only modules without a leading underscore.
  2. cli.py imports only from the public datapy package, so the command line can never do something a script cannot.

Documentation

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:

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:

  1. PyPI: on the datapy project, add a trusted publisher for this repository with workflow main.yml and environment pypi.
  2. GitHub environments: create pypi (add yourself as a required reviewer to approve each upload). github-pages is created automatically.
  3. GitHub Pages: set the source to "GitHub Actions".
  4. Branch protection on master: require a pull request, and require the checks to pass, including "Version is raised".