Upgrade to python-tools-scripts==0.10.1 and make use of it's virtualenv support

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-01-27 14:06:49 +00:00
parent 3ed7ce13f2
commit 8d5a309fa0
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF
7 changed files with 67 additions and 34 deletions

View file

@ -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: |

View file

@ -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

View file

@ -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

View file

@ -1,4 +1,4 @@
python-tools-scripts >= 0.9.7
python-tools-scripts >= 0.10.1
attrs
boto3
pyyaml

View file

@ -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:

View file

@ -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):

View file

@ -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: