summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dev/README.md9
-rwxr-xr-xdev/bump.py69
-rwxr-xr-xdev/bump.sh19
-rwxr-xr-xdev/clean.py32
-rwxr-xr-xdev/clean.sh5
-rw-r--r--setup.cfg1
-rw-r--r--tox.ini16
7 files changed, 123 insertions, 28 deletions
diff --git a/dev/README.md b/dev/README.md
index 398a4e9..de30ed9 100644
--- a/dev/README.md
+++ b/dev/README.md
@@ -2,9 +2,12 @@
This file contains some files useful for development.
-- `bump.sh` - Execute `bumpversion` then post-processes the CHANGELOG to handle corner-cases
+- `bump.py` - Execute `bumpversion` then post-processes the CHANGELOG to handle corner-cases
that `bumpversion` cannot. Requires [`bump2version`](https://github.com/c4urself/bump2version),
which is the maintained fork of [`bumpversion`](https://github.com/peritus/bumpversion).
-- `clean.sh` - This file cleans most files that are created during development.
+ It is not really intended to be called directly, but instead through `tox -e bump`.
+- `clean.py` - This file cleans most files that are created during development.
Run in the project home directory.
-- `requirements.txt` - Requirements to run tests.
+ It is not really intended to be called directly, but instead through `tox -e clean`.
+- `requirements.in` - Our direct requirements to run tests.
+- `requirements.txt` - All pinned requirements to run tests.
diff --git a/dev/bump.py b/dev/bump.py
new file mode 100755
index 0000000..7ad0585
--- /dev/null
+++ b/dev/bump.py
@@ -0,0 +1,69 @@
+#! /usr/bin/env python
+
+"""
+Cross-platform bump of version with special CHANGELOG modification.
+INTENDED TO BE CALLED FROM PROJECT ROOT, NOT FROM dev/!
+"""
+
+import subprocess
+import sys
+
+try:
+ bump_type = sys.argv[1]
+except IndexError:
+ sys.exit("Must pass 'bump_type' argument!")
+else:
+ if bump_type not in ("major", "minor", "patch"):
+ sys.exit('bump_type must be one of "major", "minor", or "patch"!')
+
+
+def git(cmd, *args):
+ """Wrapper for calling git"""
+ try:
+ subprocess.run(["git", cmd, *args], check=True, text=True)
+ except subprocess.CalledProcessError as e:
+ print("Call to git failed!", file=sys.stderr)
+ print("STDOUT:", e.stdout, file=sys.stderr)
+ print("STDERR:", e.stderr, file=sys.stderr)
+ sys.exit(e.returncode)
+
+
+def bumpversion(severity, *args, catch=False):
+ """Wrapper for calling bumpversion"""
+ cmd = ["bump2version", *args, severity]
+ try:
+ if catch:
+ return subprocess.run(cmd, check=True, capture_output=True, text=True).stdout
+ else:
+ subprocess.run(cmd, check=True, text=True)
+ except subprocess.CalledProcessError as e:
+ print("Call to bump2version failed!", file=sys.stderr)
+ print("STDOUT:", e.stdout, file=sys.stderr)
+ print("STDERR:", e.stderr, file=sys.stderr)
+ sys.exit(e.returncode)
+
+
+# Do a dry run of the bump to find what the current version is and what it will become.
+data = bumpversion(bump_type, "--dry-run", "--list", catch=True)
+data = dict(x.split("=") for x in data.splitlines())
+
+# Execute the bumpversion.
+bumpversion(bump_type)
+
+# Post-process the changelog with things that bumpversion is not good at updating.
+with open("CHANGELOG.md") as fl:
+ changelog = fl.read().replace(
+ "<!---Comparison links-->",
+ "<!---Comparison links-->\n[{new}]: {url}/{current}...{new}".format(
+ new=data["new_version"],
+ current=data["current_version"],
+ url="https://github.com/SethMMorton/natsort/compare"
+ )
+ )
+with open("CHANGELOG.md", "w") as fl:
+ fl.write(changelog)
+
+# Finally, add the CHANGELOG.md changes to the previous commit.
+git("add", "CHANGELOG.md")
+git("commit", "--amend", "--no-edit")
+git("tag", "--force", data["new_version"], "HEAD")
diff --git a/dev/bump.sh b/dev/bump.sh
deleted file mode 100755
index 54be914..0000000
--- a/dev/bump.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /bin/sh
-
-set -eux
-
-# Determine what the new version will be
-new_version=$(bump2version --dry-run --list "${1}" | grep "^new_version" | sed -r s,"^.*=",,)
-current_version=$(bump2version --dry-run --list "${1}" | grep "^current_version" | sed -r s,"^.*=",,)
-
-# Perform the bumpversion, then perform the post-processing on the CHANGELOG.md
-# to update the version comparison list.
-bump2version "${1}"
-URL="https://github.com/SethMMorton/natsort/compare"
-sed -E "s|(<!---Comparison links-->)|\1\n[${new_version}]: ${URL}/${current_version}...${new_version}|" -i.bak CHANGELOG.md
-rm CHANGELOG.md.bak # Remove backup created by in-place sed
-
-# Commit the change just made and then move the tag
-git add CHANGELOG.md
-git commit --amend --no-edit
-git tag --force "${new_version}" HEAD
diff --git a/dev/clean.py b/dev/clean.py
new file mode 100755
index 0000000..ac2c4a0
--- /dev/null
+++ b/dev/clean.py
@@ -0,0 +1,32 @@
+#! /usr/bin/env python
+
+"""
+Cross-platform clean of working directory.
+INTENDED TO BE CALLED FROM PROJECT ROOT, NOT FROM dev/!
+"""
+
+import pathlib
+import shutil
+
+# Directories to obliterate
+dirs = [
+ pathlib.Path("build"),
+ pathlib.Path("dist"),
+ pathlib.Path(".pytest_cache"),
+ pathlib.Path(".hypothesis"),
+ pathlib.Path(".tox"),
+]
+dirs += pathlib.Path.cwd().glob("*.egg-info")
+for d in dirs:
+ if d.is_dir():
+ shutil.rmtree(d, ignore_errors=True)
+ elif d.is_file():
+ d.unlink() # just in case there is a file.
+
+# Clean up any stray __pycache__.
+for d in pathlib.Path.cwd().rglob("__pycache__"):
+ shutil.rmtree(d, ignore_errors=True)
+
+# Shouldn't be any .pyc left, but just in case
+for f in pathlib.Path.cwd().rglob("*.pyc"):
+ f.unlink()
diff --git a/dev/clean.sh b/dev/clean.sh
deleted file mode 100755
index 77159bd..0000000
--- a/dev/clean.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#! /bin/sh
-
-rm -rf build/ dist/ *.egg-info .pytest_cache/ .hypothesis/ .tox/
-find . -type d -name __pycache__ -delete
-find . -type f -name "*.pyc" -delete
diff --git a/setup.cfg b/setup.cfg
index dbbbaef..0e0f872 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -63,4 +63,3 @@ exclude =
docs,
.venv
-
diff --git a/tox.ini b/tox.ini
index 698e9b9..594d0fd 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,6 +9,8 @@ envlist =
# Other valid evironments are:
# docs
# release
+# clean
+# bump
# Don't error out if a user hasn't installed all python versions.
skip_missing_interpreters =
@@ -57,6 +59,15 @@ commands =
{envpython} setup.py build_sphinx
skip_install = true
+# Bump version
+[testenv:bump]
+passenv =
+ HOME
+deps =
+ bump2version
+commands =
+ {envpython} dev/bump.py {posargs:}
+
# Release the code to PyPI
[testenv:release]
deps =
@@ -65,3 +76,8 @@ commands =
{envpython} setup.py sdist --format=gztar bdist_wheel
twine upload --skip-existing dist/*
skip_install = true
+
+# Clean up the working directory
+[testenv:clean]
+deps =
+commands = {envpython} dev/clean.py