-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update version handling and add helper script (#806)
* Update version handling and add helper script * Remove typing hints * Address review, add tag argument
- Loading branch information
Showing
4 changed files
with
119 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Constants used by plexapi.""" | ||
|
||
# Library version | ||
MAJOR_VERSION = 4 | ||
MINOR_VERSION = 7 | ||
PATCH_VERSION = 0 | ||
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}" | ||
__version__ = f"{__short_version__}.{PATCH_VERSION}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,7 @@ | |
except ImportError: | ||
from distutils.core import setup | ||
|
||
# Get the current version | ||
with open('plexapi/__init__.py') as handle: | ||
for line in handle.readlines(): | ||
if line.startswith('VERSION'): | ||
version = re.findall("'([0-9\.]+?)'", line)[0] | ||
from plexapi import const | ||
|
||
# Get README.rst contents | ||
readme = open('README.rst', 'r').read() | ||
|
@@ -28,7 +24,7 @@ | |
|
||
setup( | ||
name='PlexAPI', | ||
version=version, | ||
version=const.__version__, | ||
description='Python bindings for the Plex API.', | ||
author='Michael Shepanski', | ||
author_email='[email protected]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
"""Helper script to bump the current version.""" | ||
import argparse | ||
import re | ||
import subprocess | ||
|
||
from packaging.version import Version | ||
|
||
from plexapi import const | ||
|
||
SUPPORTED_BUMP_TYPES = ["patch", "minor", "major"] | ||
|
||
|
||
def _bump_release(release, bump_type): | ||
"""Return a bumped release tuple consisting of 3 numbers.""" | ||
major, minor, patch = release | ||
|
||
if bump_type == "patch": | ||
patch += 1 | ||
elif bump_type == "minor": | ||
minor += 1 | ||
patch = 0 | ||
elif bump_type == "major": | ||
major += 1 | ||
minor = 0 | ||
patch = 0 | ||
|
||
return major, minor, patch | ||
|
||
|
||
def bump_version(version, bump_type): | ||
"""Return a new version given a current version and action.""" | ||
new_release = _bump_release(version.release, bump_type) | ||
temp = Version("0") | ||
temp._version = version._version._replace(release=new_release) | ||
return Version(str(temp)) | ||
|
||
|
||
def write_version(version): | ||
"""Update plexapi constant file with new version.""" | ||
with open("plexapi/const.py") as f: | ||
content = f.read() | ||
|
||
version_names = ["MAJOR", "MINOR", "PATCH"] | ||
version_values = str(version).split(".", 2) | ||
|
||
for n, v in zip(version_names, version_values): | ||
version_line = f"{n}_VERSION = " | ||
content = re.sub(f"{version_line}.*\n", f"{version_line}{v}\n", content) | ||
|
||
with open("plexapi/const.py", "wt") as f: | ||
content = f.write(content) | ||
|
||
|
||
def main(): | ||
"""Execute script.""" | ||
parser = argparse.ArgumentParser(description="Bump version of plexapi") | ||
parser.add_argument( | ||
"bump_type", | ||
help="The type of version bump to perform", | ||
choices=SUPPORTED_BUMP_TYPES, | ||
) | ||
parser.add_argument( | ||
"--commit", action="store_true", help="Create a version bump commit" | ||
) | ||
parser.add_argument( | ||
"--tag", action="store_true", help="Tag the commit with the release version" | ||
) | ||
arguments = parser.parse_args() | ||
|
||
if arguments.tag and not arguments.commit: | ||
parser.error("--tag requires use of --commit") | ||
|
||
if arguments.commit and subprocess.run(["git", "diff", "--quiet"]).returncode == 1: | ||
print("Cannot use --commit because git is dirty") | ||
return | ||
|
||
current = Version(const.__version__) | ||
bumped = bump_version(current, arguments.bump_type) | ||
assert bumped > current, "Bumped version is not newer than old version" | ||
|
||
write_version(bumped) | ||
|
||
if not arguments.commit: | ||
return | ||
|
||
subprocess.run(["git", "commit", "-nam", f"Release {bumped}"]) | ||
|
||
if arguments.tag: | ||
subprocess.run(["git", "tag", str(bumped), "-m", f"Release {bumped}"]) | ||
|
||
def test_bump_version(): | ||
"""Make sure it all works.""" | ||
import pytest | ||
|
||
assert bump_version(Version("4.7.0"), "patch") == Version("4.7.1") | ||
assert bump_version(Version("4.7.0"), "minor") == Version("4.8.0") | ||
assert bump_version(Version("4.7.3"), "minor") == Version("4.8.0") | ||
assert bump_version(Version("4.7.0"), "major") == Version("5.0.0") | ||
assert bump_version(Version("4.7.3"), "major") == Version("5.0.0") | ||
assert bump_version(Version("5.0.0"), "major") == Version("6.0.0") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |