Skip to main content

Configuration and version bumping

Project detection, configuration loading, and version bumping for fastship.

Use ship-bump from the command line or ship_bump in Python to increment semantic versions (X.Y.Z) or .postN suffixes in Cargo.toml, package.json, static [project].version, or pkg/__init__.py. Synchronized copies listed in [tool.fastship].version-files update in the same step, and nbdev Python projects run nbdev-export afterward.

ship-bump                  # bump patch (or .postN when present)
ship-bump --part 1         # bump minor and drop any .postN suffix
ship-bump --part 2 --unbump

Load project settings programmatically with find_project, project_type, and the typed config loaders (get_config, get_rs_config, get_npm_config, get_crate_config). Loaders and version helpers raise FileNotFoundError for missing project markers, packages, or version-files, ValueError for invalid versions or [tool.fastship] settings, and CliError on a uv workspace root.

Configuration

Each config dataclass reads its version property fresh from disk on every access.

PyprojectConfig

def PyprojectConfig(
    root:pathlib._local.Path, # Project root directory containing `pyproject.toml`
    pyproject:pathlib._local.Path, # Resolved path to `pyproject.toml`
    data:dict, # Parsed `pyproject.toml` dictionary
    branch:str, # Release git branch
    changelog_file:pathlib._local.Path, # Path to `CHANGELOG.md` (or `[tool.fastship].changelog_file`)
    version_files:list[pathlib._local.Path], # Extra files from `[tool.fastship].version-files` updated on bump
)->None:

Common settings loaded from a pyproject.toml project and its [tool.fastship] table.

ShipConfig

def ShipConfig(
    root:pathlib._local.Path, # Project root directory containing `pyproject.toml`
    pyproject:pathlib._local.Path, # Resolved path to `pyproject.toml`
    data:dict, # Parsed `pyproject.toml` dictionary
    branch:str, # Release git branch
    changelog_file:pathlib._local.Path, # Path to `CHANGELOG.md` (or `[tool.fastship].changelog_file`)
    version_files:list[pathlib._local.Path], # Extra files from `[tool.fastship].version-files` updated on bump
    pkg:str | None, # Package import directory name, or `None` for GitHub-only projects
    pkg_path:pathlib._local.Path | None, # Path to the package directory, or `None` for GitHub-only projects
    init_file:pathlib._local.Path | None, # Path to `pkg/__init__.py`, or `None` for GitHub-only projects
    wheel_only:bool, # Whether `[tool.fastship].wheel-only` skips sdist builds
)->None:

Configuration for a Python, nbdev, Zig, or GitHub-only project.

ShipConfig.version

def version()->str:

Current version read fresh from [project].version, or __version__ in init_file.

ShipConfig.gh_only

def gh_only()->bool:

Return True when this project has no Python package and releases on GitHub only.

RustConfig

def RustConfig(
    root:pathlib._local.Path, # Project root directory containing `pyproject.toml`
    pyproject:pathlib._local.Path, # Resolved path to `pyproject.toml`
    data:dict, # Parsed `pyproject.toml` dictionary
    branch:str, # Release git branch
    changelog_file:pathlib._local.Path, # Path to `CHANGELOG.md` (or `[tool.fastship].changelog_file`)
    version_files:list[pathlib._local.Path], # Extra files from `[tool.fastship].version-files` updated on bump
    manifest_path:pathlib._local.Path, # Path to the Cargo manifest holding the package or workspace version
)->None:

Configuration for a maturin/PyO3 project whose version lives in Cargo.toml.

RustConfig.version

def version()->str:

Current version read fresh from [package] or [workspace.package] in manifest_path.

NpmConfig

def NpmConfig(
    root:pathlib._local.Path, # Project root directory containing `package.json`
    pkg_json:pathlib._local.Path, # Resolved path to `package.json`
    name:str, # Package `name` field from `package.json`
    branch:str, # Release git branch
)->None:

Configuration for an npm-only project (package.json with no closer pyproject.toml).

NpmConfig.version

def version()->str:

Current version string read fresh from pkg_json.

CrateConfig

def CrateConfig(
    root:pathlib._local.Path, # Crate root directory containing `Cargo.toml`
    manifest_path:pathlib._local.Path, # Resolved path to `Cargo.toml`
    name:str, # Crate `[package].name` from `Cargo.toml`
    branch:str, # Release git branch
    version_files:list[pathlib._local.Path]=<factory>, # Optional extra synchronized version files
)->None:

Configuration for a pure-Rust crate (Cargo.toml with no closer pyproject.toml).

CrateConfig.version

def version()->str:

Current version read fresh from [package] or [workspace.package] in manifest_path.

get_config

def get_config(
    start:str | pathlib._local.Path | None=None, # Directory to search upward from (defaults to current working directory)
)->fastship.config.ShipConfig: # Loaded Python or GitHub-only project configuration

Load ShipConfig from the nearest pyproject.toml.

Supports dynamic __init__.py versions, static [project].version, and GitHub-only projects with no package directory. Refuses uv workspace roots (CliError) and requires [tool.fastship].release to be "tag" when set.

get_rs_config

def get_rs_config(
    start:str | pathlib._local.Path | None=None, # Directory to search upward from (defaults to current working directory)
)->fastship.config.RustConfig: # Loaded maturin/PyO3 project configuration

Load RustConfig for a maturin/PyO3 project.

Reads the Cargo manifest path from [tool.fastship.rs].manifest_path, defaulting to Cargo.toml next to pyproject.toml. Requires [project].dynamic to include "version" with no static [project].version.

get_npm_config

def get_npm_config(
    start:str | pathlib._local.Path | None=None, # Directory to search upward from (defaults to current working directory)
)->fastship.config.NpmConfig: # Loaded npm project configuration

Load NpmConfig from the nearest package.json.

get_crate_config

def get_crate_config(
    start:str | pathlib._local.Path | None=None, # Directory to search upward from (defaults to current working directory)
)->fastship.config.CrateConfig: # Loaded pure-Rust crate configuration

Load CrateConfig from the nearest Cargo.toml.

Version bumping

ship_bump

def ship_bump(
    part:int=None, # Semver part from the left (`0` major, `1` minor, `2` patch); defaults to `.postN` when present, else patch (`2`)
    unbump:bool=False, # Decrement instead of incrementing
):

Bump the project version in place and sync [tool.fastship].version-files.

Detects the project type from the nearest marker (package.json, Cargo.toml, or pyproject.toml), updates the owning version file, and runs nbdev-export afterward for nbdev Python projects whose version lives in __init__.py.

Supplying part drops any .postN suffix before bumping that component.

ship-bump                  # 0.1.0 -> 0.1.1, or 0.1.0.post1 -> 0.1.0.post2
ship-bump --part 1         # 0.1.0.post2 -> 0.2.0
ship-bump --part 2 --unbump

cargo_bump

def cargo_bump(
    cfg:fastship.config.RustConfig | fastship.config.CrateConfig, # Loaded Rust or crate configuration
    part:int=None, # Semver part from the left (`0` major, `1` minor, `2` patch); `None` bumps `.postN` if present else patch
    unbump:bool=False, # Decrement the version instead of incrementing
)->str: # The new version string

Bump the version in cfg.manifest_path ([package] or [workspace.package] when inherited) and any cfg.version_files.

Prints old and new versions and updates Cargo.toml in place without rebuilding.

version_copies

def version_copies(
    old:str, # Exact current version string expected once per file
    version_files:list[pathlib._local.Path], # Synchronized files to validate and read
)->dict[pathlib._local.Path, str]: # Mapping of each path to its full text

Read synchronized version_files and raise ValueError unless old appears exactly once in each before any write.

write_npm_version

def write_npm_version(
    pkg_json:pathlib._local.Path, # Path to `package.json`
    version:str, # New version string to write
):

Rewrite the top-level version field in pkg_json, preserving existing indentation.

Project detection

find_project

def find_project(
    start:pathlib._local.Path | None=None, # Starting directory (defaults to current working directory)
)->tuple[typing.Literal['py', 'npm', 'crate'], pathlib._local.Path]: # `(kind, marker_path)` for the nearest project marker

Find the nearest project marker walking up from start.

Checks pyproject.toml ("py"), package.json ("npm"), and Cargo.toml ("crate"). When multiple markers live in the same directory, priority follows that order.

project_type

def project_type(
    root:pathlib._local.Path, # Project root directory
    data:dict, # Parsed `pyproject.toml` dictionary
)->Literal['rust', 'zig', 'python']: # Detected project kind

Classify a pyproject.toml project as "rust", "zig", or "python".

Returns "rust" when Cargo.toml exists in root or is_maturin_project(data) is true, "zig" when [build-system].requires includes ziglang, and "python" otherwise.

find_pkg_path

def find_pkg_path(
    root:pathlib._local.Path, # Project root directory
    data:dict, # Parsed `pyproject.toml` dictionary
)->pathlib._local.Path: # Path to the Python package directory

Locate the Python package directory under root.

Honors [tool.fastship].package before falling back to fastcore.project.find_pkg_path ([project].name and setuptools discovery).

gh_only

def gh_only(
    root:pathlib._local.Path, # Project root directory
    data:dict, # Parsed `pyproject.toml` dictionary
)->bool: # `True` when released on GitHub only (no PyPI build)

Return True when a project defines a static [project].version and has no Python package to build.

Projects with [tool.fastship].package set always return False.

is_maturin_project

def is_maturin_project(
    data:dict, # Parsed `pyproject.toml` dictionary
)->bool: # `True` when `maturin` is configured as build backend, build requirement, or `[tool.maturin]`

Return True when pyproject.toml data configures a maturin/PyO3 build.

is_nbdev

def is_nbdev(
    data:dict, # Parsed `pyproject.toml` dictionary
)->bool: # `True` when `[tool.nbdev]` is present

Return True when pyproject.toml data defines a [tool.nbdev] table.

is_nbdev_py

def is_nbdev_py(
    root:pathlib._local.Path, # Project root directory
    data:dict, # Parsed `pyproject.toml` dictionary
)->bool: # `True` for `nbdev` Python projects storing `__version__` in `__init__.py`

Return True for nbdev Python projects without a static [project].version.

ship_cfg

def ship_cfg(
    data:dict, # Parsed `pyproject.toml` dictionary
)->dict: # `[tool.fastship]` table, or `{}` when absent

Return the [tool.fastship] table from parsed pyproject.toml data.

Git and TOML helpers

branch

def branch(
    ship:dict=None, # `[tool.fastship]` table from `ship_cfg(data)`
)->str: # Release branch name

Resolve the target git branch.

Checks [tool.fastship].branch, then $FASTSHIP_BRANCH, then the current git branch, falling back to "main".

parse_repo

def parse_repo(
    repo:str=None, # Explicit `"OWNER/REPO"` slug, bare repo name, or `None`
    path:pathlib._local.Path=None, # Directory to inspect git `remote.origin.url` in
)->tuple[str | None, str | None]: # `(owner, repo_name)`, with `None` elements if unresolved

Parse an 'OWNER/REPO' string, falling back to the git origin remote in path.

git_cmd

def git_cmd(
    cmd:str, # Git arguments string, split with `shlex.split` (e.g. `"branch --show-current"`)
    default:str='', # Value returned when git fails or outputs only whitespace
    path:pathlib._local.Path=None, # Working directory for git (defaults to current working directory)
)->str: # Stripped stdout, or `default`

Run git <cmd> in path and return stripped stdout, falling back to default on failure or empty output.

gh_url

def gh_url(
    org:str, # GitHub owner or organization
    proj:str, # Repository name
)->str: # Repository URL without trailing slash

Build the GitHub repository URL https://github.com/{org}/{proj}.

pages_url

def pages_url(
    org:str, # GitHub owner or organization
    proj:str, # Repository name
)->str: # GitHub Pages URL ending with `/`

Build the GitHub Pages URL https://{org}.github.io/{proj}/.

toml_set

def toml_set(
    p:pathlib._local.Path, # Path to the TOML file to update in place
    section:str, # Dotted table name, e.g. `"tool.fastship"` or `"project.urls"`
    items:dict, # Key/value pairs to write into `[section]`
    replace:bool=True, # Overwrite keys that already exist (matched case-insensitively)
):

Write items into dotted [section] of TOML file p, preserving comments and formatting.

Creates missing parent tables as super-tables and skips rewriting p when nothing changed.