Skip to content

Commit

Permalink
use setuptools-scm for versioning; remove bumpversion
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Sep 18, 2018
1 parent fd8c8b8 commit 0ae3d9e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 173 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ htmlcov/

# autosaved emacs files
*~

# autogenerated by setuptools-scm
Lib/ufo2ft/_version.py
5 changes: 4 additions & 1 deletion Lib/ufo2ft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
from ufo2ft.postProcessor import PostProcessor
import logging

try:
from ._version import version as __version__
except ImportError:
__version__ = "0.0.0+unknown"

__version__ = "2.3.0.dev0"

logger = logging.getLogger(__name__)

Expand Down
35 changes: 4 additions & 31 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
[bumpversion]
current_version = 2.3.0.dev0
commit = True
tag = False
tag_name = v{new_version}
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
{major}.{minor}.{patch}.{release}{dev}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = final
values =
dev
final

[bumpversion:part:dev]

[bumpversion:file:Lib/ufo2ft/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

[bumpversion:file:setup.py]
search = version="{current_version}"
replace = version="{new_version}"

[wheel]
universal = 1

Expand All @@ -38,13 +12,12 @@ license_file = LICENSE

[tool:pytest]
minversion = 2.8
testpaths =
testpaths =
tests
python_files =
python_files =
*_test.py
python_classes =
python_classes =
*Test
addopts =
addopts =
-v
-r a

144 changes: 3 additions & 141 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,154 +2,20 @@

from __future__ import print_function, division, absolute_import
import sys
from setuptools import setup, find_packages, Command
from distutils import log


class bump_version(Command):

description = "increment the package version and commit the changes"

user_options = [
("major", None, "bump the first digit, for incompatible API changes"),
("minor", None, "bump the second digit, for new backward-compatible features"),
("patch", None, "bump the third digit, for bug fixes (default)"),
]

def initialize_options(self):
self.minor = False
self.major = False
self.patch = False

def finalize_options(self):
part = None
for attr in ("major", "minor", "patch"):
if getattr(self, attr, False):
if part is None:
part = attr
else:
from distutils.errors import DistutilsOptionError
raise DistutilsOptionError(
"version part options are mutually exclusive")
self.part = part or "patch"

def bumpversion(self, part, **kwargs):
""" Run bumpversion.main() with the specified arguments.
"""
import bumpversion

args = ['--verbose'] if self.verbose > 1 else []
for k, v in kwargs.items():
k = "--{}".format(k.replace("_", "-"))
is_bool = isinstance(v, bool) and v is True
args.extend([k] if is_bool else [k, str(v)])
args.append(part)

log.debug(
"$ bumpversion %s" % " ".join(a.replace(" ", "\\ ") for a in args))

bumpversion.main(args)

def run(self):
log.info("bumping '%s' version" % self.part)
self.bumpversion(self.part)


class release(bump_version):
"""Drop the developmental release '.devN' suffix from the package version,
open the default text $EDITOR to write release notes, commit the changes
and generate a git tag.
Release notes can also be set with the -m/--message option, or by reading
from standard input.
"""

description = "tag a new release"

user_options = [
("message=", 'm', "message containing the release notes"),
("sign", "s", "make a GPG-signed tag, using the default key"),
]

def initialize_options(self):
self.message = None
self.sign = False

def finalize_options(self):
import re

current_version = self.distribution.metadata.get_version()
if not re.search(r"\.dev[0-9]+", current_version):
from distutils.errors import DistutilsSetupError
raise DistutilsSetupError(
"current version (%s) has no '.devN' suffix.\n "
"Run 'setup.py bump_version' with any of "
"--major, --minor, --patch options" % current_version)

message = self.message
if message is None:
if sys.stdin.isatty():
# stdin is interactive, use editor to write release notes
message = self.edit_release_notes()
else:
# read release notes from stdin pipe
message = sys.stdin.read()

if not message.strip():
from distutils.errors import DistutilsSetupError
raise DistutilsSetupError("release notes message is empty")

self.message = "v{new_version}\n\n%s" % message
self.sign = bool(self.sign)

@staticmethod
def edit_release_notes():
"""Use the default text $EDITOR to write release notes.
If $EDITOR is not set, use 'nano'."""
from tempfile import mkstemp
import os
import shlex
import subprocess

text_editor = shlex.split(os.environ.get('EDITOR', 'nano'))

fd, tmp = mkstemp(prefix='bumpversion-')
try:
os.close(fd)
with open(tmp, 'w') as f:
f.write("\n\n# Write release notes.\n"
"# Lines starting with '#' will be ignored.")
subprocess.check_call(text_editor + [tmp])
with open(tmp, 'r') as f:
changes = "".join(
l for l in f.readlines() if not l.startswith('#'))
finally:
os.remove(tmp)
return changes

def run(self):
log.info("stripping developmental release suffix")
# drop '.dev0' suffix, commit with given message and create git tag
self.bumpversion("release",
tag=True,
message="Release {new_version}",
tag_message=self.message,
sign_tags=self.sign)
from setuptools import setup, find_packages


needs_pytest = {'pytest', 'test'}.intersection(sys.argv)
pytest_runner = ['pytest_runner'] if needs_pytest else []
needs_wheel = {'bdist_wheel'}.intersection(sys.argv)
wheel = ['wheel'] if needs_wheel else []
needs_bump2version = {'release', 'bump_version'}.intersection(sys.argv)
bump2version = ['bump2version >= 0.5.7'] if needs_bump2version else []

with open('README.rst', 'r') as f:
long_description = f.read()

setup(
name="ufo2ft",
version="2.3.0.dev0",
use_scm_version={"write_to": "Lib/ufo2ft/_version.py"},
author="Tal Leming, James Godfrey-Kittle",
author_email="[email protected]",
maintainer="Cosimo Lupo",
Expand All @@ -161,7 +27,7 @@ def run(self):
packages=find_packages("Lib"),
include_package_data=True,
license="MIT",
setup_requires=pytest_runner + wheel + bump2version,
setup_requires=pytest_runner + wheel + ["setuptools_scm"],
tests_require=[
'pytest>=2.8',
],
Expand All @@ -179,10 +45,6 @@ def run(self):
"skia-pathops>=0.2.0",
],
},
cmdclass={
"release": release,
"bump_version": bump_version,
},
classifiers=[
'Development Status :: 4 - Beta',
"Environment :: Console",
Expand Down

0 comments on commit 0ae3d9e

Please sign in to comment.