Skip to content

Commit 3eece4d

Browse files
committed
Update documentation for automatic version resolution and publishing process
This commit enhances the documentation in PUBLISHING.md, USAGE.md, and VERSION_RESOLUTION.md to clarify the automatic version resolution feature based on conventional commits. It details how the tool determines the next version when publishing without a specified version, including behavior for subfolder builds. Additionally, it updates examples and explanations to improve user understanding of version handling and the publishing process.
1 parent 1d82264 commit 3eece4d

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

docs/PUBLISHING.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ The package includes built-in support for publishing to PyPI, TestPyPI, and Azur
77
Publish after building:
88

99
```bash
10-
# Publish to PyPI
10+
# Publish to PyPI (version resolved automatically via conventional commits)
1111
python-package-folder --publish pypi
12+
# See [Version Resolution](VERSION_RESOLUTION.md) for details on automatic versioning
1213

1314
# Publish to PyPI with a specific version
1415
python-package-folder --version "1.2.3" --publish pypi
@@ -41,6 +42,20 @@ python-package-folder --publish pypi --skip-existing
4142
- **403 Forbidden**: Usually means you used your username instead of `__token__` with an API token. The tool now auto-detects this.
4243
- **TestPyPI vs PyPI**: TestPyPI requires a separate account and token from https://test.pypi.org/manage/account/token/
4344

45+
## Version Resolution
46+
47+
When publishing without `--version`, the tool automatically resolves the next version using [conventional commits](VERSION_RESOLUTION.md#automatic-version-resolution). This queries the target registry for the latest published version and calculates the next version based on commit messages since that version.
48+
49+
```bash
50+
# Version resolved automatically from conventional commits
51+
python-package-folder --publish pypi
52+
53+
# Or specify version explicitly
54+
python-package-folder --version "1.2.3" --publish pypi
55+
```
56+
57+
See [Version Resolution](VERSION_RESOLUTION.md) for complete details on how automatic versioning works.
58+
4459
## Smart File Filtering
4560

4661
When publishing, the tool automatically filters distribution files to only upload those matching the current build:

docs/USAGE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The tool automatically:
7777
- **For subfolder builds**: Handles `pyproject.toml` configuration:
7878
- **If `pyproject.toml` exists in subfolder**:
7979
- Uses that file (copies it to project root temporarily, adjusting package paths and ensuring `[build-system]` uses hatchling)
80-
- **Version handling**: The version in the subfolder's `pyproject.toml` is automatically updated to match the derived version (from conventional commits or `--version` argument). A warning is shown if versions differ.
80+
- **Version handling**: The version in the subfolder's `pyproject.toml` is automatically updated to match the derived version (from [conventional commits](VERSION_RESOLUTION.md#automatic-version-resolution) or `--version` argument). A warning is shown if versions differ.
8181
- **Name handling**: If the subfolder's `pyproject.toml` has a `name` field that differs from the derived name, a warning is shown but the subfolder's name is used (not the derived one).
8282
- **Dependencies handling**: If the subfolder's `pyproject.toml` has a non-empty `dependencies` field, automatic dependency detection is skipped with a warning. To enable automatic detection, remove or empty the `dependencies` field.
8383
- **Field merging**: Missing fields (like `description`, `authors`, `keywords`, `classifiers`, `license`, `urls`, etc.) are automatically filled from the parent `pyproject.toml` if available.
@@ -107,7 +107,7 @@ python-package-folder --version "0.1.0" --package-name "my-subfolder-package" --
107107
python-package-folder --version "0.1.0" --dependency-group "dev" --publish pypi
108108

109109
# If subfolder has its own pyproject.toml, it will be used automatically
110-
# The version will be updated to match the derived version (from conventional commits)
110+
# The version will be updated to match the derived version (from [conventional commits](VERSION_RESOLUTION.md#automatic-version-resolution))
111111
# The package name from the subfolder toml will be used (even if it differs from derived)
112112
cd src/integration/my_package # assuming my_package/pyproject.toml exists
113113
python-package-folder --publish pypi
@@ -117,7 +117,7 @@ python-package-folder --publish pypi
117117

118118
When a subfolder has its own `pyproject.toml`, the tool intelligently merges it with derived information:
119119

120-
1. **Version**: Always updated to match the derived version (from conventional commits or `--version`). If the subfolder's version differs, a warning is shown but the derived version is used.
120+
1. **Version**: Always updated to match the derived version (from [conventional commits](VERSION_RESOLUTION.md#automatic-version-resolution) or `--version`). If the subfolder's version differs, a warning is shown but the derived version is used.
121121

122122
2. **Name**: If the subfolder's `pyproject.toml` has a `name` field, it takes precedence over the derived name. A warning is shown if they differ.
123123

docs/VERSION_RESOLUTION.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ The `--version` option:
2929

3030
When `--version` is not provided, the tool automatically determines the next version using conventional commits. This is a **Python-native implementation** that follows the same conventions as [semantic-release](https://semantic-release.gitbook.io/semantic-release/) using the Angular preset, but requires no Node.js dependencies.
3131

32+
**When Version Resolution Happens:**
33+
- Version resolution is triggered when `--version` is **not** provided AND:
34+
- You're building a **subfolder** (any directory that's not the main `src/` directory), OR
35+
- You're using `--publish` (for main package builds)
36+
- If `--version` is provided, it is used directly and no resolution is performed
37+
- If `--analyze-only` is used, version resolution is skipped
38+
3239
**Version Resolution Flow:**
3340

3441
```mermaid
@@ -48,7 +55,8 @@ flowchart TD
4855
- **Baseline version**:
4956
- **Registry Query (Preferred)**: When publishing to a repository (PyPI, TestPyPI, or Azure Artifacts), the tool queries the target registry for the latest published version and uses it as the baseline for version calculation. This ensures version calculations are based on what's actually published, not just git tags.
5057
- **Git Tags (Fallback)**: If the package doesn't exist on the registry yet (first release) or if registry query fails, the tool falls back to using git tags to determine the starting version.
51-
- **New version to publish**: After determining the baseline version, the tool analyzes commits since that version to calculate the next version bump (major, minor, or patch) based on [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) messages.
58+
- **Default Baseline**: If no registry version or git tags are found, the baseline defaults to `0.0.0` (treating it as a first release)
59+
- **New version to publish**: After determining the baseline version, the tool analyzes commits since that version to calculate the next version bump (major, minor, or patch) based on [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) messages. If no conventional commits are found but a baseline exists (and it's not `0.0.0`), the tool automatically bumps the minor version.
5260

5361
**For subfolder builds (Workflow 1):**
5462
- Uses per-package tags: `{package-name}-v{version}` (e.g., `my-package-v1.2.3`)
@@ -112,9 +120,20 @@ python-package-folder --publish pypi
112120
python-package-folder --publish pypi
113121
```
114122

123+
**Version Calculation Behavior:**
124+
- **With conventional commits**: Version is calculated based on commit types (feat → minor, fix → patch, BREAKING CHANGE → major)
125+
- **Without conventional commits** (but baseline exists):
126+
- If a baseline version exists (from registry or git tags) and it's not `0.0.0`, the tool automatically bumps the **minor version** even if no conventional commits are found
127+
- Example: Baseline `1.2.3` with only `docs:` commits → Next version: `1.3.0`
128+
- **First release** (`0.0.0` baseline):
129+
- If any commits exist (even without conventional format), defaults to `0.1.0`
130+
- If no commits exist, version resolution fails and `--version` must be provided explicitly
131+
- **No baseline found**: Version resolution fails and `--version` must be provided explicitly
132+
115133
**Requirements:**
116-
- Conventional commits (e.g., `fix:`, `feat:`, `BREAKING CHANGE:`) are required for version calculation
117-
- The tool will fall back to requiring `--version` explicitly if no baseline version is found or no relevant commits are detected
134+
- A baseline version (from registry or git tags) is required for version calculation, OR
135+
- For first releases, at least one commit must exist
136+
- If no baseline is found and no commits exist, `--version` must be provided explicitly
118137

119138
## Subfolder Versioning
120139

0 commit comments

Comments
 (0)