Skip to content

Commit ea0cc9a

Browse files
fix #324: document/recommend the v prefix
1 parent 6655627 commit ea0cc9a

File tree

5 files changed

+133
-9
lines changed

5 files changed

+133
-9
lines changed

docs/config.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ Callables or other Python objects have to be passed in `setup.py` (via the `use_
6767
named `version`, that captures the actual version information.
6868

6969
Defaults to the value of [setuptools_scm._config.DEFAULT_TAG_REGEX][]
70+
which supports tags with optional "v" prefix (recommended), project prefixes,
71+
and various version formats.
72+
73+
!!! tip
74+
75+
The default regex supports common tag formats like `v1.0.0`, `myproject-v1.0.0`,
76+
and `1.0.0`. For best practices on tag naming, see
77+
[Version Tag Formats](usage.md#version-tag-formats).
7078

7179
`parentdir_prefix_version: str|None = None`
7280
: If the normal methods for detecting the version (SCM version,

docs/extending.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ representing the version.
5858
and custom `.devN` versions will trigger an error.
5959

6060
**Examples:**
61-
- Tag `1.0.0` → version `1.0.1.dev0` (if dirty or distance > 0)
62-
- Tag `1.0.0` → version `1.0.0` (if exact match)
61+
- Tag `v1.0.0` → version `1.0.1.dev0` (if dirty or distance > 0)
62+
- Tag `v1.0.0` → version `1.0.0` (if exact match)
6363

6464
`calver-by-date`
6565
: Calendar versioning scheme that generates versions based on dates.
@@ -69,25 +69,25 @@ representing the version.
6969
for release branches.
7070

7171
**Examples:**
72-
- Tag `23.01.15.0` on same day → version `23.01.15.1.devN`
73-
- Tag `23.01.15.0` on different day (e.g., 2023-01-16) → version `23.01.16.0.devN`
74-
- Tag `2023.01.15.0` → uses 4-digit year format for new versions
72+
- Tag `v23.01.15.0` on same day → version `23.01.15.1.devN`
73+
- Tag `v23.01.15.0` on different day (e.g., 2023-01-16) → version `23.01.16.0.devN`
74+
- Tag `v2023.01.15.0` → uses 4-digit year format for new versions
7575

7676
`no-guess-dev`
7777
: Does no next version guessing, just adds `.post1.devN`.
7878
This is the recommended replacement for the deprecated `post-release` scheme.
7979

8080
**Examples:**
81-
- Tag `1.0.0` → version `1.0.0.post1.devN` (if distance > 0)
82-
- Tag `1.0.0` → version `1.0.0` (if exact match)
81+
- Tag `v1.0.0` → version `1.0.0.post1.devN` (if distance > 0)
82+
- Tag `v1.0.0` → version `1.0.0` (if exact match)
8383

8484
`only-version`
8585
: Only use the version from the tag, as given.
8686

8787
!!! warning "This means version is no longer pseudo unique per commit"
8888

8989
**Examples:**
90-
- Tag `1.0.0` → version `1.0.0` (always, regardless of distance or dirty state)
90+
- Tag `v1.0.0` → version `1.0.0` (always, regardless of distance or dirty state)
9191

9292
`post-release (deprecated)`
9393
: Generates post release versions (adds `.postN`)

docs/index.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,21 @@ dynamic = ["version"]
4343
# more missing
4444

4545
[tool.setuptools_scm]
46+
´´´
4647

47-
```
48+
49+
!!! tip "Recommended Tag Format"
50+
51+
Use the **"v" prefix** for your version tags for best compatibility:
52+
53+
```bash
54+
git tag v1.0.0
55+
git tag v1.1.0
56+
git tag v2.0.0-rc1
57+
```
58+
59+
This is a widely adopted convention that works well with setuptools-scm and other tools.
60+
See the [Version Tag Formats](usage.md#version-tag-formats) section for more details.
4861

4962

5063
### With hatch

docs/overrides.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ Use with a specific package:
5050
export SETUPTOOLS_SCM_PRETEND_METADATA_FOR_MY_PACKAGE='{node="g1234567", distance=2}'
5151
```
5252

53+
!!! note "Node ID Prefixes"
54+
55+
Node IDs must include the appropriate SCM prefix:
56+
57+
- Use `g` prefix for git repositories (e.g., `g1a2b3c4d5`)
58+
- Use `h` prefix for mercurial repositories (e.g., `h1a2b3c4d5`)
59+
60+
This ensures consistency with setuptools-scm's automatic node ID formatting.
61+
5362
### Use case: CI/CD environments
5463

5564
This is particularly useful for solving issues where version file templates need access to

docs/usage.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,100 @@ For Git projects, the version relies on [git describe](https://git-scm.com/docs
253253
so you will see an additional `g` prepended to the `{revision hash}`.
254254

255255

256+
## Version Tag Formats
257+
258+
setuptools-scm automatically detects version information from SCM tags. The default tag regex
259+
supports a wide variety of tag formats, with the **"v" prefix being recommended** for clarity
260+
and consistency.
261+
262+
### Recommended Tag Format
263+
264+
**Use the "v" prefix for version tags:**
265+
266+
```bash
267+
git tag v1.0.0 # Recommended
268+
git tag v2.1.3
269+
git tag v1.0.0-alpha1
270+
git tag v1.0.0-rc1
271+
```
272+
273+
### Supported Tag Formats
274+
275+
setuptools-scm's default tag regex supports:
276+
277+
- **Version prefix**: `v` or `V` (optional, but recommended)
278+
- **Project prefix**: Optional project name followed by dashes (e.g., `myproject-v1.0.0`)
279+
- **Version number**: Standard semantic versioning patterns
280+
- **Pre-release suffixes**: Alpha, beta, RC versions
281+
- **Build metadata**: Anything after `+` is ignored
282+
283+
**Examples of valid tags:**
284+
```bash
285+
# Recommended formats (with v prefix)
286+
v1.0.0
287+
v2.1.3
288+
v1.0.0-alpha1
289+
v1.0.0-beta2
290+
v1.0.0-rc1
291+
v1.2.3-dev
292+
V1.0.0 # Capital V also works
293+
294+
# Project-prefixed formats
295+
myproject-v1.0.0
296+
my-lib-v2.1.0
297+
298+
# Without v prefix (supported but not recommended)
299+
1.0.0
300+
2.1.3
301+
1.0.0-alpha1
302+
303+
# With build metadata (metadata after + is ignored)
304+
v1.0.0+build.123
305+
v1.0.0+20240115
306+
```
307+
308+
### Why Use the "v" Prefix?
309+
310+
1. **Clarity**: Makes it immediately obvious that the tag represents a version
311+
2. **Convention**: Widely adopted standard across the software industry
312+
3. **Git compatibility**: Works well with git's tag sorting and filtering
313+
4. **Tool compatibility**: Many other tools expect version tags to have a "v" prefix
314+
315+
### Custom Tag Patterns
316+
317+
If you need different tag patterns, you can customize the tag regex:
318+
319+
```toml title="pyproject.toml"
320+
[tool.setuptools_scm]
321+
tag_regex = "^release-(?P<version>[0-9]+\\.[0-9]+\\.[0-9]+)$"
322+
```
323+
324+
## Node ID Prefixes
325+
326+
setuptools-scm automatically prepends identifying characters to node IDs (commit/revision hashes)
327+
to distinguish between different SCM systems:
328+
329+
- **Git repositories**: Node IDs are prefixed with `g` (e.g., `g1a2b3c4d5`)
330+
- **Mercurial repositories**: Node IDs are prefixed with `h` (e.g., `h1a2b3c4d5`)
331+
332+
This prefixing serves several purposes:
333+
334+
1. **SCM identification**: Makes it clear which version control system was used
335+
2. **Consistency**: Ensures predictable node ID format across different SCM backends
336+
3. **Debugging**: Helps identify the source SCM when troubleshooting version issues
337+
338+
The prefixes are automatically added by setuptools-scm and should be included when manually
339+
specifying node IDs in environment variables like `SETUPTOOLS_SCM_PRETEND_METADATA`.
340+
341+
**Examples:**
342+
```bash
343+
# Git node ID
344+
1.0.0.dev5+g1a2b3c4d5
345+
346+
# Mercurial node ID
347+
1.0.0.dev5+h1a2b3c4d5
348+
```
349+
256350
!!! note
257351

258352
According to [PEP 440](https://peps.python.org/pep-0440/#local-version-identifiers>),

0 commit comments

Comments
 (0)