From 8d5a309fa07705125a23ffdd50ba501258cba533 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 27 Jan 2023 14:06:49 +0000 Subject: [PATCH] Upgrade to `python-tools-scripts==0.10.1` and make use of it's virtualenv support Signed-off-by: Pedro Algarvio --- .github/actions/release-changes/action.yml | 12 ------- requirements/static/ci/py3.10/tools.txt | 4 ++- requirements/static/ci/py3.9/tools.txt | 4 ++- requirements/static/ci/tools.in | 2 +- tools/changelog.py | 40 +++++++++++++++------- tools/docs.py | 25 +++++++++++--- tools/pkg.py | 14 ++++++-- 7 files changed, 67 insertions(+), 34 deletions(-) diff --git a/.github/actions/release-changes/action.yml b/.github/actions/release-changes/action.yml index 40f4f095574..7795382c5a2 100644 --- a/.github/actions/release-changes/action.yml +++ b/.github/actions/release-changes/action.yml @@ -15,18 +15,6 @@ runs: steps: - - name: Pip Install Tools Requirements - shell: bash - run: | - pip3 install -r $(pwd)/requirements/static/ci/py3.10/tools.txt - pip3 install -r $(pwd)/requirements/static/ci/py3.10/changelog.txt - pip3 install -r $(pwd)/requirements/static/ci/py3.10/docs.txt - - - name: Set salt version - shell: bash - run: | - echo '${{ inputs.salt-version }}' > salt/_version.txt - - name: Update Debian changelog shell: bash run: | diff --git a/requirements/static/ci/py3.10/tools.txt b/requirements/static/ci/py3.10/tools.txt index fd9a24b824b..858e534198c 100644 --- a/requirements/static/ci/py3.10/tools.txt +++ b/requirements/static/ci/py3.10/tools.txt @@ -24,7 +24,7 @@ pygments==2.13.0 # via rich python-dateutil==2.8.2 # via botocore -python-tools-scripts==0.9.7 +python-tools-scripts==0.10.1 # via -r requirements/static/ci/tools.in pyyaml==6.0 # via -r requirements/static/ci/tools.in @@ -34,5 +34,7 @@ s3transfer==0.5.2 # via boto3 six==1.16.0 # via python-dateutil +typing-extensions==4.4.0 + # via python-tools-scripts urllib3==1.26.12 # via botocore diff --git a/requirements/static/ci/py3.9/tools.txt b/requirements/static/ci/py3.9/tools.txt index 31c1a91fd3a..7226647a7e2 100644 --- a/requirements/static/ci/py3.9/tools.txt +++ b/requirements/static/ci/py3.9/tools.txt @@ -24,7 +24,7 @@ pygments==2.13.0 # via rich python-dateutil==2.8.2 # via botocore -python-tools-scripts==0.9.7 +python-tools-scripts==0.10.1 # via -r requirements/static/ci/tools.in pyyaml==6.0 # via -r requirements/static/ci/tools.in @@ -34,5 +34,7 @@ s3transfer==0.5.2 # via boto3 six==1.16.0 # via python-dateutil +typing-extensions==4.4.0 + # via python-tools-scripts urllib3==1.26.12 # via botocore diff --git a/requirements/static/ci/tools.in b/requirements/static/ci/tools.in index 21b4f5f75bb..08ccf6d7245 100644 --- a/requirements/static/ci/tools.in +++ b/requirements/static/ci/tools.in @@ -1,4 +1,4 @@ -python-tools-scripts >= 0.9.7 +python-tools-scripts >= 0.10.1 attrs boto3 pyyaml diff --git a/tools/changelog.py b/tools/changelog.py index 70101bfd6ca..c1b578f06bd 100644 --- a/tools/changelog.py +++ b/tools/changelog.py @@ -9,6 +9,7 @@ import logging import os import pathlib import subprocess +import sys import textwrap from ptscripts import Context, command_group @@ -18,26 +19,41 @@ log = logging.getLogger(__name__) REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent # Define the command group -cl = command_group(name="changelog", help="Changelog tools", description=__doc__) +cl = command_group( + name="changelog", + help="Changelog tools", + description=__doc__, + venv_config={ + "requirements_files": [ + REPO_ROOT + / "requirements" + / "static" + / "ci" + / "py{}.{}".format(*sys.version_info) + / "changelog.txt" + ], + }, +) -def changelog(version): +def changelog(ctx: Context, version: str): """ Return the full changelog generated by towncrier. """ - return subprocess.run( - ["towncrier", "build", "--draft", f"--version={version}"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - check=True, + return ctx.run( + "towncrier", + "build", + "--draft", + f"--version={version}", + capture=True, ).stdout.decode() -def pkg_changelog(version): +def pkg_changelog(ctx: Context, version: str): """ Return a version of the changelog entries suitable for packaged changelogs. """ - changes = changelog(version) + changes = changelog(ctx, version) changes = "\n".join(changes.split("\n")[2:]) changes = changes.replace( textwrap.dedent( @@ -121,7 +137,7 @@ def version(): def update_rpm(ctx: Context, salt_version: str, draft: bool = False): if salt_version is None: salt_version = version() - changes = pkg_changelog(salt_version) + changes = pkg_changelog(ctx, salt_version) ctx.info("Salt version is %s", salt_version) orig = ctx.run( "sed", @@ -171,7 +187,7 @@ def update_rpm(ctx: Context, salt_version: str, draft: bool = False): def update_deb(ctx: Context, salt_version: str, draft: bool = False): if salt_version is None: salt_version = version() - changes = pkg_changelog(salt_version) + changes = pkg_changelog(ctx, salt_version) formated = "\n".join([f" {_.replace('-', '*', 1)}" for _ in changes.split("\n")]) dt = datetime.datetime.utcnow() date = dt.strftime("%a, %d %b %Y %H:%M:%S +0000") @@ -218,7 +234,7 @@ def update_release_notes(ctx: Context, salt_version: str, draft: bool = False): major_version = salt_version.split("+", 1)[0] else: major_version = salt_version - changes = changelog(salt_version) + changes = changelog(ctx, salt_version) changes = "\n".join(changes.split("\n")[2:]) tmpnotes = f"doc/topics/releases/{version}.rst.tmp" try: diff --git a/tools/docs.py b/tools/docs.py index 00d14450ee9..88ec16f56eb 100644 --- a/tools/docs.py +++ b/tools/docs.py @@ -8,6 +8,7 @@ import logging import os import pathlib import shutil +import sys from ptscripts import Context, command_group @@ -16,10 +17,24 @@ log = logging.getLogger(__name__) REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent # Define the command group -doc = command_group(name="docs", help="Manpages tools", description=__doc__) +docs = command_group( + name="docs", + help="Manpages tools", + description=__doc__, + venv_config={ + "requirements_files": [ + REPO_ROOT + / "requirements" + / "static" + / "ci" + / "py{}.{}".format(*sys.version_info) + / "docs.txt" + ], + }, +) -@doc.command( +@docs.command( name="man", ) def man(ctx: Context): @@ -30,7 +45,7 @@ def man(ctx: Context): shutil.copy(os.path.join(root, file), os.path.join("doc/man", file)) -@doc.command( +@docs.command( name="html", ) def html(ctx: Context): @@ -38,7 +53,7 @@ def html(ctx: Context): ctx.run("make", "html", "SHPINXOPTS=-W", cwd="doc/", check=True) -@doc.command( +@docs.command( name="epub", ) def epub(ctx: Context): @@ -46,7 +61,7 @@ def epub(ctx: Context): ctx.run("make", "epub", "SHPINXOPTS=-W", cwd="doc/", check=True) -@doc.command( +@docs.command( name="pdf", ) def pdf(ctx: Context): diff --git a/tools/pkg.py b/tools/pkg.py index 27f3c39c270..54d0a2fb697 100644 --- a/tools/pkg.py +++ b/tools/pkg.py @@ -284,6 +284,11 @@ def generate_hashes(ctx: Context, files: list[pathlib.Path]): @pkg.command( name="source-tarball", + venv_config={ + "requirements_files": [ + REPO_ROOT / "requirements" / "build.txt", + ] + }, ) def source_tarball(ctx: Context): shutil.rmtree("dist/", ignore_errors=True) @@ -295,7 +300,12 @@ def source_tarball(ctx: Context): "HEAD", capture=True, ).stdout.strip() - env = {**os.environ, **{"SOURCE_DATE_EPOCH": str(timestamp)}} + env = { + **os.environ, + **{ + "SOURCE_DATE_EPOCH": str(timestamp), + }, + } ctx.run( "python3", "-m", @@ -308,7 +318,7 @@ def source_tarball(ctx: Context): # Recreate sdist to be reproducible recompress = Recompress(timestamp) for targz in REPO_ROOT.joinpath("dist").glob("*.tar.gz"): - ctx.info("Re-compressing %s...", targz.relative_to(REPO_ROOT)) + ctx.info(f"Re-compressing {targz.relative_to(REPO_ROOT)} ...") recompress.recompress(targz) sha256sum = shutil.which("sha256sum") if sha256sum: