Skip to content

Commit

Permalink
Moves version to PulpPluginAppConfig subclass
Browse files Browse the repository at this point in the history
Starting with pulpcore==3.9, it's expected for the version of a plugin
to be set as the `version` attribute on the `PulpPluginAppConfig`
subclass which defines the plugin.

This also updates the bumpversion config to set versions in the right
places, and the release script to now parse those locations correctly.

re #7943
  • Loading branch information
bmbouter committed Dec 7, 2020
1 parent 7d78ed7 commit 67c18e3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGES/7943.feature
@@ -0,0 +1,4 @@
Moved the version definition to the ``version`` attribute of ``PulpPluginAppConfig``, and have
``bump2version`` maintain it. Also update the ``docs/conf.py`` to be bump2version maintained. The
release script now parses its versions from ``setup.py`` which is needed for the removal of
``{plugin_name}.__init__.__version__``.
4 changes: 3 additions & 1 deletion templates/bootstrap/.bumpversion.cfg.j2
Expand Up @@ -14,6 +14,8 @@ values =
dev
prod

"[bumpversion:file:./{{ plugin_snake }}/__init__.py]"
"[bumpversion:file:./{{ plugin_snake }}/app/__init__.py]"

[bumpversion:file:./setup.py]

[bumpversion:file:./docs/conf.py]
2 changes: 0 additions & 2 deletions templates/bootstrap/plugin_name/__init__.py.j2
@@ -1,3 +1 @@
__version__ = "0.1.0a1.dev"

default_app_config = "{{ plugin_snake }}.app.{{ plugin_camel }}PluginAppConfig"
1 change: 1 addition & 0 deletions templates/bootstrap/plugin_name/app/__init__.py.j2
Expand Up @@ -6,3 +6,4 @@ class {{ plugin_camel }}PluginAppConfig(PulpPluginAppConfig):

name = "{{ plugin_snake }}.app"
label = "{{ plugin_app_label }}"
version = "0.1.0a1.dev"
6 changes: 2 additions & 4 deletions templates/docs/docs/conf.py.j2
Expand Up @@ -15,8 +15,6 @@ import os
import sys
sys.path.insert(0, os.path.abspath('..')) # noqa

import {{ plugin_snake }}

try:
import sphinx_rtd_theme
except ImportError:
Expand Down Expand Up @@ -57,9 +55,9 @@ copyright = u''
# built documents.
#
# The short X.Y version.
version = {{ plugin_snake }}.__version__
version = "0.1.0a1.dev"
# The full version, including alpha/beta/rc tags.
release = {{ plugin_snake }}.__version__
release = "0.1.0a1.dev"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
32 changes: 20 additions & 12 deletions templates/github/.ci/scripts/release.py.j2
Expand Up @@ -64,12 +64,16 @@ def validate_redmine_data(redmine_query_url, redmine_issues):
release_path = os.path.dirname(os.path.abspath(__file__))
plugin_path = release_path.split("/.ci")[0]

version = {}
plugin_name = "{{ plugin_snake }}"
with open(f"{plugin_path}/{plugin_name}/__init__.py") as fp:
version_line = [line for line in fp.readlines() if "__version__" in line][0]
exec(version_line, version)
release_version = version["__version__"].replace(".dev", "")
version = None
with open(f"{plugin_path}/setup.py") as fp:
for line in fp.readlines():
if "version=" in line:
version = line.split('"')[1]
if not version:
raise RuntimeError("Could not detect existing version ... aborting.")
release_version = version.replace(".dev", "")


issues_to_close = []
for filename in Path(f"{plugin_path}/CHANGES").rglob("*"):
Expand Down Expand Up @@ -150,7 +154,8 @@ with open(f"{plugin_path}/requirements.txt", "wt") as setup_file:

os.system("bump2version release --allow-dirty")

git.add(f"{plugin_path}/{plugin_name}/__init__.py")
git.add(f"{plugin_path}/{plugin_name}/*")
git.add(f"{plugin_path}/docs/conf.py")
git.add(f"{plugin_path}/setup.py")
git.add(f"{plugin_path}/requirements.txt")
git.add(f"{plugin_path}/.bumpversion.cfg")
Expand All @@ -172,14 +177,17 @@ with open(f"{plugin_path}/requirements.txt", "wt") as setup_file:

os.system(f"bump2version {release_type} --allow-dirty")

version = {}
with open(f"{plugin_path}/{plugin_name}/__init__.py") as fp:
version_line = [line for line in fp.readlines() if "__version__" in line][0]
exec(version_line, version)
new_dev_version = version["__version__"]
new_dev_version = None
with open(f"{plugin_path}/setup.py") as fp:
for line in fp.readlines():
if "version=" in line:
new_dev_version = line.split('"')[1]
if not new_dev_version:
raise RuntimeError("Could not detect new dev version ... aborting.")


git.add(f"{plugin_path}/{plugin_name}/__init__.py")
git.add(f"{plugin_path}/{plugin_name}/*")
git.add(f"{plugin_path}/docs/conf.py")
git.add(f"{plugin_path}/setup.py")
git.add(f"{plugin_path}/requirements.txt")
git.add(f"{plugin_path}/.bumpversion.cfg")
Expand Down

0 comments on commit 67c18e3

Please sign in to comment.