mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 06:20:08 +01:00
wip: misc project updates
This commit is contained in:
parent
2ca615d19b
commit
e888be1f71
14 changed files with 219 additions and 438 deletions
0
CONTRIBUTING.md
Normal file
0
CONTRIBUTING.md
Normal file
146
Makefile
146
Makefile
|
|
@ -1,146 +0,0 @@
|
|||
.PHONY: setup_conda_envs install \
|
||||
test lint \
|
||||
clean rm_site_packages \
|
||||
build readme upload
|
||||
|
||||
|
||||
build/.setup_conda_envs.make_marker:
|
||||
conda create --name pycalver_37 python=3.7 --yes
|
||||
conda create --name pycalver_36 python=3.6 --yes
|
||||
conda create --name pycalver_27 python=2.7 --yes
|
||||
@mkdir -p build/
|
||||
@touch build/.setup_conda_envs.make_marker
|
||||
|
||||
|
||||
build/envs.txt: build/.setup_conda_envs.make_marker
|
||||
@mkdir -p build/
|
||||
conda env list | grep pycalver | rev | cut -d " " -f1 | rev > build/envs.txt.tmp
|
||||
mv build/envs.txt.tmp build/envs.txt
|
||||
|
||||
|
||||
PYENV37 ?= $(shell bash -c "grep 37 build/envs.txt || true")
|
||||
PYENV36 ?= $(shell bash -c "grep 36 build/envs.txt || true")
|
||||
PYENV27 ?= $(shell bash -c "grep 27 build/envs.txt || true")
|
||||
PYTHON37 ?= $(PYENV37)/bin/python
|
||||
PYTHON36 ?= $(PYENV36)/bin/python
|
||||
PYTHON27 ?= $(PYENV27)/bin/python
|
||||
|
||||
BDIST_WHEEL_PYCALVER = $(shell bash -c "ls -1t dist/pycalver*py2*.whl | head -n 1")
|
||||
SDIST_PYCALVER = $(shell bash -c "ls -1t dist/pycalver*.tar.gz | head -n 1")
|
||||
BUILD_LOG_DIR = "test_build_logs/"
|
||||
BUILD_LOG_FILE := $(shell date +"$(BUILD_LOG_DIR)%Y%m%dt%H%M%S%N.log")
|
||||
|
||||
|
||||
build/.install.make_marker: setup.py build/envs.txt requirements*.txt
|
||||
$(PYTHON37) -m pip install --upgrade --quiet $$(cat requirements.txt);
|
||||
$(PYTHON36) -m pip install --upgrade --quiet $$(cat requirements.txt);
|
||||
$(PYTHON27) -m pip install --upgrade --quiet $$(cat requirements.txt);
|
||||
|
||||
$(PYTHON37) -m pip install --upgrade \
|
||||
$$(cat requirements-test.txt) \
|
||||
$$(cat requirements-dev.txt);
|
||||
|
||||
# NOTE (mb 2018-08-23): The linter has an issue running with
|
||||
# python 3.7 because some code in pycodestyle=2.3.1
|
||||
# but we have to wait for a flake8 update because
|
||||
# reasons... https://github.com/PyCQA/pycodestyle/issues/728
|
||||
@mkdir -p lib/
|
||||
$(PYTHON37) -m pip install --src lib/ \
|
||||
-e "git+https://gitlab.com/pycqa/flake8@master#egg=flake8";
|
||||
|
||||
@mkdir -p build/
|
||||
@touch build/.install.make_marker
|
||||
|
||||
|
||||
clean:
|
||||
rm -f build/envs.txt
|
||||
rm -f build/.setup_conda_envs.make_marker
|
||||
rm -f build/.install.make_marker
|
||||
|
||||
|
||||
lint: build/.install.make_marker
|
||||
@echo -n "lint.."
|
||||
@$(PYENV37)/bin/flake8 src/pycalver/
|
||||
@echo "ok"
|
||||
|
||||
|
||||
mypy: build/.install.make_marker
|
||||
@echo -n "mypy.."
|
||||
@MYPYPATH=stubs/ $(PYTHON37) -m mypy \
|
||||
src/pycalver/
|
||||
@echo "ok"
|
||||
|
||||
|
||||
test: build/.install.make_marker
|
||||
@PYTHONPATH=src/:$$PYTHONPATH \
|
||||
$(PYTHON37) -m pytest \
|
||||
--cov-report html \
|
||||
--cov=pycalver \
|
||||
test/
|
||||
|
||||
|
||||
devtest: build/.install.make_marker
|
||||
PYTHONPATH=src/:$$PYTHONPATH \
|
||||
$(PYTHON37) -m pytest -v \
|
||||
--cov-report term \
|
||||
--cov=pycalver \
|
||||
--capture=no \
|
||||
--exitfirst \
|
||||
test/
|
||||
|
||||
|
||||
build/README.html: build/.install.make_marker README.rst CHANGELOG.rst
|
||||
@cat README.rst > build/.full_readme.rst
|
||||
@echo "\n" >> build/.full_readme.rst
|
||||
@cat CHANGELOG.rst >> build/.full_readme.rst
|
||||
@$(PYENV37)/bin/rst2html5 --strict \
|
||||
build/.full_readme.rst > build/README.html.tmp
|
||||
@mv build/README.html.tmp build/README.html
|
||||
@echo "updated build/README.html"
|
||||
|
||||
|
||||
readme: build/README.html
|
||||
|
||||
|
||||
build/.src_files.txt: setup.py build/envs.txt src/pycalver/*.py
|
||||
@mkdir -p build/
|
||||
@ls -l setup.py build/envs.txt src/pycalver/*.py > build/.src_files.txt.tmp
|
||||
@mv build/.src_files.txt.tmp build/.src_files.txt
|
||||
|
||||
|
||||
rm_site_packages:
|
||||
# whackamole
|
||||
rm -rf $(PYENV37)/lib/python3.6/site-packages/pycalver/
|
||||
rm -rf $(PYENV37)/lib/python3.6/site-packages/pycalver*.dist-info/
|
||||
rm -rf $(PYENV37)/lib/python3.6/site-packages/pycalver*.egg-info/
|
||||
rm -f $(PYENV37)/lib/python3.6/site-packages/pycalver*.egg
|
||||
|
||||
|
||||
build/.local_install.make_marker: build/.src_files.txt rm_site_packages
|
||||
@echo "installing pycalver.."
|
||||
@$(PYTHON37) setup.py install --no-compile --verbose
|
||||
@mkdir -p build/
|
||||
@$(PYTHON37) -c "import pycalver"
|
||||
@echo "install completed for pycalver"
|
||||
@touch build/.local_install.make_marker
|
||||
|
||||
|
||||
build: build/.local_install.make_marker
|
||||
@mkdir -p $(BUILD_LOG_DIR)
|
||||
@echo "writing full build log to $(BUILD_LOG_FILE)"
|
||||
@echo "building pycalver.."
|
||||
@$(PYTHON37) setup.py bdist_wheel --python-tag=py2.py3 >> $(BUILD_LOG_FILE)
|
||||
@echo "build completed for pycalver"
|
||||
|
||||
|
||||
upload: build/.install.make_marker build/README.html
|
||||
$(PYTHON37) setup.py bdist_wheel --python-tag=py2.py3
|
||||
$(PYENV37)/bin/twine upload $(BDIST_WHEEL_PYCALVER)
|
||||
|
||||
|
||||
setup_conda_envs: build/.setup_conda_envs.make_marker
|
||||
|
||||
install: build/.install.make_marker
|
||||
|
||||
run_main:
|
||||
PYTHONPATH=src/:$$PYTHONPATH $(PYTHON37) -m pycalver --help
|
||||
31
bootstrapit.sh
Normal file
31
bootstrapit.sh
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
# Bootstrapit Project Configuration
|
||||
|
||||
AUTHOR_NAME="Manuel Barkhau"
|
||||
AUTHOR_CONTACT="@mbarkhau"
|
||||
|
||||
KEYWORDS="version versioning bumpversion calver"
|
||||
DESCRIPTION="CalVer versioning for python libraries."
|
||||
|
||||
LICENSE_ID="MIT"
|
||||
|
||||
PACKAGE_NAME="pycalver"
|
||||
GIT_REPO_NAMESPACE="mbarkhau"
|
||||
GIT_REPO_DOMAIN="gitlab.com"
|
||||
|
||||
DEFAULT_PYTHON_VERSION="python=3.6"
|
||||
|
||||
IS_PUBLIC=1
|
||||
|
||||
## Download and run the actual update script
|
||||
|
||||
PROJECT_DIR=$(dirname $0)
|
||||
|
||||
if ! [[ -f $PROJECT_DIR/scripts/bootstrapit_update.sh ]]; then
|
||||
RAW_FILES_URL="https://gitlab.com/mbarkhau/bootstrapit/raw/master"
|
||||
mkdir -p "$PROJECT_DIR/scripts/";
|
||||
curl --silent -O "$PROJECT_DIR/scripts/bootstrapit_update.sh" \
|
||||
"$RAW_FILES_URL/scripts/bootstrapit_update.sh";
|
||||
fi
|
||||
|
||||
source $PROJECT_DIR/scripts/bootstrapit_update.sh;
|
||||
110
scratch.py
110
scratch.py
|
|
@ -1,109 +1,3 @@
|
|||
from pkg_resources import parse_version
|
||||
import re
|
||||
import sys
|
||||
|
||||
canonical_version_re = re.compile(r"""
|
||||
\b
|
||||
(?P<version>
|
||||
(?P<calver>
|
||||
v # "v" version prefix
|
||||
(?P<year>\d{4})
|
||||
(?P<month>\d{2})
|
||||
)
|
||||
(?:
|
||||
\. # "." build nr prefix
|
||||
(?P<build_nr>\d{3,})
|
||||
)
|
||||
)(?:\s|$)
|
||||
""", flags=re.VERBOSE)
|
||||
|
||||
|
||||
full_version_re = re.compile(r"""
|
||||
\b
|
||||
(?P<version>
|
||||
(?P<calver>
|
||||
v # "v" version prefix
|
||||
(?P<year>\d{4})
|
||||
(?P<month>\d{2})
|
||||
)
|
||||
(?:
|
||||
\. # "." build nr prefix
|
||||
(?P<build>\d+)
|
||||
)
|
||||
(?:
|
||||
\- # "-" tag prefix
|
||||
(?P<tag>a|alpha|b|beta|dev|c|rc|pre|preview|post)
|
||||
(?P<tag_nr>\d*)
|
||||
)?
|
||||
)(?:\s|$)
|
||||
""", flags=re.VERBOSE)
|
||||
|
||||
versions = [
|
||||
"v201711.0001-alpha",
|
||||
"v201711.0002-alpha",
|
||||
"v201712.0003-beta3",
|
||||
"v201712.0004-preview",
|
||||
"v201712.0005",
|
||||
"v201712.0006",
|
||||
"v201712.0007-beta",
|
||||
"v201801.0008-beta",
|
||||
"v201801.0008-dev",
|
||||
"v201801.0009",
|
||||
"v201802.0010",
|
||||
"v201802.0007",
|
||||
"v201904.0050",
|
||||
"v201905.0051",
|
||||
"v201905.0052",
|
||||
"v201712.0027-beta1",
|
||||
"v201712.beta-0027",
|
||||
"v201712.post-0027",
|
||||
"v201712.post-0027",
|
||||
]
|
||||
|
||||
for vstr in versions:
|
||||
v = parse_version(vstr)
|
||||
print(vstr.ljust(20), repr(v).ljust(30), int(v.is_prerelease))
|
||||
v = full_version_re.match(vstr)
|
||||
print("\t", v and v.groupdict())
|
||||
v = canonical_version_re.match(vstr)
|
||||
print("\t", v and v.groupdict())
|
||||
|
||||
a = "v201711.beta-0001"
|
||||
b = "v201711.0002-beta"
|
||||
c = "v201711.0002"
|
||||
d = "0.9.2"
|
||||
|
||||
va = parse_version(a)
|
||||
vb = parse_version(b)
|
||||
vc = parse_version(c)
|
||||
vd = parse_version(d)
|
||||
|
||||
print(a, repr(va))
|
||||
print(b, repr(vb))
|
||||
print(c, repr(vc))
|
||||
print(d, repr(vd), vd < vc)
|
||||
|
||||
|
||||
# https://regex101.com/r/fnj60p/3
|
||||
pycalver_re = re.compile(r"""
|
||||
\b
|
||||
(?P<full_version>
|
||||
(?P<calver>
|
||||
v # "v" version prefix
|
||||
(?P<year>\d{4})
|
||||
(?P<month>\d{2})
|
||||
)
|
||||
(?:
|
||||
. # "." build nr prefix
|
||||
(?P<build_nr>\d{4,})
|
||||
)
|
||||
)(?:\s|$)
|
||||
""", flags=re.VERBOSE)
|
||||
|
||||
print(pycalver_re.match("v201712.0027").groupdict())
|
||||
|
||||
print(repr(parse_version("v201712.0027")))
|
||||
print(repr(parse_version("v201712.0027")))
|
||||
print(repr(parse_version("v201712.0027")))
|
||||
print(repr(parse_version("v201712") == parse_version("v201712.0")))
|
||||
|
||||
print("v201712.0027" > "v201712.0028")
|
||||
print(sys.version)
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@ import os
|
|||
|
||||
__version__ = "v201809.0002-beta"
|
||||
|
||||
DEBUG = os.environ.get("PYCALVER_DEBUG", "0") == "1"
|
||||
DEBUG = os.environ.get("PYDEBUG", "0") == "1"
|
||||
|
|
|
|||
|
|
@ -66,10 +66,7 @@ def show() -> None:
|
|||
@cli.command()
|
||||
@click.argument("old_version")
|
||||
@click.option(
|
||||
"--release",
|
||||
default=None,
|
||||
metavar="<name>",
|
||||
help="Override release name of current_version",
|
||||
"--release", default=None, metavar="<name>", help="Override release name of current_version"
|
||||
)
|
||||
def incr(old_version: str, release: str = None) -> None:
|
||||
_init_loggers(verbose=False)
|
||||
|
|
@ -83,21 +80,18 @@ def incr(old_version: str, release: str = None) -> None:
|
|||
new_version_nfo = parse.parse_version_info(new_version)
|
||||
|
||||
print("PyCalVer Version:", new_version)
|
||||
print("PEP440 Version:", new_version_nfo.pep440_version)
|
||||
print("PEP440 Version:" , new_version_nfo.pep440_version)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option(
|
||||
"--dry",
|
||||
default=False,
|
||||
is_flag=True,
|
||||
help="Display diff of changes, don't rewrite files.",
|
||||
"--dry", default=False, is_flag=True, help="Display diff of changes, don't rewrite files."
|
||||
)
|
||||
def init(dry: bool) -> None:
|
||||
"""Initialize [pycalver] configuration in setup.cfg"""
|
||||
_init_loggers(verbose=False)
|
||||
|
||||
cfg: config.MaybeConfig = config.parse()
|
||||
cfg : config.MaybeConfig = config.parse()
|
||||
if cfg:
|
||||
log.error("Configuration already initialized in setup.cfg")
|
||||
sys.exit(1)
|
||||
|
|
@ -123,35 +117,14 @@ def init(dry: bool) -> None:
|
|||
|
||||
@cli.command()
|
||||
@click.option(
|
||||
"--release",
|
||||
default=None,
|
||||
metavar="<name>",
|
||||
help="Override release name of current_version",
|
||||
"--release", default=None, metavar="<name>", help="Override release name of current_version"
|
||||
)
|
||||
@click.option("--verbose", default=False, is_flag=True, help="Log applied changes to stderr")
|
||||
@click.option(
|
||||
"--verbose",
|
||||
default=False,
|
||||
is_flag=True,
|
||||
help="Log applied changes to stderr",
|
||||
)
|
||||
@click.option(
|
||||
"--dry",
|
||||
default=False,
|
||||
is_flag=True,
|
||||
help="Display diff of changes, don't rewrite files.",
|
||||
)
|
||||
@click.option(
|
||||
"--commit",
|
||||
default=True,
|
||||
is_flag=True,
|
||||
help="Commit after updating version strings.",
|
||||
)
|
||||
@click.option(
|
||||
"--tag",
|
||||
default=True,
|
||||
is_flag=True,
|
||||
help="Tag the commit.",
|
||||
"--dry", default=False, is_flag=True, help="Display diff of changes, don't rewrite files."
|
||||
)
|
||||
@click.option("--commit", default=True, is_flag=True, help="Commit after updating version strings.")
|
||||
@click.option("--tag" , default=True, is_flag=True, help="Tag the commit.")
|
||||
@click.option(
|
||||
"--allow-dirty",
|
||||
default=False,
|
||||
|
|
@ -163,12 +136,7 @@ def init(dry: bool) -> None:
|
|||
),
|
||||
)
|
||||
def bump(
|
||||
release: str,
|
||||
verbose: bool,
|
||||
dry: bool,
|
||||
commit: bool,
|
||||
tag: bool,
|
||||
allow_dirty: bool,
|
||||
release: str, verbose: bool, dry: bool, commit: bool, tag: bool, allow_dirty: bool
|
||||
) -> None:
|
||||
_init_loggers(verbose)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ log = logging.getLogger("pycalver.config")
|
|||
|
||||
class Config(typ.NamedTuple):
|
||||
|
||||
current_version : str
|
||||
current_version: str
|
||||
pep440_version : str
|
||||
|
||||
tag : bool
|
||||
commit : bool
|
||||
commit: bool
|
||||
|
||||
file_patterns : typ.Dict[str, typ.List[str]]
|
||||
file_patterns: typ.Dict[str, typ.List[str]]
|
||||
|
||||
|
||||
MaybeConfig = typ.Optional[Config]
|
||||
|
|
@ -34,6 +34,9 @@ MaybeConfig = typ.Optional[Config]
|
|||
|
||||
def parse_buffer(cfg_buffer: io.StringIO) -> MaybeConfig:
|
||||
cfg_parser = configparser.RawConfigParser()
|
||||
if hasattr(cfg_parser, 'read_file'):
|
||||
cfg_parser.read_file(cfg_buffer)
|
||||
else:
|
||||
cfg_parser.readfp(cfg_buffer)
|
||||
|
||||
if not cfg_parser.has_section("pycalver"):
|
||||
|
|
@ -46,7 +49,7 @@ def parse_buffer(cfg_buffer: io.StringIO) -> MaybeConfig:
|
|||
log.error("setup.cfg does not have 'pycalver.current_version'")
|
||||
return None
|
||||
|
||||
current_version = base_cfg["current_version"]
|
||||
current_version = base_cfg['current_version']
|
||||
if PYCALVER_RE.match(current_version) is None:
|
||||
log.error(f"setup.cfg 'pycalver.current_version is invalid")
|
||||
log.error(f"current_version = {current_version}")
|
||||
|
|
@ -54,7 +57,7 @@ def parse_buffer(cfg_buffer: io.StringIO) -> MaybeConfig:
|
|||
|
||||
pep440_version = str(pkg_resources.parse_version(current_version))
|
||||
|
||||
tag = base_cfg.get("tag", "").lower() in ("yes", "true", "1", "on")
|
||||
tag = base_cfg.get("tag" , "").lower() in ("yes", "true", "1", "on")
|
||||
commit = base_cfg.get("commit", "").lower() in ("yes", "true", "1", "on")
|
||||
|
||||
file_patterns: typ.Dict[str, typ.List[str]] = {}
|
||||
|
|
@ -76,9 +79,7 @@ def parse_buffer(cfg_buffer: io.StringIO) -> MaybeConfig:
|
|||
file_patterns[filepath] = ["{version}", "{pep440_version}"]
|
||||
else:
|
||||
file_patterns[filepath] = [
|
||||
line.strip()
|
||||
for line in patterns.splitlines()
|
||||
if line.strip()
|
||||
line.strip() for line in patterns.splitlines() if line.strip()
|
||||
]
|
||||
|
||||
if not file_patterns:
|
||||
|
|
@ -118,29 +119,28 @@ def default_config_lines() -> typ.List[str]:
|
|||
]
|
||||
|
||||
if os.path.exists("setup.py"):
|
||||
cfg_lines.extend([
|
||||
cfg_lines.extend(
|
||||
[
|
||||
"[pycalver:file:setup.py]",
|
||||
"patterns = ",
|
||||
" \"{version}\"",
|
||||
" \"{pep440_version}\"",
|
||||
"",
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
if os.path.exists("README.rst"):
|
||||
cfg_lines.extend([
|
||||
cfg_lines.extend(
|
||||
[
|
||||
"[pycalver:file:README.rst]",
|
||||
"patterns = ",
|
||||
" {version}",
|
||||
" {pep440_version}",
|
||||
"",
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
if os.path.exists("README.md"):
|
||||
cfg_lines.extend([
|
||||
"[pycalver:file:README.md]",
|
||||
" {version}",
|
||||
" {pep440_version}",
|
||||
"",
|
||||
])
|
||||
cfg_lines.extend(["[pycalver:file:README.md]", " {version}", " {pep440_version}", ""])
|
||||
|
||||
return cfg_lines
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
# This file is part of the pycalver project
|
||||
# https://github.com/mbarkhau/pycalver
|
||||
#
|
||||
|
|
@ -15,42 +14,47 @@ from . import parse
|
|||
log = logging.getLogger("pycalver.rewrite")
|
||||
|
||||
|
||||
def rewrite(
|
||||
new_version: str,
|
||||
file_patterns: typ.Dict[str, typ.List[str]],
|
||||
dry=False,
|
||||
verbose=False,
|
||||
) -> None:
|
||||
def rewrite_lines(
|
||||
old_lines: typ.List[str], patterns: typ.List[str], new_version: str
|
||||
) -> typ.List[str]:
|
||||
new_version_nfo = parse.parse_version_info(new_version)
|
||||
new_version_fmt_kwargs = new_version_nfo._asdict()
|
||||
|
||||
matches: typ.List[parse.PatternMatch]
|
||||
for filepath, patterns in file_patterns.items():
|
||||
with io.open(filepath, mode="rt", encoding="utf-8") as fh:
|
||||
content = fh.read()
|
||||
|
||||
old_lines = content.splitlines()
|
||||
new_lines = old_lines.copy()
|
||||
|
||||
matches = parse.parse_patterns(old_lines, patterns)
|
||||
matches: typ.List[parse.PatternMatch] = parse.parse_patterns(old_lines, patterns)
|
||||
|
||||
for m in matches:
|
||||
replacement = m.pattern.format(**new_version_fmt_kwargs)
|
||||
span_l, span_r = m.span
|
||||
new_line = m.line[:span_l] + replacement + m.line[span_r:]
|
||||
new_lines[m.lineno] = new_line
|
||||
|
||||
return new_lines
|
||||
|
||||
|
||||
def rewrite(
|
||||
new_version: str, file_patterns: typ.Dict[str, typ.List[str]], dry=False, verbose=False
|
||||
) -> None:
|
||||
for filepath, patterns in file_patterns.items():
|
||||
with io.open(filepath, mode="rt", encoding="utf-8") as fh:
|
||||
content = fh.read()
|
||||
|
||||
# TODO (mb 2018-09-18): Detect line sep
|
||||
line_sep = "\n"
|
||||
|
||||
old_lines = content.splitlines()
|
||||
new_lines = rewrite_lines(old_lines, patterns, new_version)
|
||||
|
||||
if dry or verbose:
|
||||
print("\n".join(difflib.unified_diff(
|
||||
old_lines,
|
||||
new_lines,
|
||||
lineterm="",
|
||||
fromfile="a/" + filepath,
|
||||
tofile="b/" + filepath,
|
||||
)))
|
||||
diff_lines = difflib.unified_diff(
|
||||
old_lines, new_lines, lineterm="", fromfile="a/" + filepath, tofile="b/" + filepath
|
||||
)
|
||||
print("\n".join(diff_lines))
|
||||
|
||||
if dry:
|
||||
continue
|
||||
|
||||
new_content = "\n".join(new_lines)
|
||||
new_content = line_sep.join(new_lines)
|
||||
with io.open(filepath, mode="wt", encoding="utf-8") as fh:
|
||||
fh.write(new_content)
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ log = logging.getLogger("pycalver.vcs")
|
|||
class BaseVCS:
|
||||
|
||||
_TEST_USABLE_COMMAND: typ.List[str]
|
||||
_COMMIT_COMMAND: typ.List[str]
|
||||
_STATUS_COMMAND: typ.List[str]
|
||||
_COMMIT_COMMAND : typ.List[str]
|
||||
_STATUS_COMMAND : typ.List[str]
|
||||
|
||||
@classmethod
|
||||
def commit(cls, message: str) -> None:
|
||||
|
|
@ -38,18 +38,14 @@ class BaseVCS:
|
|||
env = os.environ.copy()
|
||||
# TODO (mb 2018-09-04): check that this works on py27,
|
||||
# might need to be bytes there, idk.
|
||||
env["HGENCODING"] = "utf-8"
|
||||
env['HGENCODING'] = "utf-8"
|
||||
sp.check_output(cmd, env=env)
|
||||
os.unlink(tmp_file.name)
|
||||
|
||||
@classmethod
|
||||
def is_usable(cls) -> bool:
|
||||
try:
|
||||
return sp.call(
|
||||
cls._TEST_USABLE_COMMAND,
|
||||
stderr=sp.PIPE,
|
||||
stdout=sp.PIPE,
|
||||
) == 0
|
||||
return sp.call(cls._TEST_USABLE_COMMAND, stderr=sp.PIPE, stdout=sp.PIPE) == 0
|
||||
except OSError as e:
|
||||
if e.errno == 2:
|
||||
# mercurial is not installed then, ok.
|
||||
|
|
@ -88,8 +84,8 @@ class BaseVCS:
|
|||
class Git(BaseVCS):
|
||||
|
||||
_TEST_USABLE_COMMAND = ["git", "rev-parse", "--git-dir"]
|
||||
_COMMIT_COMMAND = ["git", "commit", "-F"]
|
||||
_STATUS_COMMAND = ["git", "status", "--porcelain"]
|
||||
_COMMIT_COMMAND = ["git", "commit" , "-F"]
|
||||
_STATUS_COMMAND = ["git", "status" , "--porcelain"]
|
||||
|
||||
@classmethod
|
||||
def tag(cls, name):
|
||||
|
|
@ -102,7 +98,7 @@ class Git(BaseVCS):
|
|||
|
||||
class Mercurial(BaseVCS):
|
||||
|
||||
_TEST_USABLE_COMMAND = ["hg", "root"]
|
||||
_TEST_USABLE_COMMAND = ["hg", 'root']
|
||||
_COMMIT_COMMAND = ["hg", "commit", "--logfile"]
|
||||
_STATUS_COMMAND = ["hg", "status", "-mard"]
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ def bump(old_version: str, *, release: str = None) -> str:
|
|||
|
||||
if old_ver.calver > new_calver:
|
||||
log.warning(
|
||||
f"'version.bump' called with '{old_version}', " +
|
||||
f"which is from the future, " +
|
||||
f"maybe your system clock is out of sync."
|
||||
f"'version.bump' called with '{old_version}', "
|
||||
+ f"which is from the future, "
|
||||
+ f"maybe your system clock is out of sync."
|
||||
)
|
||||
# leave calver as is (don't go back in time)
|
||||
new_calver = old_ver.calver
|
||||
|
|
@ -43,7 +43,7 @@ def bump(old_version: str, *, release: str = None) -> str:
|
|||
new_release = old_ver.release[1:]
|
||||
else:
|
||||
new_release = None
|
||||
elif release == "final":
|
||||
elif release == 'final':
|
||||
new_release = None
|
||||
else:
|
||||
new_release = release
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ def test_readme_pycalver1():
|
|||
version_info = parse.PYCALVER_RE.match(version_str).groupdict()
|
||||
|
||||
assert version_info == {
|
||||
"version" : "v201712.0001-alpha",
|
||||
"calver" : "v201712",
|
||||
"year" : "2017",
|
||||
"month" : "12",
|
||||
"build" : ".0001",
|
||||
"release" : "-alpha",
|
||||
'version': "v201712.0001-alpha",
|
||||
'calver' : "v201712",
|
||||
'year' : "2017",
|
||||
'month' : "12",
|
||||
'build' : ".0001",
|
||||
'release': "-alpha",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -21,12 +21,12 @@ def test_readme_pycalver2():
|
|||
version_info = parse.PYCALVER_RE.match(version_str).groupdict()
|
||||
|
||||
assert version_info == {
|
||||
"version" : "v201712.0033",
|
||||
"calver" : "v201712",
|
||||
"year" : "2017",
|
||||
"month" : "12",
|
||||
"build" : ".0033",
|
||||
"release" : None,
|
||||
'version': "v201712.0033",
|
||||
'calver' : "v201712",
|
||||
'year' : "2017",
|
||||
'month' : "12",
|
||||
'build' : ".0033",
|
||||
'release': None,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -37,30 +37,30 @@ def test_re_pattern_parts():
|
|||
}
|
||||
|
||||
cases = [
|
||||
("pep440_version", "201712.31", "201712.31"),
|
||||
("pep440_version", "v201712.0032", None),
|
||||
("pep440_version", "201712.0033-alpha", None),
|
||||
("version", "v201712.0034", "v201712.0034"),
|
||||
("version", "v201712.0035-alpha", "v201712.0035-alpha"),
|
||||
("version", "v201712.0036-alpha0", "v201712.0036-alpha"),
|
||||
("version", "v201712.0037-pre", "v201712.0037"),
|
||||
("version", "201712.38a0", None),
|
||||
("version", "201712.0039", None),
|
||||
("calver", "v201712", "v201712"),
|
||||
("calver", "v201799", "v201799"), # maybe date validation should be a thing
|
||||
("calver", "201712", None),
|
||||
("calver", "v20171", None),
|
||||
("build", ".0012", ".0012"),
|
||||
("build", ".11012", ".11012"),
|
||||
("build", ".012", None),
|
||||
("build", "11012", None),
|
||||
("release", "-alpha", "-alpha"),
|
||||
("release", "-beta", "-beta"),
|
||||
("release", "-dev", "-dev"),
|
||||
("release", "-rc", "-rc"),
|
||||
("release", "-post", "-post"),
|
||||
("release", "-pre", ""),
|
||||
("release", "alpha", ""),
|
||||
("pep440_version", "201712.31" , "201712.31"),
|
||||
("pep440_version", "v201712.0032" , None),
|
||||
("pep440_version", "201712.0033-alpha" , None),
|
||||
("version" , "v201712.0034" , "v201712.0034"),
|
||||
("version" , "v201712.0035-alpha" , "v201712.0035-alpha"),
|
||||
("version" , "v201712.0036-alpha0", "v201712.0036-alpha"),
|
||||
("version" , "v201712.0037-pre" , "v201712.0037"),
|
||||
("version" , "201712.38a0" , None),
|
||||
("version" , "201712.0039" , None),
|
||||
("calver" , "v201712" , "v201712"),
|
||||
("calver" , "v201799" , "v201799"), # maybe date validation should be a thing
|
||||
("calver" , "201712" , None),
|
||||
("calver" , "v20171" , None),
|
||||
("build" , ".0012" , ".0012"),
|
||||
("build" , ".11012" , ".11012"),
|
||||
("build" , ".012" , None),
|
||||
("build" , "11012" , None),
|
||||
("release" , "-alpha" , "-alpha"),
|
||||
("release" , "-beta" , "-beta"),
|
||||
("release" , "-dev" , "-dev"),
|
||||
("release" , "-rc" , "-rc"),
|
||||
("release" , "-post" , "-post"),
|
||||
("release" , "-pre" , ""),
|
||||
("release" , "alpha" , ""),
|
||||
]
|
||||
|
||||
for part_name, line, expected in cases:
|
||||
|
|
@ -107,10 +107,7 @@ def test_default_parse_patterns():
|
|||
" version='201712.2a0',",
|
||||
]
|
||||
|
||||
patterns = [
|
||||
"{version}",
|
||||
"{pep440_version}",
|
||||
]
|
||||
patterns = ["{version}", "{pep440_version}"]
|
||||
|
||||
matches = parse.parse_patterns(lines, patterns)
|
||||
assert len(matches) == 2
|
||||
|
|
@ -135,10 +132,7 @@ def test_explicit_parse_patterns():
|
|||
" version='201712.2a0',",
|
||||
]
|
||||
|
||||
patterns = [
|
||||
"__version__ = '{version}'",
|
||||
"version='{pep440_version}'",
|
||||
]
|
||||
patterns = ["__version__ = '{version}'", "version='{pep440_version}'"]
|
||||
|
||||
matches = parse.parse_patterns(lines, patterns)
|
||||
assert len(matches) == 2
|
||||
|
|
@ -163,10 +157,7 @@ def test_badge_parse_patterns():
|
|||
"",
|
||||
]
|
||||
|
||||
patterns = [
|
||||
"badge/CalVer-{calver}{build}-{release}-blue.svg",
|
||||
":alt: CalVer {version}",
|
||||
]
|
||||
patterns = ["badge/CalVer-{calver}{build}-{release}-blue.svg", ":alt: CalVer {version}"]
|
||||
|
||||
matches = parse.parse_patterns(lines, patterns)
|
||||
assert len(matches) == 2
|
||||
|
|
@ -179,3 +170,23 @@ def test_badge_parse_patterns():
|
|||
|
||||
assert matches[0].match == "badge/CalVer-v201809.0002--beta-blue.svg"
|
||||
assert matches[1].match == ":alt: CalVer v201809.0002-beta"
|
||||
|
||||
|
||||
def test_parse_error():
|
||||
try:
|
||||
parse.parse_version_info("")
|
||||
assert False
|
||||
except ValueError as err:
|
||||
pass
|
||||
|
||||
try:
|
||||
parse.parse_version_info("201809.0002")
|
||||
assert False
|
||||
except ValueError as err:
|
||||
pass
|
||||
|
||||
try:
|
||||
parse.parse_version_info("v201809.2b0")
|
||||
assert False
|
||||
except ValueError as err:
|
||||
pass
|
||||
|
|
|
|||
23
test/test_rewrite.py
Normal file
23
test/test_rewrite.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from pycalver import rewrite
|
||||
|
||||
|
||||
def test_rewrite_lines():
|
||||
old_lines = [
|
||||
'# This file is part of the pycalver project',
|
||||
'# https://github.com/mbarkhau/pycalver',
|
||||
'#',
|
||||
'# (C) 2018 Manuel Barkhau (@mbarkhau)',
|
||||
'# SPDX-License-Identifier: MIT',
|
||||
'',
|
||||
'import os',
|
||||
'',
|
||||
'__version__ = "v201809.0002-beta"',
|
||||
'DEBUG = os.environ.get("PYDEBUG", "0") == "1"',
|
||||
]
|
||||
patterns = ['__version__ = "{version}"']
|
||||
new_version = "v201809.0003"
|
||||
new_lines = rewrite.rewrite_lines(old_lines, patterns, new_version)
|
||||
|
||||
assert len(new_lines) == len(old_lines)
|
||||
assert new_version not in "\n".join(old_lines)
|
||||
assert new_version in "\n".join(new_lines)
|
||||
Loading…
Add table
Add a link
Reference in a new issue