1 min read
pyssg.deploy.netlify
Netlify deploy target (pyssg deploy netlify).
Publishes the built site with Netlify's file-digest Deploy API: the whole site
is described as a {path: sha1} manifest, Netlify replies with the subset of
hashes it does not already have, and only those files are uploaded. This is the
same content-addressed flow the Netlify CLI uses, so re-deploying a mostly
unchanged site uploads almost nothing.
Unlike Cloudflare's Direct Upload, the digest here is a plain SHA1 of the file
contents (stdlib hashlib), so this target needs no extra hashing
dependency -- only httpx from the optional pyssg[deploy] extra, imported
lazily so that merely importing this module never requires the extra.
Configuration (under Config.deploy["netlify"]):
site_id(required) -- the Netlify site's API id (itsapi_id, or the*.netlify.appsubdomain).production(optional, defaultTrue) --Truepublishes to the live site;Falsecreates a draft (preview) deploy that does not change what is currently published.
Authentication: the NETLIFY_AUTH_TOKEN environment variable (a personal
access token). Read from the environment, never from config.
class NetlifyTarget
Deploy to Netlify via the file-digest Deploy API.
Stateless with respect to the pipeline. The test seams (transport,
sleep, retry/backoff knobs) let the flow run against an httpx
MockTransport with no real network or wall-clock delay.
NetlifyTarget.__init__(self, *, transport: httpx.AsyncBaseTransport | None = None, sleep: Callable[[float], Awaitable[None]] | None = None, max_retries: int = 4, backoff_base: float = 0.5) -> None
NetlifyTarget.required_env(self) -> list[str]
The personal access token used as a bearer credential.
NetlifyTarget.required_config_keys(self) -> list[str]
The site id identifies which Netlify site to deploy to.
async NetlifyTarget.deploy(self, ctx: DeployContext) -> DeployResult
Create a deploy from the digest manifest and upload required files.
Returns the deploy id and its URL. Raises :class:DeployError on a
missing extra, an API error, or a malformed response.