Development
This guide covers how to set up a development environment for infrahub-sync, contribute to the project, and publish releases.
Prerequisites
- Python 3.10–3.13 (3.12 recommended)
- uv for dependency management
- Git
Setting up your development environment
Clone the repository
git clone https://github.com/opsmill/infrahub-sync.git
cd infrahub-sync
Install uv
If you don't have uv installed, you can install it with:
curl -LsSf https://astral.sh/uv/install.sh | sh
Or see the uv installation guide for other options.
Install dependencies
uv sync --group dev
This installs all runtime and development dependencies defined in pyproject.toml.
Verify your setup
uv run infrahub-sync --help
uv run infrahub-sync list --directory examples/
Development workflow
Before committing any changes, run the following commands in order:
uv run invoke format # Format code with ruff
uv run invoke lint # Lint code with ruff and pylint
uv run mypy infrahub_sync/ --ignore-missing-imports
Validate the CLI
After making changes, verify the CLI still works:
uv run infrahub-sync --help
uv run infrahub-sync list --directory examples/
uv run infrahub-sync generate --name from-netbox --directory examples/
Running tests
uv run pytest -q
Code standards
Python style
- Python 3.10–3.13 compatible
- Type hints on new or changed code
- Ruff-formatted and lint-clean
- Mypy-checked (do not increase existing error count)
- Public functions and classes require documentation strings
- Raise specific exceptions; avoid broad
except Exception:
Line length
- Maximum line length: 120 characters (configured in
pyproject.toml)
Documentation
If you make user-facing changes (CLI flags, configuration options, new adapters), update the documentation.
Generate command-line documentation
uv run invoke docs.generate
Build documentation site
First-time setup (requires Node.js):
cd docs && npm install
Build the site:
uv run invoke docs.docusaurus
Lint markdown files
npx markdownlint-cli "docs/docs/**/*.{md,mdx}"
npx markdownlint-cli --fix "docs/docs/**/*.{md,mdx}"
Adding a new adapter
- Create
infrahub_sync/adapters/<name>.pyfollowing existing adapter patterns - Add connection configuration schema and an example under
examples/ - Provide
listanddiffpathways before enablingsync - Document required environment variables and expected error cases
- Create a documentation page in
docs/docs/adapters/ - Add the adapter to the sidebar in
docs/sidebars.ts
Invoke tasks
View all available tasks:
uv run invoke --list
Common tasks:
| Task | Description |
|---|---|
linter.format-ruff | Format Python code with ruff |
linter.lint-ruff | Lint Python code with ruff |
linter.lint-pylint | Lint Python code with pylint |
linter.lint-yaml | Lint YAML files with yamllint |
docs.generate | Generate CLI documentation |
docs.docusaurus | Build documentation website |
format | Alias for ruff format |
lint | Run all linters |
Publishing a release
This section documents how to publish new releases of infrahub-sync to PyPI.
Overview
The project uses an automated release system powered by GitHub Actions. There are three ways to publish a release:
- Automated release (recommended for regular releases)
- Manual GitHub release (for controlled releases)
- Manual workflow dispatch (for emergency or custom releases)
Prerequisites
Before publishing, ensure:
- You have write access to the repository
- The
PYPI_TOKENsecret is configured in repository settings - The
GH_INFRAHUB_BOT_TOKENsecret is configured (for automated releases)
Method 1: Automated release (recommended)
This is the standard release flow. Releases are triggered automatically when PRs are merged to main or stable branches.
Step 1: Label your pull requests
Apply appropriate labels to PRs before merging. Labels determine the version bump:
| Label | Version Bump | Use When |
|---|---|---|
changes/major, type/breaking-change | Major (1.0.0 → 2.0.0) | Breaking API changes |
changes/minor, type/feature, type/refactoring | Minor (1.0.0 → 1.1.0) | New features, refactoring |
changes/patch, type/bug, type/housekeeping, type/documentation | Patch (1.0.0 → 1.0.1) | Bug fixes, docs, maintenance |
Auto-labeling rules are configured in .github/release-drafter.yml but require a separate workflow trigger to activate. For now, apply labels manually:
| PR Title Pattern | Recommended Label |
|---|---|
Contains fix | type/bug |
Contains enhance, improve, feature | type/feature |
Contains chore | ci/skip-changelog |
Contains deprecat | type/deprecated |
Step 2: Merge to main
Merge your labeled PR to the main branch. The automation will:
- Calculate the next version based on PR labels
- Update
pyproject.tomlwith the new version (and regenerateuv.lock) - Commit changes as
chore(release): v{VERSION} [skip ci] - Create/update a draft GitHub Release with auto-generated release notes