Skip to content

versioning ¤

Utilities to handle different versioning schemes such as SemVer and PEP 440.

Classes:

Functions:

Attributes:

bump_pep440 module-attribute ¤

bump_pep440 = PEP440Bumper(__args__)

Bump a PEP 440 version.

bump_semver module-attribute ¤

bump_semver = SemVerBumper(__args__)

Bump a SemVer version.

PEP440Bumper ¤

PEP440Bumper(strategies: tuple[str, ...])

Bases: VersionBumper

PEP 440 version bumper.

Parameters:

  • strategies (tuple[str, ...]) –

    The supported bumping strategies.

Source code in src/git_changelog/versioning.py
650
651
652
653
654
655
656
def __init__(self, strategies: tuple[str, ...]) -> None:
    """Initialize the bumper.

    Parameters:
        strategies: The supported bumping strategies.
    """
    self.strategies = strategies

PEP440Version ¤

Bases: Version, ParsedVersion

PEP 440 version.

Methods:

bump_alpha ¤

bump_alpha() -> PEP440Version

Bump alpha-release.

Examples:

>>> PEP440Version("1").bump_alpha()
ValueError: Cannot bump from release to alpha pre-release (use `dent_alpha`)
>>> PEP440Version("1a0").bump_alpha()
<Version('1a1')>
>>> PEP440Version("1a0").bump_alpha("a")
<Version('1a1')>
>>> PEP440Version("1a0.post0").bump_alpha()
<Version('1a1')>

Returns:

  • PEP440Version

    Version with same epoch, same release, bumped alpha pre-release and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
def bump_alpha(self) -> PEP440Version:
    """Bump alpha-release.

    Examples:
        >>> PEP440Version("1").bump_alpha()
        ValueError: Cannot bump from release to alpha pre-release (use `dent_alpha`)
        >>> PEP440Version("1a0").bump_alpha()
        <Version('1a1')>
        >>> PEP440Version("1a0").bump_alpha("a")
        <Version('1a1')>
        >>> PEP440Version("1a0.post0").bump_alpha()
        <Version('1a1')>

    Returns:
        Version with same epoch, same release, bumped alpha pre-release and the right parts reset to 0 or nothing.
    """
    return self.bump_pre("a")

bump_beta ¤

bump_beta() -> PEP440Version

Bump beta-release.

Examples:

>>> PEP440Version("1").bump_beta()
ValueError: Cannot bump from release to beta pre-release (use `dent_beta`)
>>> PEP440Version("1b0").bump_beta()
<Version('1b1')>
>>> PEP440Version("1b0").bump_beta()
<Version('1b1')>
>>> PEP440Version("1b0.post0").bump_beta()
<Version('1b1')>

Returns:

  • PEP440Version

    Version with same epoch, same release, bumped beta pre-release and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
def bump_beta(self) -> PEP440Version:
    """Bump beta-release.

    Examples:
        >>> PEP440Version("1").bump_beta()
        ValueError: Cannot bump from release to beta pre-release (use `dent_beta`)
        >>> PEP440Version("1b0").bump_beta()
        <Version('1b1')>
        >>> PEP440Version("1b0").bump_beta()
        <Version('1b1')>
        >>> PEP440Version("1b0.post0").bump_beta()
        <Version('1b1')>

    Returns:
        Version with same epoch, same release, bumped beta pre-release and the right parts reset to 0 or nothing.
    """
    return self.bump_pre("b")

bump_candidate ¤

bump_candidate() -> PEP440Version

Bump candidate release.

Examples:

>>> PEP440Version("1").bump_candidate()
ValueError: Cannot bump from release to candidate pre-release (use `dent_candidate`)
>>> PEP440Version("1c0").bump_candidate()
<Version('1rc1')>
>>> PEP440Version("1c0").bump_candidate()
<Version('1rc1')>
>>> PEP440Version("1c0.post0").bump_candidate()
<Version('1rc1')>

Returns:

  • PEP440Version

    Version with same epoch, same release, bumped candidate pre-release and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
def bump_candidate(self) -> PEP440Version:
    """Bump candidate release.

    Examples:
        >>> PEP440Version("1").bump_candidate()
        ValueError: Cannot bump from release to candidate pre-release (use `dent_candidate`)
        >>> PEP440Version("1c0").bump_candidate()
        <Version('1rc1')>
        >>> PEP440Version("1c0").bump_candidate()
        <Version('1rc1')>
        >>> PEP440Version("1c0.post0").bump_candidate()
        <Version('1rc1')>

    Returns:
        Version with same epoch, same release, bumped candidate pre-release and the right parts reset to 0 or nothing.
    """
    return self.bump_pre("rc")

bump_dev ¤

bump_dev() -> PEP440Version

Bump dev-release.

Examples:

>>> PEP440Version("1").bump_dev()
ValueError: Cannot bump from release to dev-release (use `dent_dev`)
>>> PEP440Version("1a0").bump_dev()
ValueError: Cannot bump from alpha to dev-release (use `dent_dev`)
>>> PEP440Version("1b1").bump_dev()
ValueError: Cannot bump from beta to dev-release (use `dent_dev`)
>>> PEP440Version("1rc2").bump_dev()
ValueError: Cannot bump from candidate to dev-release (use `dent_dev`)
>>> PEP440Version("1.post0").bump_dev()
ValueError: Cannot bump from post to dev-release (use `dent_dev`)
>>> PEP440Version("1a0.dev1").bump_dev()
<Version('1a0.dev2')>

Returns:

  • PEP440Version

    Version with same epoch, same release, same pre-release, same post-release and bumped dev-release.

Source code in src/git_changelog/versioning.py
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
def bump_dev(self) -> PEP440Version:
    """Bump dev-release.

    Examples:
        >>> PEP440Version("1").bump_dev()
        ValueError: Cannot bump from release to dev-release (use `dent_dev`)
        >>> PEP440Version("1a0").bump_dev()
        ValueError: Cannot bump from alpha to dev-release (use `dent_dev`)
        >>> PEP440Version("1b1").bump_dev()
        ValueError: Cannot bump from beta to dev-release (use `dent_dev`)
        >>> PEP440Version("1rc2").bump_dev()
        ValueError: Cannot bump from candidate to dev-release (use `dent_dev`)
        >>> PEP440Version("1.post0").bump_dev()
        ValueError: Cannot bump from post to dev-release (use `dent_dev`)
        >>> PEP440Version("1a0.dev1").bump_dev()
        <Version('1a0.dev2')>

    Returns:
        Version with same epoch, same release, same pre-release, same post-release and bumped dev-release.
    """
    if self.dev is None:
        if self.post is not None:
            kind = "p"
        elif self.pre is not None:
            kind = self.pre[0]
        else:
            kind = "z"
        raise ValueError(f"Cannot bump from {_release_kind.get(kind, 'release')} to dev-release (use `dent_dev`)")
    return PEP440Version.from_parts(
        epoch=self.epoch,
        release=self.release,
        pre=self.pre,
        post=self.post,
        dev=self.dev + 1,
    )

bump_epoch ¤

bump_epoch() -> PEP440Version

Bump epoch.

Examples:

>>> PEP440Version("1.0").bump_epoch()
<Version('1!1.0')>
>>> PEP440Version("0!1.0").bump_epoch()
<Version('1!1.0')>
>>> PEP440Version("1!1.0").bump_epoch()
<Version('2!1.0')>
>>> PEP440Version("1.0a2.post3").bump_epoch()
<Version('2!1.0')>

Returns:

  • PEP440Version

    Version with bumped epoch, same release, and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def bump_epoch(self) -> PEP440Version:
    """Bump epoch.

    Examples:
        >>> PEP440Version("1.0").bump_epoch()
        <Version('1!1.0')>
        >>> PEP440Version("0!1.0").bump_epoch()
        <Version('1!1.0')>
        >>> PEP440Version("1!1.0").bump_epoch()
        <Version('2!1.0')>
        >>> PEP440Version("1.0a2.post3").bump_epoch()
        <Version('2!1.0')>

    Returns:
        Version with bumped epoch, same release, and the right parts reset to 0 or nothing.
    """
    return PEP440Version.from_parts(epoch=self.epoch + 1, release=self.release)

bump_major ¤

bump_major(*, trim: bool = False) -> PEP440Version

Bump major.

Parameters:

  • trim (bool, default: False ) –

    Whether to trim all zeroes on the right after bumping.

Examples:

>>> PEP440Version("1").bump_major()
<Version('2')>
>>> PEP440Version("1.1").bump_major()
<Version('2.0')>
>>> PEP440Version("1.1.1").bump_major()
<Version('2.0.0')>
>>> PEP440Version("1.1.1").bump_major(trim=True)
<Version('2')>
>>> PEP440Version("1a2.post3").bump_major()
<Version('2')>

Returns:

  • PEP440Version

    Version with same epoch, bumped major and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
def bump_major(self, *, trim: bool = False) -> PEP440Version:
    """Bump major.

    Parameters:
        trim: Whether to trim all zeroes on the right after bumping.

    Examples:
        >>> PEP440Version("1").bump_major()
        <Version('2')>
        >>> PEP440Version("1.1").bump_major()
        <Version('2.0')>
        >>> PEP440Version("1.1.1").bump_major()
        <Version('2.0.0')>
        >>> PEP440Version("1.1.1").bump_major(trim=True)
        <Version('2')>
        >>> PEP440Version("1a2.post3").bump_major()
        <Version('2')>

    Returns:
        Version with same epoch, bumped major and the right parts reset to 0 or nothing.
    """
    return self.bump_release(level=0, trim=trim)

bump_micro ¤

bump_micro(*, trim: bool = False) -> PEP440Version

Bump micro.

Parameters:

  • trim (bool, default: False ) –

    Whether to trim all zeroes on the right after bumping.

Examples:

>>> PEP440Version("1").bump_micro()
<Version('1.0.1')>
>>> PEP440Version("1.1").bump_micro()
<Version('1.1.1')>
>>> PEP440Version("1.1.1").bump_micro()
<Version('1.1.2')>
>>> PEP440Version("1.1.1").bump_micro()
<Version('1.1.2')>
>>> PEP440Version("1.1.1.1").bump_micro()
<Version('1.1.2.0')>
>>> PEP440Version("1.1.1.1").bump_micro(trim=True)
<Version('1.1.2')>
>>> PEP440Version("1a2.post3").bump_micro()
<Version('1.0.1')>

Returns:

  • PEP440Version

    Version with same epoch, same major, same minor, bumped micro and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
def bump_micro(self, *, trim: bool = False) -> PEP440Version:
    """Bump micro.

    Parameters:
        trim: Whether to trim all zeroes on the right after bumping.

    Examples:
        >>> PEP440Version("1").bump_micro()
        <Version('1.0.1')>
        >>> PEP440Version("1.1").bump_micro()
        <Version('1.1.1')>
        >>> PEP440Version("1.1.1").bump_micro()
        <Version('1.1.2')>
        >>> PEP440Version("1.1.1").bump_micro()
        <Version('1.1.2')>
        >>> PEP440Version("1.1.1.1").bump_micro()
        <Version('1.1.2.0')>
        >>> PEP440Version("1.1.1.1").bump_micro(trim=True)
        <Version('1.1.2')>
        >>> PEP440Version("1a2.post3").bump_micro()
        <Version('1.0.1')>

    Returns:
        Version with same epoch, same major, same minor, bumped micro and the right parts reset to 0 or nothing.
    """
    return self.bump_release(level=2, trim=trim)

bump_minor ¤

bump_minor(*, trim: bool = False) -> PEP440Version

Bump minor.

Parameters:

  • trim (bool, default: False ) –

    Whether to trim all zeroes on the right after bumping.

Examples:

>>> PEP440Version("1").bump_minor()
<Version('1.1')>
>>> PEP440Version("1.1").bump_minor()
<Version('1.2')>
>>> PEP440Version("1.1.1").bump_minor()
<Version('1.2.0')>
>>> PEP440Version("1.1.1").bump_minor(trim=True)
<Version('1.2')>
>>> PEP440Version("1a2.post3").bump_minor()
<Version('1.1')>

Returns:

  • PEP440Version

    Version with same epoch, same major, bumped minor and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
def bump_minor(self, *, trim: bool = False) -> PEP440Version:
    """Bump minor.

    Parameters:
        trim: Whether to trim all zeroes on the right after bumping.

    Examples:
        >>> PEP440Version("1").bump_minor()
        <Version('1.1')>
        >>> PEP440Version("1.1").bump_minor()
        <Version('1.2')>
        >>> PEP440Version("1.1.1").bump_minor()
        <Version('1.2.0')>
        >>> PEP440Version("1.1.1").bump_minor(trim=True)
        <Version('1.2')>
        >>> PEP440Version("1a2.post3").bump_minor()
        <Version('1.1')>

    Returns:
        Version with same epoch, same major, bumped minor and the right parts reset to 0 or nothing.
    """
    return self.bump_release(level=1, trim=trim)

bump_post ¤

bump_post() -> PEP440Version

Bump post-release.

Examples:

>>> PEP440Version("1").bump_post()
<Version('1.post0')>
>>> PEP440Version("1.post0").bump_post()
<Version('1.post1')>
>>> PEP440Version("1a0.post0").bump_post()
<Version('1a0.post1')>
>>> PEP440Version("1.post0.dev1").bump_post()
<Version('1.post1')>

Returns:

  • PEP440Version

    Version with same epoch, same release, same pre-release, bumped post-release and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
def bump_post(self) -> PEP440Version:
    """Bump post-release.

    Examples:
        >>> PEP440Version("1").bump_post()
        <Version('1.post0')>
        >>> PEP440Version("1.post0").bump_post()
        <Version('1.post1')>
        >>> PEP440Version("1a0.post0").bump_post()
        <Version('1a0.post1')>
        >>> PEP440Version("1.post0.dev1").bump_post()
        <Version('1.post1')>

    Returns:
        Version with same epoch, same release, same pre-release, bumped post-release and the right parts reset to 0 or nothing.
    """
    post = 0 if self.post is None else self.post + 1
    return PEP440Version.from_parts(epoch=self.epoch, release=self.release, pre=self.pre, post=post)

bump_pre ¤

bump_pre(
    pre: Literal["a", "b", "c", "rc"] | None = None
) -> PEP440Version

Bump pre-release.

Parameters:

  • pre (Literal['a', 'b', 'c', 'rc'] | None, default: None ) –

    Kind of pre-release to bump.

    • a means alpha
    • b means beta
    • c or rc means (release) candidate

Examples:

>>> PEP440Version("1").bump_pre()
ValueError: Cannot bump from release to alpha pre-release (use `dent_pre`)
>>> PEP440Version("1a0").bump_pre()
<Version('1a1')>
>>> PEP440Version("1a0").bump_pre("a")
<Version('1a1')>
>>> PEP440Version("1a0.post0").bump_pre()
<Version('1a1')>
>>> PEP440Version("1b2").bump_pre("a")
ValueError: Cannot bump from beta to alpha pre-release (use `dent_alpha`)
>>> PEP440Version("1c2").bump_pre("a")
ValueError: Cannot bump from candidate to alpha pre-release (use `dent_alpha`)
>>> PEP440Version("1").bump_pre("b")
ValueError: Cannot bump from release to beta pre-release (use `dent_beta`)
>>> PEP440Version("1a2").bump_pre("b")
<Version('1b0')>
>>> PEP440Version("1b2").bump_pre("b")
<Version('1b3')>
>>> PEP440Version("1c2").bump_pre("b")
ValueError: Cannot bump from candidate to beta pre-release (use `dent_beta`)
>>> PEP440Version("1").bump_pre("c")
ValueError: Cannot bump from release to candidate pre-release (use `dent_candidate`)
>>> PEP440Version("1a2").bump_pre("c")
<Version('1rc0')>
>>> PEP440Version("1b2").bump_pre("rc")
<Version('1rc0')>
>>> PEP440Version("1rc2").bump_pre("c")
<Version('1rc3')>

Returns:

  • PEP440Version

    Version with same epoch, same release, bumped pre-release and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
def bump_pre(self, pre: Literal["a", "b", "c", "rc"] | None = None) -> PEP440Version:
    """Bump pre-release.

    Parameters:
        pre: Kind of pre-release to bump.

            - a means alpha
            - b means beta
            - c or rc means (release) candidate

    Examples:
        >>> PEP440Version("1").bump_pre()
        ValueError: Cannot bump from release to alpha pre-release (use `dent_pre`)
        >>> PEP440Version("1a0").bump_pre()
        <Version('1a1')>
        >>> PEP440Version("1a0").bump_pre("a")
        <Version('1a1')>
        >>> PEP440Version("1a0.post0").bump_pre()
        <Version('1a1')>
        >>> PEP440Version("1b2").bump_pre("a")
        ValueError: Cannot bump from beta to alpha pre-release (use `dent_alpha`)
        >>> PEP440Version("1c2").bump_pre("a")
        ValueError: Cannot bump from candidate to alpha pre-release (use `dent_alpha`)

        >>> PEP440Version("1").bump_pre("b")
        ValueError: Cannot bump from release to beta pre-release (use `dent_beta`)
        >>> PEP440Version("1a2").bump_pre("b")
        <Version('1b0')>
        >>> PEP440Version("1b2").bump_pre("b")
        <Version('1b3')>
        >>> PEP440Version("1c2").bump_pre("b")
        ValueError: Cannot bump from candidate to beta pre-release (use `dent_beta`)

        >>> PEP440Version("1").bump_pre("c")
        ValueError: Cannot bump from release to candidate pre-release (use `dent_candidate`)
        >>> PEP440Version("1a2").bump_pre("c")
        <Version('1rc0')>
        >>> PEP440Version("1b2").bump_pre("rc")
        <Version('1rc0')>
        >>> PEP440Version("1rc2").bump_pre("c")
        <Version('1rc3')>

    Returns:
        Version with same epoch, same release, bumped pre-release and the right parts reset to 0 or nothing.
    """
    if self.pre is None:
        kind = _release_kind.get(pre, "")  # type: ignore[arg-type]
        raise ValueError(
            f"Cannot bump from release to {kind + ' ' if kind else ''}pre-release (use `dent_{kind or 'pre'}`)",
        )
    current_pre: Literal["a", "b", "c", "rc"]
    current_pre, number = self.pre  # type: ignore[assignment]
    if pre is None:
        pre = current_pre
    if pre == current_pre:
        number += 1
    elif current_pre < pre:
        number = 0
    else:
        raise ValueError(
            f"Cannot bump from {_release_kind.get(current_pre, 'release')} to {_release_kind[pre]} pre-release (use `dent_{_release_kind[pre]}`)",
        )
    return PEP440Version.from_parts(epoch=self.epoch, release=self.release, pre=(pre, number))

bump_release ¤

bump_release(
    level: int | None = None, *, trim: bool = False
) -> PEP440Version

Bump given release level.

Parameters:

  • level (int | None, default: None ) –

    The release level to bump.

    • 0 means major
    • 1 means minor
    • 2 means micro (patch)
    • 3+ don't have names
    • None means move from pre-release to release (unchanged)
  • trim (bool, default: False ) –

    Whether to trim all zeroes on the right after bumping.

Examples:

>>> PEP440Version("1").bump_release(0)
<Version('2')>
>>> PEP440Version("1.1").bump_release(0)
<Version('2.0')>
>>> PEP440Version("1.1.1").bump_release(0)
<Version('2.0.0')>
>>> PEP440Version("1.1.1").bump_release(0, trim=True)
<Version('2')>
>>> PEP440Version("1a2.post3").bump_release(0)
<Version('2')>
>>> PEP440Version("1").bump_release(1)
<Version('1.1')>
>>> PEP440Version("1.1").bump_release(1)
<Version('1.2')>
>>> PEP440Version("1.1.1").bump_release(1)
<Version('1.2.0')>
>>> PEP440Version("1.1.1").bump_release(1, trim=True)
<Version('1.2')>
>>> PEP440Version("1a2.post3").bump_release(1)
<Version('1.1')>
>>> PEP440Version("1a0").bump_release()
<Version('1')>
>>> PEP440Version("1b1").bump_release()
<Version('1')>
>>> PEP440Version("1rc2").bump_release()
<Version('1')>
>>> PEP440Version("1a2.dev0").bump_release()
<Version('1')>
>>> PEP440Version("1post0").bump_release()
ValueError: Cannot bump from post-release to release

Returns:

  • PEP440Version

    Version with same epoch, bumped release level, and the right parts reset to 0 or nothing.

Source code in src/git_changelog/versioning.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
def bump_release(self, level: int | None = None, *, trim: bool = False) -> PEP440Version:
    """Bump given release level.

    Parameters:
        level: The release level to bump.

            - 0 means major
            - 1 means minor
            - 2 means micro (patch)
            - 3+ don't have names
            - None means move from pre-release to release (unchanged)
        trim: Whether to trim all zeroes on the right after bumping.

    Examples:
        >>> PEP440Version("1").bump_release(0)
        <Version('2')>
        >>> PEP440Version("1.1").bump_release(0)
        <Version('2.0')>
        >>> PEP440Version("1.1.1").bump_release(0)
        <Version('2.0.0')>
        >>> PEP440Version("1.1.1").bump_release(0, trim=True)
        <Version('2')>
        >>> PEP440Version("1a2.post3").bump_release(0)
        <Version('2')>

        >>> PEP440Version("1").bump_release(1)
        <Version('1.1')>
        >>> PEP440Version("1.1").bump_release(1)
        <Version('1.2')>
        >>> PEP440Version("1.1.1").bump_release(1)
        <Version('1.2.0')>
        >>> PEP440Version("1.1.1").bump_release(1, trim=True)
        <Version('1.2')>
        >>> PEP440Version("1a2.post3").bump_release(1)
        <Version('1.1')>

        >>> PEP440Version("1a0").bump_release()
        <Version('1')>
        >>> PEP440Version("1b1").bump_release()
        <Version('1')>
        >>> PEP440Version("1rc2").bump_release()
        <Version('1')>
        >>> PEP440Version("1a2.dev0").bump_release()
        <Version('1')>
        >>> PEP440Version("1post0").bump_release()
        ValueError: Cannot bump from post-release to release

    Returns:
        Version with same epoch, bumped release level, and the right parts reset to 0 or nothing.
    """
    release = list(self.release)

    # When level is not specified, user wants to bump the version
    # as a "release", going out of alpha/beta/candidate phase.
    # So we simply keep the release part as it is, optionally trimming it.
    if level is None:
        # However if this is a post-release, this is an error:
        # we can't bump from a post-release to the same, regular release.
        if self.post is not None:
            raise ValueError("Cannot bump from post-release to release")
        if trim:
            while release[-1] == 0:
                release.pop()

    # When level is specified, we bump the specified level.
    # If the given level is higher that the number of release parts,
    # we insert the missing parts as 0.
    else:
        try:
            release[level] += 1
        except IndexError:
            while len(release) < level:
                release.append(0)
            release.append(1)
        if trim:
            release = release[: level + 1]
        else:
            for index in range(level + 1, len(release)):
                release[index] = 0

    # We rebuild the version with same epoch, updated release,
    # and pre/post/dev parts dropped.
    return PEP440Version.from_parts(epoch=self.epoch, release=tuple(release))

dent_alpha ¤

dent_alpha() -> PEP440Version

Dent to alpha-release.

Examples:

>>> PEP440Version("1").dent_alpha()
<Version('1a0')>
>>> PEP440Version("1a0").dent_alpha()
ValueError: Cannot dent alpha pre-releases
>>> PEP440Version("1b0").dent_alpha()
ValueError: Cannot dent beta pre-releases
>>> PEP440Version("1rc0").dent_alpha()
ValueError: Cannot dent candidate pre-releases

Returns:

  • PEP440Version

    Version with same epoch and release dented to alpha pre-release.

Source code in src/git_changelog/versioning.py
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
def dent_alpha(self) -> PEP440Version:
    """Dent to alpha-release.

    Examples:
        >>> PEP440Version("1").dent_alpha()
        <Version('1a0')>
        >>> PEP440Version("1a0").dent_alpha()
        ValueError: Cannot dent alpha pre-releases
        >>> PEP440Version("1b0").dent_alpha()
        ValueError: Cannot dent beta pre-releases
        >>> PEP440Version("1rc0").dent_alpha()
        ValueError: Cannot dent candidate pre-releases

    Returns:
        Version with same epoch and release dented to alpha pre-release.
    """
    return self.dent_pre("a")

dent_beta ¤

dent_beta() -> PEP440Version

Dent to beta-release.

Examples:

>>> PEP440Version("1").dent_beta()
<Version('1b0')>
>>> PEP440Version("1a0").dent_beta()
ValueError: Cannot dent alpha pre-releases
>>> PEP440Version("1b0").dent_beta()
ValueError: Cannot dent beta pre-releases
>>> PEP440Version("1rc0").dent_beta()
ValueError: Cannot dent candidate pre-releases

Returns:

  • PEP440Version

    Version with same epoch and release dented to beta pre-release.

Source code in src/git_changelog/versioning.py
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
def dent_beta(self) -> PEP440Version:
    """Dent to beta-release.

    Examples:
        >>> PEP440Version("1").dent_beta()
        <Version('1b0')>
        >>> PEP440Version("1a0").dent_beta()
        ValueError: Cannot dent alpha pre-releases
        >>> PEP440Version("1b0").dent_beta()
        ValueError: Cannot dent beta pre-releases
        >>> PEP440Version("1rc0").dent_beta()
        ValueError: Cannot dent candidate pre-releases

    Returns:
        Version with same epoch and release dented to beta pre-release.
    """
    return self.dent_pre("b")

dent_candidate ¤

dent_candidate() -> PEP440Version

Dent to candidate release.

Examples:

>>> PEP440Version("1").dent_candidate()
<Version('1rc0')>
>>> PEP440Version("1a0").dent_candidate()
ValueError: Cannot dent alpha pre-releases
>>> PEP440Version("1b0").dent_candidate()
ValueError: Cannot dent beta pre-releases
>>> PEP440Version("1rc0").dent_candidate()
ValueError: Cannot dent candidate pre-releases

Returns:

  • PEP440Version

    Version with same epoch and release dented to candidate pre-release.

Source code in src/git_changelog/versioning.py
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
def dent_candidate(self) -> PEP440Version:
    """Dent to candidate release.

    Examples:
        >>> PEP440Version("1").dent_candidate()
        <Version('1rc0')>
        >>> PEP440Version("1a0").dent_candidate()
        ValueError: Cannot dent alpha pre-releases
        >>> PEP440Version("1b0").dent_candidate()
        ValueError: Cannot dent beta pre-releases
        >>> PEP440Version("1rc0").dent_candidate()
        ValueError: Cannot dent candidate pre-releases

    Returns:
        Version with same epoch and release dented to candidate pre-release.
    """
    return self.dent_pre("rc")

dent_dev ¤

dent_dev() -> PEP440Version

Dent to dev-release.

Examples:

>>> PEP440Version("1").dent_dev()
<Version('1.dev0')>
>>> PEP440Version("1a0").dent_dev()
<Version('1a0.dev0')>
>>> PEP440Version("1b1").dent_dev()
<Version('1b1.dev0')>
>>> PEP440Version("1c2").dent_dev()
<Version('1rc2.dev0')>
>>> PEP440Version("1.post0").dent_dev()
<Version('1.post0.dev0')>
>>> PEP440Version("1a0.dev1").dent_dev()
ValueError: Cannot dent dev-releases

Returns:

  • PEP440Version

    Version with same epoch and release dented to dev-release.

Source code in src/git_changelog/versioning.py
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
def dent_dev(self) -> PEP440Version:
    """Dent to dev-release.

    Examples:
        >>> PEP440Version("1").dent_dev()
        <Version('1.dev0')>
        >>> PEP440Version("1a0").dent_dev()
        <Version('1a0.dev0')>
        >>> PEP440Version("1b1").dent_dev()
        <Version('1b1.dev0')>
        >>> PEP440Version("1c2").dent_dev()
        <Version('1rc2.dev0')>
        >>> PEP440Version("1.post0").dent_dev()
        <Version('1.post0.dev0')>
        >>> PEP440Version("1a0.dev1").dent_dev()
        ValueError: Cannot dent dev-releases

    Returns:
        Version with same epoch and release dented to dev-release.
    """
    if self.dev is not None:
        raise ValueError("Cannot dent dev-releases")
    return PEP440Version.from_parts(epoch=self.epoch, release=self.release, pre=self.pre, post=self.post, dev=0)

dent_pre ¤

dent_pre(
    pre: Literal["a", "b", "c", "rc"] | None = None
) -> PEP440Version

Dent to pre-release.

This method dents a release down to an alpha, beta or candidate pre-release.

Parameters:

  • pre (Literal['a', 'b', 'c', 'rc'] | None, default: None ) –

    Kind of pre-release to bump.

    • a means alpha
    • b means beta
    • c or rc means (release) candidate

Examples:

>>> PEP440Version("1").dent_pre()
<Version('1a0')>
>>> PEP440Version("1").dent_pre("a")
<Version('1a0')>
>>> PEP440Version("1a0").dent_pre("a")
ValueError: Cannot dent alpha pre-releases
>>> PEP440Version("1").dent_pre("b")
<Version('1b0')>
>>> PEP440Version("1b0").dent_pre("b")
ValueError: Cannot dent beta pre-releases
>>> PEP440Version("1").dent_pre("c")
<Version('1rc0')>
>>> PEP440Version("1").dent_pre("rc")
<Version('1rc0')>
>>> PEP440Version("1rc0").dent_pre("c")
ValueError: Cannot dent candidate pre-releases

Returns:

  • PEP440Version

    Version with same epoch and release dented to pre-release.

Source code in src/git_changelog/versioning.py
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
def dent_pre(self, pre: Literal["a", "b", "c", "rc"] | None = None) -> PEP440Version:
    """Dent to pre-release.

    This method dents a release down to an alpha, beta or candidate pre-release.

    Parameters:
        pre: Kind of pre-release to bump.

            - a means alpha
            - b means beta
            - c or rc means (release) candidate

    Examples:
        >>> PEP440Version("1").dent_pre()
        <Version('1a0')>
        >>> PEP440Version("1").dent_pre("a")
        <Version('1a0')>
        >>> PEP440Version("1a0").dent_pre("a")
        ValueError: Cannot dent alpha pre-releases
        >>> PEP440Version("1").dent_pre("b")
        <Version('1b0')>
        >>> PEP440Version("1b0").dent_pre("b")
        ValueError: Cannot dent beta pre-releases
        >>> PEP440Version("1").dent_pre("c")
        <Version('1rc0')>
        >>> PEP440Version("1").dent_pre("rc")
        <Version('1rc0')>
        >>> PEP440Version("1rc0").dent_pre("c")
        ValueError: Cannot dent candidate pre-releases

    Returns:
        Version with same epoch and release dented to pre-release.
    """
    if self.pre is not None:
        raise ValueError(f"Cannot dent {_release_kind[self.pre[0]]} pre-releases")
    if pre is None:
        pre = "a"
    return PEP440Version.from_parts(epoch=self.epoch, release=self.release, pre=(pre, 0))

from_parts classmethod ¤

from_parts(
    epoch: int | None = None,
    release: tuple[int, ...] | None = None,
    pre: tuple[str, int] | None = None,
    post: int | None = None,
    dev: int | None = None,
) -> PEP440Version

Build a version from its parts.

Parameters:

  • epoch (int | None, default: None ) –

    Version's epoch number.

  • release (tuple[int, ...] | None, default: None ) –

    Version's release numbers.

  • pre (tuple[str, int] | None, default: None ) –

    Version's prerelease kind and number.

  • post (int | None, default: None ) –

    Version's post number.

  • dev (int | None, default: None ) –

    Version's dev number.

Returns:

Source code in src/git_changelog/versioning.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
@classmethod
def from_parts(
    cls,
    epoch: int | None = None,
    release: tuple[int, ...] | None = None,
    pre: tuple[str, int] | None = None,
    post: int | None = None,
    dev: int | None = None,
) -> PEP440Version:
    """Build a version from its parts.

    Parameters:
        epoch: Version's epoch number.
        release: Version's release numbers.
        pre: Version's prerelease kind and number.
        post: Version's post number.
        dev: Version's dev number.

    Returns:
        A PEP 440 version.
    """
    # Since the original class only allows instantiating a version
    # by passing a string, we first create a dummy version "1"
    # and then re-assign its internal `_version` with the real one.
    version = cls("1")
    version._version = packaging_version._Version(
        epoch=epoch or 0,
        release=release or (),
        pre=pre,
        post=None if post is None else ("post", post),
        dev=None if dev is None else ("dev", dev),
        local=None,
    )

    # We also have to update its `_key` attribute.
    # This is a hack and I would prefer that such functionality
    # is exposed directly in the original class.
    version._key = packaging_version._cmpkey(
        version._version.epoch,
        version._version.release,
        version._version.pre,
        version._version.post,
        version._version.dev,
        version._version.local,
    )

    return version

ParsedVersion ¤

Bases: Protocol

Base class for versioning schemes.

SemVerBumper ¤

SemVerBumper(strategies: tuple[str, ...])

Bases: VersionBumper

SemVer version bumper.

Parameters:

  • strategies (tuple[str, ...]) –

    The supported bumping strategies.

Source code in src/git_changelog/versioning.py
650
651
652
653
654
655
656
def __init__(self, strategies: tuple[str, ...]) -> None:
    """Initialize the bumper.

    Parameters:
        strategies: The supported bumping strategies.
    """
    self.strategies = strategies

SemVerVersion ¤

Bases: Version, ParsedVersion

SemVer version.

Methods:

  • bump_release

    Bump from a pre-release to the same, regular release.

bump_release ¤

bump_release() -> SemVerVersion

Bump from a pre-release to the same, regular release.

Returns:

  • SemVerVersion

    The same version, without pre-release or build metadata.

Source code in src/git_changelog/versioning.py
82
83
84
85
86
87
88
def bump_release(self) -> SemVerVersion:
    """Bump from a pre-release to the same, regular release.

    Returns:
        The same version, without pre-release or build metadata.
    """
    return SemVerVersion(self.major, self.minor, self.patch)

VersionBumper ¤

VersionBumper(strategies: tuple[str, ...])

Base class for version bumpers.

Parameters:

  • strategies (tuple[str, ...]) –

    The supported bumping strategies.

Source code in src/git_changelog/versioning.py
650
651
652
653
654
655
656
def __init__(self, strategies: tuple[str, ...]) -> None:
    """Initialize the bumper.

    Parameters:
        strategies: The supported bumping strategies.
    """
    self.strategies = strategies

parse_pep440 ¤

parse_pep440(version: str) -> tuple[PEP440Version, str]

Parse a PEP version.

Returns:

Source code in src/git_changelog/versioning.py
635
636
637
638
639
640
641
642
def parse_pep440(version: str) -> tuple[PEP440Version, str]:
    """Parse a PEP version.

    Returns:
        A PEP 440 version instance with useful methods.
    """
    version, prefix = version_prefix(version)
    return PEP440Version(version), prefix

parse_semver ¤

parse_semver(version: str) -> tuple[SemVerVersion, str]

Parse a SemVer version.

Returns:

Source code in src/git_changelog/versioning.py
625
626
627
628
629
630
631
632
def parse_semver(version: str) -> tuple[SemVerVersion, str]:
    """Parse a SemVer version.

    Returns:
        A semver version instance with useful methods.
    """
    version, prefix = version_prefix(version)
    return SemVerVersion.parse(version), prefix

version_prefix ¤

version_prefix(version: str) -> tuple[str, str]

Return a version and its optional v prefix.

Parameters:

  • version (str) –

    The full version.

Returns:

  • version ( str ) –

    The version without its prefix.

  • prefix ( str ) –

    The version prefix.

Source code in src/git_changelog/versioning.py
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
def version_prefix(version: str) -> tuple[str, str]:
    """Return a version and its optional `v` prefix.

    Arguments:
        version: The full version.

    Returns:
        version: The version without its prefix.
        prefix: The version prefix.
    """
    prefix = ""
    if version[0] == "v":
        prefix = "v"
        version = version[1:]
    return version, prefix