Skip to main content

Plugin for Hatch to infer env dependencies from properdocs.yml

Project description

hatch-properdocs

Hatch plugin to integrate ProperDocs and infer dependencies into an env

PyPI License GitHub Workflow Status

This plugin populates Hatch environments with dependencies on the fly based on a properdocs.yml file.

This is intended to effortlessly manage dependencies for a ProperDocs site.

You just need to add this minimal config to Hatch, along with any existing ProperDocs config:

hatch.tomlproperdocs.yml
[env]
requires = [
    "hatch-properdocs",
]

[env.collectors.properdocs.docs]
path = "properdocs.yml"
site_name: ProperDocs example

plugins:
  - autorefs

markdown_extensions:
  - callouts
  - pymdownx.superfences
This gets you the following implied Hatch configuration: (click to expand)
hatch.toml
[envs.docs]
detached = true
dependencies = [
    "markdown-callouts",
    "mkdocs-autorefs",
    "properdocs",
    "pymdown-extensions",
]

[envs.docs.scripts]
build = "properdocs build -f properdocs.yml {args}"
serve = "properdocs serve -f properdocs.yml {args}"
gh-deploy = "properdocs gh-deploy -f properdocs.yml {args}"

(this is just for posterity, no such config is actually written to a file)

With this:

  • You don't need to specify the PyPI dependencies, they get inferred on the fly just from properdocs.yml by doing a reverse lookup of ProperDocs plugins in the catalog, using properdocs get-deps. (See more details there)

  • An automatically managed virtual environment with pre-defined ProperDocs commands is at your fingertips.

You can check this yourself:

hatch env show docs
                    Standalone                     
┌──────┬─────────┬────────────────────┬───────────┐
│ Name │ Type    │ Dependencies       │ Scripts   │
├──────┼─────────┼────────────────────┼───────────┤
│ docs │ virtual │ markdown-callouts  │ build     │
│      │         │ mkdocs-autorefs    │ gh-deploy │
│      │         │ properdocs         │ serve     │
│      │         │ pymdown-extensions │           │
└──────┴─────────┴────────────────────┴───────────┘

The dependencies get resolved and installed into a virtual environment as part of a Hatch invocation. So, you can directly run:

hatch run docs:build
Creating environment: docs
Checking dependencies
Syncing dependencies
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: site
INFO    -  Documentation built in 0.03 seconds

(If you've been using virtualenvs directly, this single command replaces creating an environment, installing dependencies into it, as well as running properdocs in it, optionally with arguments)

Furthermore, whenever the set of dependencies changes (i.e. you select new ProperDocs plugins), these Hatch commands will re-install dependencies as necessary.
Otherwise, the environment is just reused; the installation happens only on the first invocation.

If at any point you want to make sure the dependencies are re-installed anew, you can just remove the environment:

hatch env remove docs
Removing environment: docs

Installation

Just install Hatch. Ideally in an isolated way with pipx install hatch (after installing pipx), or just pip install hatch as a more well-known way.

If you declare hatch-properdocs as a dependency in your Hatch config (pyproject.toml or hatch.toml) as shown above, Hatch will automatically install it on first use.

Alternatively you can install it manually: pipx inject hatch hatch-properdocs or just pip install hatch-properdocs.

And do not install ProperDocs - it's unnecessary, only the sub-environments will have it.

Configuration

Note that although Hatch is typically associated with managing entire Python projects and applications, you can use it purely for environment management for a ProperDocs site - through this plugin, or even without it.

Hatch can be configured through one of two files - hatch.toml or pyproject.toml. Configs in the latter are equivalent but will always need a [tool.hatch...] prefix; it can be used if you have an existing Python project and you don't want to add another config file.

So, add the following into one of the files:

hatch.tomlpyproject.toml
[env]
requires = [
    "hatch-properdocs",
]

[env.collectors.properdocs.ENV_NAME]
path = "path/to/properdocs.yml"

[envs.ENV_NAME]
...
[tool.hatch.env]
requires = [
    "hatch-properdocs"
]

[tool.hatch.env.collectors.properdocs.ENV_NAME]
path = "path/to/properdocs.yml"

[tool.hatch.envs.ENV_NAME]
...

Here, [env.collectors.properdocs.ENV_NAME] means: please populate an environment named "ENV_NAME" based on an ProperDocs config. In that section, path is the path to properdocs.yml.

At the moment that is the entire configurability of this plugin.

In the first example we used "docs" as the environment name, you can use "properdocs" as well if you like, or anything else. Further, if you use "default" as the name (which you might do if documentation building is all that you'll ever use Hatch for) then you can skip the environment prefix (docs: in the above example).

Multiple separate environments with their own configs and dependencies can be populated as well.

Inside [envs.ENV_NAME] (which is an ordinary construct in Hatch) you can proceed to further customize the environment (though normally it shouldn't be necessary, and the section can be omitted from the text config): you can add extra dependencies or scripts, or any other environment config. You could also set detached back to false if the documentation actually relies on the project itself being installed, such as in the case of mkdocstrings.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hatch_properdocs-0.2.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hatch_properdocs-0.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file hatch_properdocs-0.2.0.tar.gz.

File metadata

  • Download URL: hatch_properdocs-0.2.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for hatch_properdocs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ca96ec0490874104ca787c175f4e0417c607a27fd6975019e8f88ae43c7701e9
MD5 2e89986fc95cafc175ceadea3d074190
BLAKE2b-256 1fba9daf8baad374057e03d73ce405d3af25214fd6ccf6760e7a15a5b7778ca7

See more details on using hashes here.

File details

Details for the file hatch_properdocs-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hatch_properdocs-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07afddc4c015fe520f95c56c58efab73761bb43baafe3f4e1b26eb2ea4320c34
MD5 279bbfd6298303182442cccd710ae329
BLAKE2b-256 c2c5b1138dc693802aa92ae9362ab71dbf78d6ed057f287ed2b3a88fd0f87b22

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page