From 67c18e3b5f4ac3c4ef316cff7be2468647952edf Mon Sep 17 00:00:00 2001 From: Brian Bouterse Date: Fri, 4 Dec 2020 15:35:25 -0500 Subject: [PATCH] Moves version to PulpPluginAppConfig subclass 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 --- CHANGES/7943.feature | 4 +++ templates/bootstrap/.bumpversion.cfg.j2 | 4 ++- .../bootstrap/plugin_name/__init__.py.j2 | 2 -- .../bootstrap/plugin_name/app/__init__.py.j2 | 1 + templates/docs/docs/conf.py.j2 | 6 ++-- templates/github/.ci/scripts/release.py.j2 | 32 ++++++++++++------- 6 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 CHANGES/7943.feature diff --git a/CHANGES/7943.feature b/CHANGES/7943.feature new file mode 100644 index 00000000..09ff69e1 --- /dev/null +++ b/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__``. diff --git a/templates/bootstrap/.bumpversion.cfg.j2 b/templates/bootstrap/.bumpversion.cfg.j2 index a5591106..b74b5775 100644 --- a/templates/bootstrap/.bumpversion.cfg.j2 +++ b/templates/bootstrap/.bumpversion.cfg.j2 @@ -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] diff --git a/templates/bootstrap/plugin_name/__init__.py.j2 b/templates/bootstrap/plugin_name/__init__.py.j2 index 95fde7c1..e9c6c60f 100644 --- a/templates/bootstrap/plugin_name/__init__.py.j2 +++ b/templates/bootstrap/plugin_name/__init__.py.j2 @@ -1,3 +1 @@ -__version__ = "0.1.0a1.dev" - default_app_config = "{{ plugin_snake }}.app.{{ plugin_camel }}PluginAppConfig" diff --git a/templates/bootstrap/plugin_name/app/__init__.py.j2 b/templates/bootstrap/plugin_name/app/__init__.py.j2 index 107c03e0..7fb9a8c9 100644 --- a/templates/bootstrap/plugin_name/app/__init__.py.j2 +++ b/templates/bootstrap/plugin_name/app/__init__.py.j2 @@ -6,3 +6,4 @@ class {{ plugin_camel }}PluginAppConfig(PulpPluginAppConfig): name = "{{ plugin_snake }}.app" label = "{{ plugin_app_label }}" + version = "0.1.0a1.dev" diff --git a/templates/docs/docs/conf.py.j2 b/templates/docs/docs/conf.py.j2 index 6a5e0e7c..579f7f96 100644 --- a/templates/docs/docs/conf.py.j2 +++ b/templates/docs/docs/conf.py.j2 @@ -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: @@ -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. diff --git a/templates/github/.ci/scripts/release.py.j2 b/templates/github/.ci/scripts/release.py.j2 index a99da934..05ded0bc 100644 --- a/templates/github/.ci/scripts/release.py.j2 +++ b/templates/github/.ci/scripts/release.py.j2 @@ -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("*"): @@ -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") @@ -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")