mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
formatting for new style versions
This commit is contained in:
parent
f21c0f1d0f
commit
b07edc9c8a
12 changed files with 288 additions and 261 deletions
36
README.md
36
README.md
|
|
@ -90,7 +90,7 @@ Exiting because of '--dry'. Would have written to pycalver.toml:
|
||||||
|
|
||||||
[pycalver]
|
[pycalver]
|
||||||
current_version = "v202010.1001-alpha"
|
current_version = "v202010.1001-alpha"
|
||||||
version_pattern = "vYYYY0M.BUILD[-TAG]"
|
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
commit_message = "bump version to {new_version}"
|
commit_message = "bump version to {new_version}"
|
||||||
commit = true
|
commit = true
|
||||||
tag = true
|
tag = true
|
||||||
|
|
@ -125,7 +125,7 @@ This will add the something like the following to your `setup.cfg`
|
||||||
# setup.cfg
|
# setup.cfg
|
||||||
[pycalver]
|
[pycalver]
|
||||||
current_version = "v201902.1001-alpha"
|
current_version = "v201902.1001-alpha"
|
||||||
version_pattern = "vYYYY0M.BUILD[-TAG]"
|
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
commit_message = "bump version to {new_version}"
|
commit_message = "bump version to {new_version}"
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
|
|
@ -238,7 +238,7 @@ These patterns are closely based on https://calver.org/
|
||||||
| `00J` | 001, 002..366 | `%j` |
|
| `00J` | 001, 002..366 | `%j` |
|
||||||
| `BUILD` | 0011, 1001, 1002, .. | build number (lexid) |
|
| `BUILD` | 0011, 1001, 1002, .. | build number (lexid) |
|
||||||
| `BLD` | 11, 1001, 1002, .. | zero truncated `BUILD` |
|
| `BLD` | 11, 1001, 1002, .. | zero truncated `BUILD` |
|
||||||
| `TAG` | alpha, beta, rc | `--release=<tag>` |
|
| `RELEASE` | alpha, beta, rc | `--release=<tag>` |
|
||||||
| `PYTAG` | a, b, rc | `--release=<tag>` |
|
| `PYTAG` | a, b, rc | `--release=<tag>` |
|
||||||
| `NUM` | 0, 1, 2... | release tag number |
|
| `NUM` | 0, 1, 2... | release tag number |
|
||||||
| `MAJOR` | 0..9, 10..99, 100.. | `--major` |
|
| `MAJOR` | 0..9, 10..99, 100.. | `--major` |
|
||||||
|
|
@ -280,7 +280,7 @@ According to these rules:
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
- Pattern: `vYY.0M.0D[-TAG]`
|
- Pattern: `vYY.0M.0D[-RELEASE]`
|
||||||
- Version: `v20.08.02-beta`
|
- Version: `v20.08.02-beta`
|
||||||
- PEP440 : `20.8.2b0`
|
- PEP440 : `20.8.2b0`
|
||||||
|
|
||||||
|
|
@ -299,15 +299,15 @@ If you wish to avoid this, you should use a pattern which maintains lexiographic
|
||||||
|
|
||||||
|
|
||||||
| pattern | example | lexio. | PEP440 | lexio. |
|
| pattern | example | lexio. | PEP440 | lexio. |
|
||||||
|-----------------------|---------|--------|--------|--------|
|
|---------------------------|---------|--------|--------|--------|
|
||||||
| `YYYY0M.BUILD[-TAG]` | | yes | | yes |
|
| `YYYY0M.BUILD[-RELEASE]` | | yes | | yes |
|
||||||
| `YYYY.BUILD[-TAG]` | | yes | | yes |
|
| `YYYY.BUILD[-RELEASE]` | | yes | | yes |
|
||||||
| `YYYY0M.MINOR[-TAG]` | | yes² | | yes |
|
| `YYYY0M.MINOR[-RELEASE]` | | yes² | | yes |
|
||||||
| `YY0M.BUILD[-TAG]` | | yes¹ | | yes¹ |
|
| `YY0M.BUILD[-RELEASE]` | | yes¹ | | yes¹ |
|
||||||
| `YYYY.MM.MINOR[-TAG]` | | no | | no |
|
| `YYYY.MM.MINOR[-RELEASE]` | | no | | no |
|
||||||
| `YYYY.0M.MINOR[-TAG]` | | yes² | | no |
|
| `YYYY.0M.MINOR[-RELEASE]` | | yes² | | no |
|
||||||
| `YYYY.WW.MINOR[-TAG]` | | no | | no |
|
| `YYYY.WW.MINOR[-RELEASE]` | | no | | no |
|
||||||
| `YYYY.0W.MINOR[-TAG]` | | yes² | | no |
|
| `YYYY.0W.MINOR[-RELEASE]` | | yes² | | no |
|
||||||
| `YYYY.0M.0D` | | yes | | no |
|
| `YYYY.0M.0D` | | yes | | no |
|
||||||
| `YYYY.MM.DD` | | no | | no |
|
| `YYYY.MM.DD` | | no | | no |
|
||||||
| `vYYYY.0W` | | yes | | no |
|
| `vYYYY.0W` | | yes | | no |
|
||||||
|
|
@ -427,15 +427,15 @@ $ pycalver test 'v18.1.2' 'vYY.MINOR.PATCH' --minor
|
||||||
New Version: v19.2.0
|
New Version: v19.2.0
|
||||||
PEP440 : 19.2.0
|
PEP440 : 19.2.0
|
||||||
|
|
||||||
$ pycalver test 'v201811.1051-beta' 'vYYYYMM.BUILD[-TAG]'
|
$ pycalver test 'v201811.1051-beta' 'vYYYYMM.BUILD[-RELEASE]'
|
||||||
New Version: v201902.1052-beta
|
New Version: v201902.1052-beta
|
||||||
PEP440 : 201902.1052b0
|
PEP440 : 201902.1052b0
|
||||||
|
|
||||||
$ pycalver test 'v201811.0051-beta' 'vYYYYMM.BUILD[-TAG]' --release rc
|
$ pycalver test 'v201811.0051-beta' 'vYYYYMM.BUILD[-RELEASE]' --release rc
|
||||||
New Version: v201902.1052-rc
|
New Version: v201902.1052-rc
|
||||||
PEP440 : 201902.1052rc0
|
PEP440 : 201902.1052rc0
|
||||||
|
|
||||||
$ pycalver test 'v201811.0051-beta' 'vYYYYMM.BUILD[-TAG]' --release final
|
$ pycalver test 'v201811.0051-beta' 'vYYYYMM.BUILD[-RELEASE]' --release final
|
||||||
New Version: v201902.1052
|
New Version: v201902.1052
|
||||||
PEP440 : 201902.1052
|
PEP440 : 201902.1052
|
||||||
```
|
```
|
||||||
|
|
@ -509,7 +509,7 @@ section:
|
||||||
```ini
|
```ini
|
||||||
[pycalver]
|
[pycalver]
|
||||||
current_version = "v202010.1006-beta"
|
current_version = "v202010.1006-beta"
|
||||||
version_pattern = "vYYYY0M.BUILD[-TAG]"
|
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
commit_message = "bump version to {new_version}"
|
commit_message = "bump version to {new_version}"
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
|
|
@ -549,7 +549,7 @@ $ pycalver bump --dry
|
||||||
[pycalver]
|
[pycalver]
|
||||||
-current_version = v202010.1005-beta
|
-current_version = v202010.1005-beta
|
||||||
+current_version = v202010.1006-beta
|
+current_version = v202010.1006-beta
|
||||||
version_pattern = "vYYYY0M.BUILD[-TAG]"
|
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
commit_message = "bump version to {new_version}"
|
commit_message = "bump version to {new_version}"
|
||||||
commit = True
|
commit = True
|
||||||
...
|
...
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ The recommended approach to using `pylint-ignore` is:
|
||||||
|
|
||||||
# Overview
|
# Overview
|
||||||
|
|
||||||
- [E1123: unexpected-keyword-arg (1x)](#e1123-unexpected-keyword-arg)
|
|
||||||
- [W0511: fixme (9x)](#w0511-fixme)
|
- [W0511: fixme (9x)](#w0511-fixme)
|
||||||
- [W0703: broad-except (1x)](#w0703-broad-except)
|
- [W0703: broad-except (1x)](#w0703-broad-except)
|
||||||
|
|
||||||
|
|
@ -74,8 +73,8 @@ The recommended approach to using `pylint-ignore` is:
|
||||||
154: assert "setup.py" in cfg.file_patterns
|
154: assert "setup.py" in cfg.file_patterns
|
||||||
155: assert "setup.cfg" in cfg.file_patterns
|
155: assert "setup.cfg" in cfg.file_patterns
|
||||||
> 156: # TODO (mb 2020-09-18):
|
> 156: # TODO (mb 2020-09-18):
|
||||||
157: # assert cfg.file_patterns["setup.py" ] == ["vYYYY0M.BUILD[-TAG]", "YYYY0M.BLD[PYTAGNUM]"]
|
157: # assert cfg.file_patterns["setup.py" ] == ["vYYYY0M.BUILD[-RELEASE]", "YYYY0M.BLD[PYTAGNUM]"]
|
||||||
158: # assert cfg.file_patterns["setup.cfg" ] == ['current_version = "vYYYY0M.BUILD[-TAG]"']
|
158: # assert cfg.file_patterns["setup.cfg" ] == ['current_version = "vYYYY0M.BUILD[-RELEASE]"']
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -96,71 +95,54 @@ The recommended approach to using `pylint-ignore` is:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## File src/pycalver/v1patterns.py - Line 212 - W0511 (fixme)
|
## File src/pycalver/v1patterns.py - Line 214 - W0511 (fixme)
|
||||||
|
|
||||||
- `message: TODO (mb 2020-09-19): replace {version} etc with version_pattern`
|
- `message: TODO (mb 2020-09-19): replace {version} etc with version_pattern`
|
||||||
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
||||||
- `date : 2020-09-19T16:24:10`
|
- `date : 2020-09-19T16:24:10`
|
||||||
|
|
||||||
```
|
```
|
||||||
199: def _compile_pattern_re(version_pattern: str, raw_pattern: str) -> typ.Pattern[str]:
|
201: def _compile_pattern_re(version_pattern: str, raw_pattern: str) -> typ.Pattern[str]:
|
||||||
...
|
...
|
||||||
210: escaped_pattern = escaped_pattern.replace(char, escaped)
|
212: escaped_pattern = escaped_pattern.replace(char, escaped)
|
||||||
211:
|
213:
|
||||||
> 212: # TODO (mb 2020-09-19): replace {version} etc with version_pattern
|
> 214: # TODO (mb 2020-09-19): replace {version} etc with version_pattern
|
||||||
213: pattern_str = _replace_pattern_parts(escaped_pattern)
|
215: pattern_str = _replace_pattern_parts(escaped_pattern)
|
||||||
214: return re.compile(pattern_str)
|
216: return re.compile(pattern_str)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## File src/pycalver/__main__.py - Line 247 - W0511 (fixme)
|
## File src/pycalver/__main__.py - Line 250 - W0511 (fixme)
|
||||||
|
|
||||||
- `message: TODO (mb 2020-09-18): Investigate error messages`
|
- `message: TODO (mb 2020-09-18): Investigate error messages`
|
||||||
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
||||||
- `date : 2020-09-19T16:24:10`
|
- `date : 2020-09-19T16:24:10`
|
||||||
|
|
||||||
```
|
```
|
||||||
219: def _bump(
|
222: def _bump(
|
||||||
...
|
...
|
||||||
245: sys.exit(1)
|
248: sys.exit(1)
|
||||||
246: except Exception as ex:
|
249: except Exception as ex:
|
||||||
> 247: # TODO (mb 2020-09-18): Investigate error messages
|
> 250: # TODO (mb 2020-09-18): Investigate error messages
|
||||||
248: logger.error(str(ex))
|
251: logger.error(str(ex))
|
||||||
249: sys.exit(1)
|
252: sys.exit(1)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## File src/pycalver/v2patterns.py - Line 256 - W0511 (fixme)
|
## File src/pycalver/config.py - Line 273 - W0511 (fixme)
|
||||||
|
|
||||||
- `message: TODO (mb 2020-09-19): replace {version} etc with version_pattern`
|
|
||||||
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
|
||||||
- `date : 2020-09-19T16:24:10`
|
|
||||||
|
|
||||||
```
|
|
||||||
240: def _compile_pattern_re(version_pattern: str, raw_pattern: str) -> typ.Pattern[str]:
|
|
||||||
...
|
|
||||||
254: print("<<<<", (normalized_pattern,))
|
|
||||||
255:
|
|
||||||
> 256: # TODO (mb 2020-09-19): replace {version} etc with version_pattern
|
|
||||||
257: pattern_str = _replace_pattern_parts(escaped_pattern)
|
|
||||||
258: return re.compile(pattern_str)
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## File src/pycalver/config.py - Line 264 - W0511 (fixme)
|
|
||||||
|
|
||||||
- `message: TODO (mb 2020-09-18): Validate Pattern`
|
- `message: TODO (mb 2020-09-18): Validate Pattern`
|
||||||
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
||||||
- `date : 2020-09-18T19:04:06`
|
- `date : 2020-09-18T19:04:06`
|
||||||
|
|
||||||
```
|
```
|
||||||
250: def _parse_config(raw_cfg: RawConfig) -> Config:
|
251: def _parse_config(raw_cfg: RawConfig) -> Config:
|
||||||
...
|
...
|
||||||
262: is_new_pattern = "{" not in version_pattern and "}" not in version_pattern
|
271: )
|
||||||
263:
|
272:
|
||||||
> 264: # TODO (mb 2020-09-18): Validate Pattern
|
> 273: # TODO (mb 2020-09-18): Validate Pattern
|
||||||
265: # detect YY with WW or UU -> suggest GG with VV
|
274: # detect YY with WW or UU -> suggest GG with VV
|
||||||
266: # detect YYMM -> suggest YY0M
|
275: # detect YYMM -> suggest YY0M
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -178,22 +160,39 @@ The recommended approach to using `pylint-ignore` is:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## File src/pycalver/v2version.py - Line 551 - W0511 (fixme)
|
||||||
|
|
||||||
|
- `message: TODO (mb 2020-09-20): New Rollover Behaviour:`
|
||||||
|
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
||||||
|
- `date : 2020-09-20T17:36:38`
|
||||||
|
|
||||||
|
```
|
||||||
|
508: def incr(
|
||||||
|
...
|
||||||
|
549: cur_vinfo = cur_vinfo._replace(patch=cur_vinfo.patch + 1)
|
||||||
|
550:
|
||||||
|
> 551: # TODO (mb 2020-09-20): New Rollover Behaviour:
|
||||||
|
552: # Reset major, minor, patch to zero if any part to the left of it is incremented
|
||||||
|
553:
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
# W0703: broad-except
|
# W0703: broad-except
|
||||||
|
|
||||||
## File src/pycalver/__main__.py - Line 246 - W0703 (broad-except)
|
## File src/pycalver/__main__.py - Line 249 - W0703 (broad-except)
|
||||||
|
|
||||||
- `message: Catching too general exception Exception`
|
- `message: Catching too general exception Exception`
|
||||||
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
- `author : Manuel Barkhau <mbarkhau@gmail.com>`
|
||||||
- `date : 2020-09-05T14:30:17`
|
- `date : 2020-09-05T14:30:17`
|
||||||
|
|
||||||
```
|
```
|
||||||
219: def _bump(
|
222: def _bump(
|
||||||
...
|
...
|
||||||
244: logger.error(str(ex))
|
247: logger.error(str(ex))
|
||||||
245: sys.exit(1)
|
248: sys.exit(1)
|
||||||
> 246: except Exception as ex:
|
> 249: except Exception as ex:
|
||||||
247: # TODO (mb 2020-09-18): Investigate error messages
|
250: # TODO (mb 2020-09-18): Investigate error messages
|
||||||
248: logger.error(str(ex))
|
251: logger.error(str(ex))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
26
setup.cfg
26
setup.cfg
|
|
@ -92,28 +92,34 @@ addopts = --doctest-modules
|
||||||
|
|
||||||
|
|
||||||
[pycalver]
|
[pycalver]
|
||||||
current_version = v202007.1036
|
current_version = "v202007.1036"
|
||||||
version_pattern = "{pycalver}"
|
version_pattern = "vYYYY0M.BUILD[-RELEASE[NUM]]"
|
||||||
|
commit_message = "bump version to {new_version}"
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
push = True
|
push = True
|
||||||
|
|
||||||
[pycalver:file_patterns]
|
[pycalver:file_patterns]
|
||||||
bootstrapit.sh =
|
bootstrapit.sh =
|
||||||
PACKAGE_VERSION="{pycalver}"
|
PACKAGE_VERSION="{version}"
|
||||||
setup.cfg =
|
setup.cfg =
|
||||||
current_version = {pycalver}
|
current_version = "{version}"
|
||||||
setup.py =
|
setup.py =
|
||||||
version="{pep440_pycalver}"
|
version="{pep440_version}"
|
||||||
src/pycalver/__init__.py =
|
src/pycalver/__init__.py =
|
||||||
__version__ = "{pycalver}"
|
__version__ = "{version}"
|
||||||
src/pycalver/cli.py =
|
src/pycalver/__main__.py =
|
||||||
click.version_option(version="{pycalver}")
|
click.version_option(version="{version}")
|
||||||
|
src/pycalver*/*.py =
|
||||||
|
Copyright (c) 2018-YYYY
|
||||||
|
LICENSE =
|
||||||
|
Copyright (c) 2018-YYYY
|
||||||
|
license.header =
|
||||||
|
Copyright (c) 2018-YYYY
|
||||||
README.md =
|
README.md =
|
||||||
[PyCalVer {version}]
|
\[PyCalVer {version}\]
|
||||||
img.shields.io/static/v1.svg?label=PyCalVer&message={version}&color=blue
|
img.shields.io/static/v1.svg?label=PyCalVer&message={version}&color=blue
|
||||||
Successfully installed pycalver-{pep440_version}
|
Successfully installed pycalver-{pep440_version}
|
||||||
pycalver, version {version}
|
|
||||||
|
|
||||||
|
|
||||||
[tool:pylint]
|
[tool:pylint]
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ def _parse_field_values(field_values: FieldValues) -> version.V1VersionInfo:
|
||||||
tag = fvals.get('tag')
|
tag = fvals.get('tag')
|
||||||
if tag is None:
|
if tag is None:
|
||||||
tag = "final"
|
tag = "final"
|
||||||
tag = version.TAG_BY_PEP440_TAG.get(tag, tag)
|
tag = version.RELEASE_BY_PEP440_TAG.get(tag, tag)
|
||||||
assert tag is not None
|
assert tag is not None
|
||||||
|
|
||||||
bid = fvals['bid'] if 'bid' in fvals else "0001"
|
bid = fvals['bid'] if 'bid' in fvals else "0001"
|
||||||
|
|
@ -338,15 +338,15 @@ def format_version(vinfo: version.V1VersionInfo, raw_pattern: str) -> str:
|
||||||
|
|
||||||
kwargs: typ.Dict[str, typ.Union[str, int, None]] = vinfo._asdict()
|
kwargs: typ.Dict[str, typ.Union[str, int, None]] = vinfo._asdict()
|
||||||
|
|
||||||
tag = vinfo.tag
|
release_tag = vinfo.tag
|
||||||
if tag == 'final':
|
if release_tag == 'final':
|
||||||
kwargs['release' ] = ""
|
kwargs['release' ] = ""
|
||||||
kwargs['pep440_tag'] = ""
|
kwargs['pep440_tag'] = ""
|
||||||
else:
|
else:
|
||||||
kwargs['release' ] = "-" + tag
|
kwargs['release' ] = "-" + release_tag
|
||||||
kwargs['pep440_tag'] = version.PEP440_TAG_BY_TAG[tag] + "0"
|
kwargs['pep440_tag'] = version.PEP440_TAG_BY_RELEASE[release_tag] + "0"
|
||||||
|
|
||||||
kwargs['release_tag'] = tag
|
kwargs['release_tag'] = release_tag
|
||||||
|
|
||||||
year = vinfo.year
|
year = vinfo.year
|
||||||
if year:
|
if year:
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
"""Compose Regular Expressions from Patterns.
|
"""Compose Regular Expressions from Patterns.
|
||||||
|
|
||||||
>>> pattern = compile_pattern("vYYYY0M.BUILD[-TAG]")
|
>>> pattern = compile_pattern("vYYYY0M.BUILD[-RELEASE]")
|
||||||
>>> version_info = pattern.regexp.match("v201712.0123-alpha")
|
>>> version_info = pattern.regexp.match("v201712.0123-alpha")
|
||||||
>>> assert version_info.groupdict() == {
|
>>> assert version_info.groupdict() == {
|
||||||
... "version": "v201712.0123-alpha",
|
... "version": "v201712.0123-alpha",
|
||||||
|
|
@ -80,13 +80,13 @@ PART_PATTERNS = {
|
||||||
'VV': r"(?:5[0-3]|[1-4][0-9]|[1-9])",
|
'VV': r"(?:5[0-3]|[1-4][0-9]|[1-9])",
|
||||||
'0V': r"(?:5[0-3]|[1-4][0-9]|0[1-9])",
|
'0V': r"(?:5[0-3]|[1-4][0-9]|0[1-9])",
|
||||||
# non calver parts
|
# non calver parts
|
||||||
'MAJOR': r"[0-9]+",
|
'MAJOR' : r"[0-9]+",
|
||||||
'MINOR': r"[0-9]+",
|
'MINOR' : r"[0-9]+",
|
||||||
'PATCH': r"[0-9]+",
|
'PATCH' : r"[0-9]+",
|
||||||
'BUILD': r"[0-9]+",
|
'BUILD' : r"[0-9]+",
|
||||||
'BLD' : r"[1-9][0-9]*",
|
'BLD' : r"[1-9][0-9]*",
|
||||||
'TAG' : r"(?:preview|final|alpha|beta|post|pre|dev|rc|a|b|c|r)",
|
'RELEASE': r"(?:preview|final|alpha|beta|post|pre|dev|rc|a|b|c|r)",
|
||||||
'PYTAG': r"(?:post|dev|rc|a|b)",
|
'PYTAG' : r"(?:post|dev|rc|a|b)",
|
||||||
'NUM' : r"[0-9]+",
|
'NUM' : r"[0-9]+",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,13 +105,13 @@ PATTERN_PART_FIELDS = {
|
||||||
'0D' : 'dom',
|
'0D' : 'dom',
|
||||||
'JJJ' : 'doy',
|
'JJJ' : 'doy',
|
||||||
'00J' : 'doy',
|
'00J' : 'doy',
|
||||||
'MAJOR': 'major',
|
'MAJOR' : 'major',
|
||||||
'MINOR': 'minor',
|
'MINOR' : 'minor',
|
||||||
'PATCH': 'patch',
|
'PATCH' : 'patch',
|
||||||
'BUILD': 'bid',
|
'BUILD' : 'bid',
|
||||||
'BLD' : 'bid',
|
'BLD' : 'bid',
|
||||||
'TAG' : 'tag',
|
'RELEASE': 'tag',
|
||||||
'PYTAG': 'pytag',
|
'PYTAG' : 'pytag',
|
||||||
'NUM' : 'num',
|
'NUM' : 'num',
|
||||||
'WW' : 'week_w',
|
'WW' : 'week_w',
|
||||||
'0W' : 'week_w',
|
'0W' : 'week_w',
|
||||||
|
|
@ -122,6 +122,18 @@ PATTERN_PART_FIELDS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PEP440_PART_SUBSTITUTIONS = {
|
||||||
|
'0W' : "WW",
|
||||||
|
'0U' : "UU",
|
||||||
|
'0V' : "VV",
|
||||||
|
'0M' : "MM",
|
||||||
|
'0D' : "DD",
|
||||||
|
'00J' : "JJJ",
|
||||||
|
'BUILD' : "BLD",
|
||||||
|
'RELEASE': "PYTAG",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FieldValue = typ.Union[str, int]
|
FieldValue = typ.Union[str, int]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -187,13 +199,13 @@ PART_FORMATS: typ.Dict[str, typ.Callable[[FieldValue], str]] = {
|
||||||
'0D' : _fmt_0d,
|
'0D' : _fmt_0d,
|
||||||
'JJJ' : _fmt_num,
|
'JJJ' : _fmt_num,
|
||||||
'00J' : _fmt_00j,
|
'00J' : _fmt_00j,
|
||||||
'MAJOR': _fmt_num,
|
'MAJOR' : _fmt_num,
|
||||||
'MINOR': _fmt_num,
|
'MINOR' : _fmt_num,
|
||||||
'PATCH': _fmt_num,
|
'PATCH' : _fmt_num,
|
||||||
'BUILD': _fmt_num,
|
'BUILD' : _fmt_num,
|
||||||
'BLD' : _fmt_bld,
|
'BLD' : _fmt_bld,
|
||||||
'TAG' : _fmt_num,
|
'RELEASE': _fmt_num,
|
||||||
'PYTAG': _fmt_num,
|
'PYTAG' : _fmt_num,
|
||||||
'NUM' : _fmt_num,
|
'NUM' : _fmt_num,
|
||||||
'WW' : _fmt_num,
|
'WW' : _fmt_num,
|
||||||
'0W' : _fmt_0w,
|
'0W' : _fmt_0w,
|
||||||
|
|
@ -209,15 +221,37 @@ def _convert_to_pep440(version_pattern: str) -> str:
|
||||||
# corner cases as specified in PEP440, in particular
|
# corner cases as specified in PEP440, in particular
|
||||||
# related to post and dev releases.
|
# related to post and dev releases.
|
||||||
|
|
||||||
version_pattern = version_pattern.lstrip("v")
|
pep440_pattern = version_pattern
|
||||||
|
|
||||||
|
if pep440_pattern.startswith("v"):
|
||||||
|
pep440_pattern = pep440_pattern[1:]
|
||||||
|
|
||||||
|
pep440_pattern = pep440_pattern.replace(r"\[", "")
|
||||||
|
pep440_pattern = pep440_pattern.replace(r"\]", "")
|
||||||
|
|
||||||
|
pep440_pattern, _ = re.subn(r"[^a-zA-Z0-9\.\[\]]", "", pep440_pattern)
|
||||||
|
|
||||||
part_names = list(PATTERN_PART_FIELDS.keys())
|
part_names = list(PATTERN_PART_FIELDS.keys())
|
||||||
part_names.sort(key=len, reverse=True)
|
part_names.sort(key=len, reverse=True)
|
||||||
if version_pattern == "vYYYY0M.BUILD[-TAG]":
|
|
||||||
return "YYYY0M.BLD[PYTAGNUM]"
|
|
||||||
|
|
||||||
# TODO (mb 2020-09-20)
|
for part_name in part_names:
|
||||||
raise NotImplementedError
|
if part_name not in version_pattern:
|
||||||
|
continue
|
||||||
|
if part_name not in PEP440_PART_SUBSTITUTIONS:
|
||||||
|
continue
|
||||||
|
|
||||||
|
substitution = PEP440_PART_SUBSTITUTIONS[part_name]
|
||||||
|
|
||||||
|
is_numerical_part = part_name not in ('RELEASE', 'PYTAG')
|
||||||
|
if is_numerical_part:
|
||||||
|
part_index = pep440_pattern.find(part_name)
|
||||||
|
is_zero_truncation_part = part_index == 0 or pep440_pattern[part_index - 1] == "."
|
||||||
|
if is_zero_truncation_part:
|
||||||
|
pep440_pattern = pep440_pattern.replace(part_name, substitution)
|
||||||
|
else:
|
||||||
|
pep440_pattern = pep440_pattern.replace(part_name, substitution)
|
||||||
|
|
||||||
|
return pep440_pattern
|
||||||
|
|
||||||
|
|
||||||
def normalize_pattern(version_pattern: str, raw_pattern: str) -> str:
|
def normalize_pattern(version_pattern: str, raw_pattern: str) -> str:
|
||||||
|
|
@ -236,10 +270,10 @@ def _replace_pattern_parts(pattern: str) -> str:
|
||||||
# The pattern is escaped, so that everything besides the format
|
# The pattern is escaped, so that everything besides the format
|
||||||
# string variables is treated literally.
|
# string variables is treated literally.
|
||||||
while True:
|
while True:
|
||||||
new_pattern, n = re.subn(r"([^\\]|^)\[", r"\1(?:", pattern)
|
new_pattern, _n = re.subn(r"([^\\]|^)\[", r"\1(?:", pattern)
|
||||||
new_pattern, m = re.subn(r"([^\\]|^)\]", r"\1)?" , new_pattern)
|
new_pattern, _m = re.subn(r"([^\\]|^)\]", r"\1)?" , new_pattern)
|
||||||
pattern = new_pattern
|
pattern = new_pattern
|
||||||
if n + m == 0:
|
if _n + _m == 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
SortKey = typ.Tuple[int, int]
|
SortKey = typ.Tuple[int, int]
|
||||||
|
|
@ -274,7 +308,7 @@ def _compile_pattern_re(version_pattern: str, raw_pattern: str) -> typ.Pattern[s
|
||||||
normalized_pattern = normalize_pattern(version_pattern, raw_pattern)
|
normalized_pattern = normalize_pattern(version_pattern, raw_pattern)
|
||||||
escaped_pattern = normalized_pattern
|
escaped_pattern = normalized_pattern
|
||||||
for char, escaped in RE_PATTERN_ESCAPES:
|
for char, escaped in RE_PATTERN_ESCAPES:
|
||||||
# [] braces are used for optional parts, such as [-TAG]/[-beta]
|
# [] braces are used for optional parts, such as [-RELEASE]/[-beta]
|
||||||
# and need to be escaped manually.
|
# and need to be escaped manually.
|
||||||
is_semantic_char = char in "[]\\"
|
is_semantic_char = char in "[]\\"
|
||||||
if not is_semantic_char:
|
if not is_semantic_char:
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ def rewrite_lines(
|
||||||
"""Replace occurances of patterns in old_lines with new_vinfo.
|
"""Replace occurances of patterns in old_lines with new_vinfo.
|
||||||
|
|
||||||
>>> from .v2patterns import compile_pattern
|
>>> from .v2patterns import compile_pattern
|
||||||
>>> version_pattern = "vYYYY0M.BUILD[-TAG]"
|
>>> version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
>>> new_vinfo = v2version.parse_version_info("v201811.0123-beta", version_pattern)
|
>>> new_vinfo = v2version.parse_version_info("v201811.0123-beta", version_pattern)
|
||||||
>>> patterns = [compile_pattern(version_pattern, '__version__ = "{version}"')]
|
>>> patterns = [compile_pattern(version_pattern, '__version__ = "{version}"')]
|
||||||
>>> rewrite_lines(patterns, new_vinfo, ['__version__ = "v201809.0002-alpha" '])
|
>>> rewrite_lines(patterns, new_vinfo, ['__version__ = "v201809.0002-alpha" '])
|
||||||
|
|
@ -73,9 +73,9 @@ def rfd_from_content(
|
||||||
) -> rewrite.RewrittenFileData:
|
) -> rewrite.RewrittenFileData:
|
||||||
r"""Rewrite pattern occurrences with version string.
|
r"""Rewrite pattern occurrences with version string.
|
||||||
|
|
||||||
>>> version_pattern = "vYYYY0M.BUILD[-TAG]"
|
>>> version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
>>> new_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
>>> new_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
||||||
>>> raw_patterns = ['__version__ = "vYYYY0M.BUILD[-TAG]"']
|
>>> raw_patterns = ['__version__ = "vYYYY0M.BUILD[-RELEASE]"']
|
||||||
>>> patterns =
|
>>> patterns =
|
||||||
>>> content = '__version__ = "v201809.0001-alpha"'
|
>>> content = '__version__ = "v201809.0001-alpha"'
|
||||||
>>> rfd = rfd_from_content(patterns, new_vinfo, content)
|
>>> rfd = rfd_from_content(patterns, new_vinfo, content)
|
||||||
|
|
@ -115,8 +115,8 @@ def iter_rewritten(
|
||||||
) -> typ.Iterable[rewrite.RewrittenFileData]:
|
) -> typ.Iterable[rewrite.RewrittenFileData]:
|
||||||
r'''Iterate over files with version string replaced.
|
r'''Iterate over files with version string replaced.
|
||||||
|
|
||||||
>>> version_pattern = "vYYYY0M.BUILD[-TAG]"
|
>>> version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
>>> file_patterns = {"src/pycalver/__init__.py": ['__version__ = "vYYYY0M.BUILD[-TAG]"']}
|
>>> file_patterns = {"src/pycalver/__init__.py": ['__version__ = "vYYYY0M.BUILD[-RELEASE]"']}
|
||||||
>>> new_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
>>> new_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
||||||
>>> rewritten_datas = iter_rewritten(file_patterns, new_vinfo)
|
>>> rewritten_datas = iter_rewritten(file_patterns, new_vinfo)
|
||||||
>>> rfd = list(rewritten_datas)[0]
|
>>> rfd = list(rewritten_datas)[0]
|
||||||
|
|
@ -153,7 +153,7 @@ def diff(
|
||||||
|
|
||||||
>>> old_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
>>> old_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
||||||
>>> new_vinfo = v2version.parse_version_info("v201810.1124", version_pattern)
|
>>> new_vinfo = v2version.parse_version_info("v201810.1124", version_pattern)
|
||||||
>>> file_patterns = {"src/pycalver/__init__.py": ['__version__ = "vYYYY0M.BUILD[-TAG]"']}
|
>>> file_patterns = {"src/pycalver/__init__.py": ['__version__ = "vYYYY0M.BUILD[-RELEASE]"']}
|
||||||
>>> diff_str = diff(old_vinfo, new_vinfo, file_patterns)
|
>>> diff_str = diff(old_vinfo, new_vinfo, file_patterns)
|
||||||
>>> lines = diff_str.split("\n")
|
>>> lines = diff_str.split("\n")
|
||||||
>>> lines[:2]
|
>>> lines[:2]
|
||||||
|
|
|
||||||
|
|
@ -149,9 +149,9 @@ def _parse_version_info(field_values: FieldValues) -> version.V2VersionInfo:
|
||||||
pytag = fvals.get('pytag') or ""
|
pytag = fvals.get('pytag') or ""
|
||||||
|
|
||||||
if tag and not pytag:
|
if tag and not pytag:
|
||||||
pytag = version.PEP440_TAG_BY_TAG[tag]
|
pytag = version.PEP440_TAG_BY_RELEASE[tag]
|
||||||
elif pytag and not tag:
|
elif pytag and not tag:
|
||||||
tag = version.TAG_BY_PEP440_TAG[pytag]
|
tag = version.RELEASE_BY_PEP440_TAG[pytag]
|
||||||
|
|
||||||
date: typ.Optional[dt.date] = None
|
date: typ.Optional[dt.date] = None
|
||||||
|
|
||||||
|
|
@ -221,19 +221,19 @@ def _parse_version_info(field_values: FieldValues) -> version.V2VersionInfo:
|
||||||
|
|
||||||
|
|
||||||
def parse_version_info(
|
def parse_version_info(
|
||||||
version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-TAG[NUM]]"
|
version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-RELEASE[NUM]]"
|
||||||
) -> version.V2VersionInfo:
|
) -> version.V2VersionInfo:
|
||||||
"""Parse normalized V2VersionInfo.
|
"""Parse normalized V2VersionInfo.
|
||||||
|
|
||||||
>>> vinfo = parse_version_info("v201712.0033-beta0", raw_pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
>>> vinfo = parse_version_info("v201712.0033-beta0", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||||
>>> fvals = {'year_y': 2017, 'month': 12, 'bid': "0033", 'tag': "beta", 'num': 0}
|
>>> fvals = {'year_y': 2017, 'month': 12, 'bid': "0033", 'tag': "beta", 'num': 0}
|
||||||
>>> assert vinfo == _parse_version_info(fvals)
|
>>> assert vinfo == _parse_version_info(fvals)
|
||||||
|
|
||||||
>>> vinfo = parse_version_info("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
>>> vinfo = parse_version_info("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||||
>>> fvals = {'year_y': 2017, 'month': 12, 'bid': "0033", 'tag': "beta"}
|
>>> fvals = {'year_y': 2017, 'month': 12, 'bid': "0033", 'tag': "beta"}
|
||||||
>>> assert vinfo == _parse_version_info(fvals)
|
>>> assert vinfo == _parse_version_info(fvals)
|
||||||
|
|
||||||
>>> vinfo = parse_version_info("v201712.0033", raw_pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
>>> vinfo = parse_version_info("v201712.0033", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||||
>>> fvals = {'year_y': 2017, 'month': 12, 'bid': "0033"}
|
>>> fvals = {'year_y': 2017, 'month': 12, 'bid': "0033"}
|
||||||
>>> assert vinfo == _parse_version_info(fvals)
|
>>> assert vinfo == _parse_version_info(fvals)
|
||||||
|
|
||||||
|
|
@ -254,10 +254,10 @@ def parse_version_info(
|
||||||
return _parse_version_info(field_values)
|
return _parse_version_info(field_values)
|
||||||
|
|
||||||
|
|
||||||
def is_valid(version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-TAG]") -> bool:
|
def is_valid(version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-RELEASE[NUM]]") -> bool:
|
||||||
"""Check if a version matches a pattern.
|
"""Check if a version matches a pattern.
|
||||||
|
|
||||||
>>> is_valid("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-TAG]")
|
>>> is_valid("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||||
True
|
True
|
||||||
>>> is_valid("v201712.0033-beta", raw_pattern="MAJOR.MINOR.PATCH")
|
>>> is_valid("v201712.0033-beta", raw_pattern="MAJOR.MINOR.PATCH")
|
||||||
False
|
False
|
||||||
|
|
@ -285,9 +285,9 @@ def _format_part_values(vinfo: version.V2VersionInfo) -> PartValues:
|
||||||
It may for example have month=9, but not the formatted
|
It may for example have month=9, but not the formatted
|
||||||
representation '09' for '0M'.
|
representation '09' for '0M'.
|
||||||
|
|
||||||
>>> vinfo = parse_version_info("v200709.1033-beta", pattern="vYYYY0M.BUILD[-TAG]")
|
>>> vinfo = parse_version_info("v200709.1033-beta", pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||||
>>> kwargs = dict(_format_part_values(vinfo))
|
>>> kwargs = dict(_format_part_values(vinfo))
|
||||||
>>> (kwargs['YYYY'], kwargs['0M'], kwargs['BUILD'], kwargs['TAG'])
|
>>> (kwargs['YYYY'], kwargs['0M'], kwargs['BUILD'], kwargs['RELEASE[NUM]'])
|
||||||
('2007', '09', '1033', 'beta')
|
('2007', '09', '1033', 'beta')
|
||||||
>>> (kwargs['YY'], kwargs['0Y'], kwargs['MM'], kwargs['PYTAG'])
|
>>> (kwargs['YY'], kwargs['0Y'], kwargs['MM'], kwargs['PYTAG'])
|
||||||
('7', '07', '9', 'b')
|
('7', '07', '9', 'b')
|
||||||
|
|
@ -381,8 +381,8 @@ FormattedSegmentParts = typ.List[str]
|
||||||
|
|
||||||
|
|
||||||
def _format_segment_tree(
|
def _format_segment_tree(
|
||||||
seg_tree: SegmentTree,
|
seg_tree : SegmentTree,
|
||||||
part_values : PartValues,
|
part_values: PartValues,
|
||||||
) -> FormattedSegmentParts:
|
) -> FormattedSegmentParts:
|
||||||
result_parts = []
|
result_parts = []
|
||||||
for seg in seg_tree:
|
for seg in seg_tree:
|
||||||
|
|
@ -400,8 +400,7 @@ def _format_segment_tree(
|
||||||
for part, part_value in part_values:
|
for part, part_value in part_values:
|
||||||
if part in formatted_seg:
|
if part in formatted_seg:
|
||||||
is_zero_part = (
|
is_zero_part = (
|
||||||
part in version.ZERO_VALUES
|
part in version.ZERO_VALUES and str(part_value) == version.ZERO_VALUES[part]
|
||||||
and str(part_value) == version.ZERO_VALUES[part]
|
|
||||||
)
|
)
|
||||||
if is_zero_part:
|
if is_zero_part:
|
||||||
is_zero_seg = True
|
is_zero_seg = True
|
||||||
|
|
@ -418,7 +417,7 @@ def format_version(vinfo: version.V2VersionInfo, raw_pattern: str) -> str:
|
||||||
"""Generate version string.
|
"""Generate version string.
|
||||||
|
|
||||||
>>> import datetime as dt
|
>>> import datetime as dt
|
||||||
>>> vinfo = parse_version_info("v200712.0033-beta", pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
>>> vinfo = parse_version_info("v200712.0033-beta", pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||||
>>> vinfo_a = vinfo._replace(**cal_info(date=dt.date(2007, 1, 1))._asdict())
|
>>> vinfo_a = vinfo._replace(**cal_info(date=dt.date(2007, 1, 1))._asdict())
|
||||||
>>> vinfo_b = vinfo._replace(**cal_info(date=dt.date(2007, 12, 31))._asdict())
|
>>> vinfo_b = vinfo._replace(**cal_info(date=dt.date(2007, 12, 31))._asdict())
|
||||||
|
|
||||||
|
|
@ -429,75 +428,75 @@ def format_version(vinfo: version.V2VersionInfo, raw_pattern: str) -> str:
|
||||||
'200701.0033b'
|
'200701.0033b'
|
||||||
>>> format_version(vinfo_a, pattern="vYY.BLD[-PYTAGNUM]")
|
>>> format_version(vinfo_a, pattern="vYY.BLD[-PYTAGNUM]")
|
||||||
'v7.33-b0'
|
'v7.33-b0'
|
||||||
>>> format_version(vinfo_a, pattern="v0Y.BLD[-TAG]")
|
>>> format_version(vinfo_a, pattern="v0Y.BLD[-RELEASE[NUM]]")
|
||||||
'v07.33-beta'
|
'v07.33-beta'
|
||||||
|
|
||||||
>>> format_version(vinfo_a, pattern="vYYYY0M.BUILD[-TAG]")
|
>>> format_version(vinfo_a, pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||||
'v200701.0033-beta'
|
'v200701.0033-beta'
|
||||||
>>> format_version(vinfo_b, pattern="vYYYY0M.BUILD[-TAG]")
|
>>> format_version(vinfo_b, pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||||
'v200712.0033-beta'
|
'v200712.0033-beta'
|
||||||
|
|
||||||
>>> format_version(vinfo_a, pattern="vYYYYw0W.BUILD[-TAG]")
|
>>> format_version(vinfo_a, pattern="vYYYYw0W.BUILD[-RELEASE[NUM]]")
|
||||||
'v2007w01.0033-beta'
|
'v2007w01.0033-beta'
|
||||||
>>> format_version(vinfo_a, pattern="vYYYYwWW.BLD[-TAG]")
|
>>> format_version(vinfo_a, pattern="vYYYYwWW.BLD[-RELEASE[NUM]]")
|
||||||
'v2007w1.33-beta'
|
'v2007w1.33-beta'
|
||||||
>>> format_version(vinfo_b, pattern="vYYYYw0W.BUILD[-TAG]")
|
>>> format_version(vinfo_b, pattern="vYYYYw0W.BUILD[-RELEASE[NUM]]")
|
||||||
'v2007w53.0033-beta'
|
'v2007w53.0033-beta'
|
||||||
|
|
||||||
>>> format_version(vinfo_a, pattern="vYYYYd00J.BUILD[-TAG]")
|
>>> format_version(vinfo_a, pattern="vYYYYd00J.BUILD[-RELEASE[NUM]]")
|
||||||
'v2007d001.0033-beta'
|
'v2007d001.0033-beta'
|
||||||
>>> format_version(vinfo_a, pattern="vYYYYdJJJ.BUILD[-TAG]")
|
>>> format_version(vinfo_a, pattern="vYYYYdJJJ.BUILD[-RELEASE[NUM]]")
|
||||||
'v2007d1.0033-beta'
|
'v2007d1.0033-beta'
|
||||||
>>> format_version(vinfo_b, pattern="vYYYYd00J.BUILD[-TAG]")
|
>>> format_version(vinfo_b, pattern="vYYYYd00J.BUILD[-RELEASE[NUM]]")
|
||||||
'v2007d365.0033-beta'
|
'v2007d365.0033-beta'
|
||||||
|
|
||||||
>>> format_version(vinfo_a, pattern="vGGGGwVV.BLD[PYTAGNUM]")
|
>>> format_version(vinfo_a, pattern="vGGGGwVV.BLD[PYTAGNUM]")
|
||||||
'v2007w1.33b0'
|
'v2007w1.33b0'
|
||||||
>>> format_version(vinfo_a, pattern="vGGGGw0V.BUILD[-TAG]")
|
>>> format_version(vinfo_a, pattern="vGGGGw0V.BUILD[-RELEASE[NUM]]")
|
||||||
'v2007w01.0033-beta'
|
'v2007w01.0033-beta'
|
||||||
>>> format_version(vinfo_b, pattern="vGGGGw0V.BUILD[-TAG]")
|
>>> format_version(vinfo_b, pattern="vGGGGw0V.BUILD[-RELEASE[NUM]]")
|
||||||
'v2008w01.0033-beta'
|
'v2008w01.0033-beta'
|
||||||
|
|
||||||
>>> vinfo_c = vinfo_b._replace(major=1, minor=2, patch=34, tag='final')
|
>>> vinfo_c = vinfo_b._replace(major=1, minor=2, patch=34, tag='final')
|
||||||
|
|
||||||
>>> format_version(vinfo_c, pattern="vYYYYwWW.BUILD-TAG")
|
>>> format_version(vinfo_c, pattern="vYYYYwWW.BUILD-RELEASE")
|
||||||
'v2007w53.0033-final'
|
'v2007w53.0033-final'
|
||||||
>>> format_version(vinfo_c, pattern="vYYYYwWW.BUILD[-TAG]")
|
>>> format_version(vinfo_c, pattern="vYYYYwWW.BUILD[-RELEASE[NUM]]")
|
||||||
'v2007w53.0033'
|
'v2007w53.0033'
|
||||||
|
|
||||||
>>> format_version(vinfo_c, pattern="vMAJOR.MINOR.PATCH")
|
>>> format_version(vinfo_c, pattern="vMAJOR.MINOR.PATCH")
|
||||||
'v1.2.34'
|
'v1.2.34'
|
||||||
|
|
||||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='final')
|
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='final')
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-TAGNUM")
|
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-RELEASENUM")
|
||||||
'v1.0.0-final0'
|
'v1.0.0-final0'
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-TAG[NUM]")
|
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-RELEASE[NUM]")
|
||||||
'v1.0.0-final'
|
'v1.0.0-final'
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-TAG")
|
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-RELEASE")
|
||||||
'v1.0.0-final'
|
'v1.0.0-final'
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH[-TAG]")
|
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH[-RELEASE[NUM]]")
|
||||||
'v1.0.0'
|
'v1.0.0'
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR[.PATCH[-TAG]]")
|
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR[.PATCH[-RELEASE[NUM]]]")
|
||||||
'v1.0'
|
'v1.0'
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-TAG]]]")
|
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]")
|
||||||
'v1'
|
'v1'
|
||||||
|
|
||||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=1, tag='rc', num=0)
|
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=1, tag='rc', num=0)
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH]]")
|
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH]]")
|
||||||
'v1.0.1'
|
'v1.0.1'
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-TAG[NUM]]]]")
|
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]")
|
||||||
'v1.0.1-rc'
|
'v1.0.1-rc'
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-TAGNUM]]]")
|
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-RELEASENUM]]]")
|
||||||
'v1.0.1-rc0'
|
'v1.0.1-rc0'
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH]]")
|
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH]]")
|
||||||
'v1.0.1'
|
'v1.0.1'
|
||||||
|
|
||||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
||||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-TAG[NUM]]]]")
|
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]")
|
||||||
'v1.0.0-rc2'
|
'v1.0.0-rc2'
|
||||||
|
|
||||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
||||||
>>> format_version(vinfo_d, pattern='__version__ = "vMAJOR[.MINOR[.PATCH[-TAG[NUM]]]]"')
|
>>> format_version(vinfo_d, pattern='__version__ = "vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]"')
|
||||||
'__version__ = "v1.0.0-rc2"'
|
'__version__ = "v1.0.0-rc2"'
|
||||||
"""
|
"""
|
||||||
part_values = _format_part_values(vinfo)
|
part_values = _format_part_values(vinfo)
|
||||||
|
|
@ -508,7 +507,7 @@ def format_version(vinfo: version.V2VersionInfo, raw_pattern: str) -> str:
|
||||||
|
|
||||||
def incr(
|
def incr(
|
||||||
old_version: str,
|
old_version: str,
|
||||||
raw_pattern: str = "vYYYY0M.BUILD[-TAG]",
|
raw_pattern: str = "vYYYY0M.BUILD[-RELEASE]",
|
||||||
*,
|
*,
|
||||||
release : typ.Optional[str] = None,
|
release : typ.Optional[str] = None,
|
||||||
major : bool = False,
|
major : bool = False,
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ class V2VersionInfo(typ.NamedTuple):
|
||||||
TODAY = dt.datetime.utcnow().date()
|
TODAY = dt.datetime.utcnow().date()
|
||||||
|
|
||||||
|
|
||||||
TAG_BY_PEP440_TAG = {
|
RELEASE_BY_PEP440_TAG = {
|
||||||
'a' : 'alpha',
|
'a' : 'alpha',
|
||||||
'b' : 'beta',
|
'b' : 'beta',
|
||||||
'' : 'final',
|
'' : 'final',
|
||||||
|
|
@ -89,7 +89,7 @@ TAG_BY_PEP440_TAG = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PEP440_TAG_BY_TAG = {
|
PEP440_TAG_BY_RELEASE = {
|
||||||
'a' : 'a',
|
'a' : 'a',
|
||||||
'b' : 'b',
|
'b' : 'b',
|
||||||
'dev' : 'dev',
|
'dev' : 'dev',
|
||||||
|
|
@ -105,16 +105,16 @@ PEP440_TAG_BY_TAG = {
|
||||||
'rev' : 'post',
|
'rev' : 'post',
|
||||||
}
|
}
|
||||||
|
|
||||||
assert set(TAG_BY_PEP440_TAG.keys()) == set(PEP440_TAG_BY_TAG.values())
|
assert set(RELEASE_BY_PEP440_TAG.keys()) == set(PEP440_TAG_BY_RELEASE.values())
|
||||||
assert set(TAG_BY_PEP440_TAG.values()) < set(PEP440_TAG_BY_TAG.keys())
|
assert set(RELEASE_BY_PEP440_TAG.values()) < set(PEP440_TAG_BY_RELEASE.keys())
|
||||||
|
|
||||||
|
|
||||||
ZERO_VALUES = {
|
ZERO_VALUES = {
|
||||||
'MAJOR': "0",
|
'MAJOR' : "0",
|
||||||
'MINOR': "0",
|
'MINOR' : "0",
|
||||||
'PATCH': "0",
|
'PATCH' : "0",
|
||||||
'TAG' : "final",
|
'RELEASE': "final",
|
||||||
'PYTAG': "",
|
'PYTAG' : "",
|
||||||
'NUM' : "0",
|
'NUM' : "0",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ setup.cfg =
|
||||||
NEW_PATTERN_CFG_FIXTURE = """
|
NEW_PATTERN_CFG_FIXTURE = """
|
||||||
[pycalver]
|
[pycalver]
|
||||||
current_version = "v201808.1456-beta"
|
current_version = "v201808.1456-beta"
|
||||||
version_pattern = "vYYYY0M.BUILD[-TAG]"
|
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
commit_message = "bump version to {new_version}"
|
commit_message = "bump version to {new_version}"
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
|
|
@ -154,8 +154,8 @@ def test_parse_v2_cfg():
|
||||||
assert "setup.py" in cfg.file_patterns
|
assert "setup.py" in cfg.file_patterns
|
||||||
assert "setup.cfg" in cfg.file_patterns
|
assert "setup.cfg" in cfg.file_patterns
|
||||||
# TODO (mb 2020-09-18):
|
# TODO (mb 2020-09-18):
|
||||||
# assert cfg.file_patterns["setup.py" ] == ["vYYYY0M.BUILD[-TAG]", "YYYY0M.BLD[PYTAGNUM]"]
|
# assert cfg.file_patterns["setup.py" ] == ["vYYYY0M.BUILD[-RELEASE]", "YYYY0M.BLD[PYTAGNUM]"]
|
||||||
# assert cfg.file_patterns["setup.cfg" ] == ['current_version = "vYYYY0M.BUILD[-TAG]"']
|
# assert cfg.file_patterns["setup.cfg" ] == ['current_version = "vYYYY0M.BUILD[-RELEASE]"']
|
||||||
# assert cfg.file_patterns["src/project/*.py"] == ['Copyright (c) 2018-YYYY"']
|
# assert cfg.file_patterns["src/project/*.py"] == ['Copyright (c) 2018-YYYY"']
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,21 +129,21 @@ V2_PART_PATTERN_CASES = [
|
||||||
(['0V'], "53", "53"),
|
(['0V'], "53", "53"),
|
||||||
(['0V'], "54", None),
|
(['0V'], "54", None),
|
||||||
(['MAJOR', 'MINOR', 'PATCH'], "0", "0"),
|
(['MAJOR', 'MINOR', 'PATCH'], "0", "0"),
|
||||||
(['TAG' ], "alpha" , "alpha"),
|
(['RELEASE'], "alpha" , "alpha"),
|
||||||
(['TAG' ], "alfa" , None),
|
(['RELEASE'], "alfa" , None),
|
||||||
(['TAG' ], "beta" , "beta"),
|
(['RELEASE'], "beta" , "beta"),
|
||||||
(['TAG' ], "dev" , "dev"),
|
(['RELEASE'], "dev" , "dev"),
|
||||||
(['TAG' ], "rc" , "rc"),
|
(['RELEASE'], "rc" , "rc"),
|
||||||
(['TAG' ], "post" , "post"),
|
(['RELEASE'], "post" , "post"),
|
||||||
(['TAG' ], "final" , "final"),
|
(['RELEASE'], "final" , "final"),
|
||||||
(['TAG' ], "latest", None),
|
(['RELEASE'], "latest", None),
|
||||||
(['PYTAG'], "a" , "a"),
|
(['PYTAG' ], "a" , "a"),
|
||||||
(['PYTAG'], "b" , "b"),
|
(['PYTAG' ], "b" , "b"),
|
||||||
(['PYTAG'], "dev" , "dev"),
|
(['PYTAG' ], "dev" , "dev"),
|
||||||
(['PYTAG'], "rc" , "rc"),
|
(['PYTAG' ], "rc" , "rc"),
|
||||||
(['PYTAG'], "post" , "post"),
|
(['PYTAG' ], "post" , "post"),
|
||||||
(['PYTAG'], "post" , "post"),
|
(['PYTAG' ], "post" , "post"),
|
||||||
(['PYTAG'], "x" , None),
|
(['PYTAG' ], "x" , None),
|
||||||
(['NUM' ], "a" , None),
|
(['NUM' ], "a" , None),
|
||||||
(['NUM' ], "0" , "0"),
|
(['NUM' ], "0" , "0"),
|
||||||
(['NUM' ], "1" , "1"),
|
(['NUM' ], "1" , "1"),
|
||||||
|
|
|
||||||
|
|
@ -141,8 +141,8 @@ def test_v1_optional_release():
|
||||||
|
|
||||||
def test_v2_optional_release():
|
def test_v2_optional_release():
|
||||||
old_lines = OPTIONAL_RELEASE_FIXTURE.splitlines()
|
old_lines = OPTIONAL_RELEASE_FIXTURE.splitlines()
|
||||||
pattern = "YYYY.BUILD[-TAG]"
|
pattern = "YYYY.BUILD[-RELEASE]"
|
||||||
patterns = ['__version__ = "YYYY.BUILD[-TAG]"']
|
patterns = ['__version__ = "YYYY.BUILD[-RELEASE]"']
|
||||||
|
|
||||||
new_vinfo = v2version.parse_version_info("2019.0003", pattern)
|
new_vinfo = v2version.parse_version_info("2019.0003", pattern)
|
||||||
new_lines = v2rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
|
new_lines = v2rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
|
||||||
|
|
|
||||||
|
|
@ -201,40 +201,29 @@ def test_v1_parse_versions(pattern_str, line, expected_vinfo):
|
||||||
|
|
||||||
# def test_v2_parse_versions(pattern_str, line, expected_vinfo):
|
# def test_v2_parse_versions(pattern_str, line, expected_vinfo):
|
||||||
def test_v2_parse_versions():
|
def test_v2_parse_versions():
|
||||||
_vnfo = v2version.parse_version_info("v201712.0033", raw_pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
_vnfo = v2version.parse_version_info("v201712.0033", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||||
fvals = {'year_y': 2017, 'month': 12, 'bid': "0033"}
|
fvals = {'year_y': 2017, 'month': 12, 'bid': "0033"}
|
||||||
assert _vnfo == v2version._parse_version_info(fvals)
|
assert _vnfo == v2version._parse_version_info(fvals)
|
||||||
|
|
||||||
|
|
||||||
def test_make_segments():
|
|
||||||
segs = v2version._make_segments("vYYYY0M.BUILD[-TAG[NUM]]")
|
|
||||||
assert segs == ["vYYYY0M.BUILD", "-TAG", "NUM", "", ""]
|
|
||||||
|
|
||||||
segs = v2version._make_segments('__version__ = "YYYY0M.BLD[PYTAGNUM]"')
|
|
||||||
assert segs == ['__version__ = "YYYY0M.BLD', 'PYTAGNUM', '"']
|
|
||||||
|
|
||||||
segs = v2version._make_segments('__version__ = "YYYY.BUILD[-TAG]"')
|
|
||||||
assert segs == ['__version__ = "YYYY.BUILD', '-TAG', '"']
|
|
||||||
|
|
||||||
|
|
||||||
def test_v2_format_version():
|
def test_v2_format_version():
|
||||||
version_pattern = "vYYYY0M.BUILD[-TAG[NUM]]"
|
version_pattern = "vYYYY0M.BUILD[-RELEASE[NUM]]"
|
||||||
in_version = "v200701.0033-beta"
|
in_version = "v200701.0033-beta"
|
||||||
|
|
||||||
vinfo = v2version.parse_version_info(in_version, raw_pattern=version_pattern)
|
vinfo = v2version.parse_version_info(in_version, raw_pattern=version_pattern)
|
||||||
out_version = v2version.format_version(vinfo, raw_pattern=version_pattern)
|
out_version = v2version.format_version(vinfo, raw_pattern=version_pattern)
|
||||||
assert in_version == out_version
|
assert in_version == out_version
|
||||||
|
|
||||||
result = v2version.format_version(vinfo, raw_pattern="v0Y.BUILD[-TAG]")
|
result = v2version.format_version(vinfo, raw_pattern="v0Y.BUILD[-RELEASE]")
|
||||||
assert result == "v07.0033-beta"
|
assert result == "v07.0033-beta"
|
||||||
|
|
||||||
result = v2version.format_version(vinfo, raw_pattern="vYY.BLD[-TAG]")
|
result = v2version.format_version(vinfo, raw_pattern="vYY.BLD[-RELEASE]")
|
||||||
assert result == "v7.33-beta"
|
assert result == "v7.33-beta"
|
||||||
|
|
||||||
result = v2version.format_version(vinfo, raw_pattern="vYY.BLD-TAG")
|
result = v2version.format_version(vinfo, raw_pattern="vYY.BLD-RELEASE")
|
||||||
assert result == "v7.33-beta"
|
assert result == "v7.33-beta"
|
||||||
|
|
||||||
result = v2version.format_version(vinfo, raw_pattern='__version__ = "YYYY.BUILD[-TAG]"')
|
result = v2version.format_version(vinfo, raw_pattern='__version__ = "YYYY.BUILD[-RELEASE]"')
|
||||||
assert result == '__version__ = "2007.0033-beta"'
|
assert result == '__version__ = "2007.0033-beta"'
|
||||||
|
|
||||||
result = v2version.format_version(vinfo, raw_pattern='__version__ = "YYYY.BLD"')
|
result = v2version.format_version(vinfo, raw_pattern='__version__ = "YYYY.BLD"')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue