mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 01:30:20 +00:00
Fix linter warts
This commit is contained in:
parent
d81df5bbe5
commit
f9ed1fd313
2 changed files with 86 additions and 46 deletions
1
.github/workflows/build-rpm-packages.yml
vendored
1
.github/workflows/build-rpm-packages.yml
vendored
|
@ -43,6 +43,7 @@ jobs:
|
||||||
- name: Pip Install Tools Requirements
|
- name: Pip Install Tools Requirements
|
||||||
run: |
|
run: |
|
||||||
pip3 install -r $(pwd)/requirements/static/ci/py3.10/tools.txt
|
pip3 install -r $(pwd)/requirements/static/ci/py3.10/tools.txt
|
||||||
|
pip3 install -r $(pwd)/requirements/static/ci/py3.10/changelog.txt
|
||||||
|
|
||||||
- name: Build RPM
|
- name: Build RPM
|
||||||
env:
|
env:
|
||||||
|
|
|
@ -5,16 +5,12 @@ These commands are used manage Salt's changelog.
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import fnmatch
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import shutil
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import yaml
|
|
||||||
from ptscripts import Context, command_group
|
from ptscripts import Context, command_group
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -29,7 +25,11 @@ def changelog(version):
|
||||||
"""
|
"""
|
||||||
Return the full changelog generated by towncrier.
|
Return the full changelog generated by towncrier.
|
||||||
"""
|
"""
|
||||||
proc = subprocess.run(["towncrier", "build", "--draft", f"--version={version}"], stdout=subprocess.PIPE)
|
proc = subprocess.run(
|
||||||
|
["towncrier", "build", "--draft", f"--version={version}"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
return proc.stdout.decode()
|
return proc.stdout.decode()
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,39 +39,65 @@ def pkg_changelog(version):
|
||||||
"""
|
"""
|
||||||
changes = changelog(version)
|
changes = changelog(version)
|
||||||
changes = "\n".join(changes.split("\n")[2:])
|
changes = "\n".join(changes.split("\n")[2:])
|
||||||
changes = changes.replace(textwrap.dedent("""
|
changes = changes.replace(
|
||||||
|
textwrap.dedent(
|
||||||
|
"""
|
||||||
Removed
|
Removed
|
||||||
-------
|
-------
|
||||||
|
|
||||||
"""), "")
|
"""
|
||||||
changes = changes.replace(textwrap.dedent("""
|
),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
changes = changes.replace(
|
||||||
|
textwrap.dedent(
|
||||||
|
"""
|
||||||
Deprecated
|
Deprecated
|
||||||
----------
|
----------
|
||||||
|
|
||||||
"""), "")
|
"""
|
||||||
changes = changes.replace(textwrap.dedent("""
|
),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
changes = changes.replace(
|
||||||
|
textwrap.dedent(
|
||||||
|
"""
|
||||||
Changed
|
Changed
|
||||||
-------
|
-------
|
||||||
|
|
||||||
"""), "")
|
"""
|
||||||
changes = changes.replace(textwrap.dedent("""
|
),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
changes = changes.replace(
|
||||||
|
textwrap.dedent(
|
||||||
|
"""
|
||||||
Fixed
|
Fixed
|
||||||
-----
|
-----
|
||||||
|
|
||||||
"""), "")
|
"""
|
||||||
changes = changes.replace(textwrap.dedent("""
|
),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
changes = changes.replace(
|
||||||
|
textwrap.dedent(
|
||||||
|
"""
|
||||||
Added
|
Added
|
||||||
-----
|
-----
|
||||||
|
|
||||||
"""), "")
|
"""
|
||||||
|
),
|
||||||
|
"",
|
||||||
|
)
|
||||||
return changes
|
return changes
|
||||||
|
|
||||||
|
|
||||||
def version():
|
def version():
|
||||||
proc = subprocess.run(["python3", "-m", "salt.version"], stdout=subprocess.PIPE, check=True)
|
proc = subprocess.run(
|
||||||
|
["python3", "-m", "salt.version"], stdout=subprocess.PIPE, check=True
|
||||||
|
)
|
||||||
return proc.stdout.decode().strip()
|
return proc.stdout.decode().strip()
|
||||||
|
|
||||||
DEFAULT_VERSION = version()
|
|
||||||
|
|
||||||
@cl.command(
|
@cl.command(
|
||||||
name="update-rpm",
|
name="update-rpm",
|
||||||
|
@ -82,27 +108,35 @@ DEFAULT_VERSION = version()
|
||||||
"it will be discovered by running 'python3 salt/version.py'."
|
"it will be discovered by running 'python3 salt/version.py'."
|
||||||
),
|
),
|
||||||
"nargs": "?",
|
"nargs": "?",
|
||||||
"default": DEFAULT_VERSION,
|
"default": None,
|
||||||
},
|
},
|
||||||
"draft": {
|
"draft": {
|
||||||
"help": (
|
"help": ("Do not make any changes, instead output what would be changed."),
|
||||||
"Do not make any changes, instead output what would be changed."
|
|
||||||
),
|
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"default": False,
|
"default": False,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def update_rpm(ctx: Context, salt_version: str, draft: bool):
|
def update_rpm(ctx: Context, salt_version: str, draft: bool):
|
||||||
proc = subprocess.run(["towncrier", "build", "--draft", f"--version={salt_version}"], stdout=subprocess.PIPE)
|
if salt_version is None:
|
||||||
changes = pgk_changelog(salt_version)
|
salt_version = version()
|
||||||
proc = subprocess.run(["sed", f"s/Version: .*/Version: {salt_version}/g", "pkg/rpm/salt.spec"], stdout=subprocess.PIPE, check=True)
|
proc = subprocess.run(
|
||||||
|
["towncrier", "build", "--draft", f"--version={salt_version}"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
changes = pkg_changelog(salt_version)
|
||||||
|
proc = subprocess.run(
|
||||||
|
["sed", f"s/Version: .*/Version: {salt_version}/g", "pkg/rpm/salt.spec"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
orig = proc.stdout.decode()
|
orig = proc.stdout.decode()
|
||||||
|
|
||||||
dt = datetime.datetime.utcnow()
|
dt = datetime.datetime.utcnow()
|
||||||
date = dt.strftime("%a %b %d %Y")
|
date = dt.strftime("%a %b %d %Y")
|
||||||
header = f"* {date} Salt Project Packaging <saltproject-packaging@vmware.com> - {salt_version}\n"
|
header = f"* {date} Salt Project Packaging <saltproject-packaging@vmware.com> - {salt_version}\n"
|
||||||
parts = orig.split('%changelog')
|
parts = orig.split("%changelog")
|
||||||
tmpspec = "pkg/rpm/salt.spec.1"
|
tmpspec = "pkg/rpm/salt.spec.1"
|
||||||
with open(tmpspec, "w") as wfp:
|
with open(tmpspec, "w") as wfp:
|
||||||
wfp.write(parts[0])
|
wfp.write(parts[0])
|
||||||
|
@ -111,7 +145,7 @@ def update_rpm(ctx: Context, salt_version: str, draft: bool):
|
||||||
wfp.write(changes)
|
wfp.write(changes)
|
||||||
wfp.write(parts[1])
|
wfp.write(parts[1])
|
||||||
try:
|
try:
|
||||||
with open(tmpspec, "r") as rfp:
|
with open(tmpspec) as rfp:
|
||||||
if draft:
|
if draft:
|
||||||
ctx.info(rfp.read())
|
ctx.info(rfp.read())
|
||||||
else:
|
else:
|
||||||
|
@ -130,31 +164,33 @@ def update_rpm(ctx: Context, salt_version: str, draft: bool):
|
||||||
"it will be discovered by running 'python3 salt/version.py'."
|
"it will be discovered by running 'python3 salt/version.py'."
|
||||||
),
|
),
|
||||||
"nargs": "?",
|
"nargs": "?",
|
||||||
"default": DEFAULT_VERSION,
|
"default": None,
|
||||||
},
|
},
|
||||||
"draft": {
|
"draft": {
|
||||||
"help": (
|
"help": ("Do not make any changes, instead output what would be changed."),
|
||||||
"Do not make any changes, instead output what would be changed."
|
|
||||||
),
|
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"default": False,
|
"default": False,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def update_deb(ctx: Context, salt_version: str, draft: bool):
|
def update_deb(ctx: Context, salt_version: str, draft: bool):
|
||||||
|
if salt_version is None:
|
||||||
|
salt_version = version()
|
||||||
changes = pkg_changelog(salt_version)
|
changes = pkg_changelog(salt_version)
|
||||||
formated = "\n".join([f" {_.replace('-', '*', 1)}" for _ in changes.split('\n')])
|
formated = "\n".join([f" {_.replace('-', '*', 1)}" for _ in changes.split("\n")])
|
||||||
dt = datetime.datetime.utcnow()
|
dt = datetime.datetime.utcnow()
|
||||||
date = dt.strftime("%a, %d %b %Y %H:%M:%S +0000")
|
date = dt.strftime("%a, %d %b %Y %H:%M:%S +0000")
|
||||||
tmpchanges = "pkg/rpm/salt.spec.1"
|
tmpchanges = "pkg/rpm/salt.spec.1"
|
||||||
with open(tmpchanges, "w") as wfp:
|
with open(tmpchanges, "w") as wfp:
|
||||||
wfp.write(f"salt ({salt_version}) stable; urgency=medium\n\n")
|
wfp.write(f"salt ({salt_version}) stable; urgency=medium\n\n")
|
||||||
wfp.write(formated)
|
wfp.write(formated)
|
||||||
wfp.write(f"\n -- Salt Project Packaging <saltproject-packaging@vmware.com> {date}\n\n")
|
wfp.write(
|
||||||
with open("pkg/debian/changelog", "r") as rfp:
|
f"\n -- Salt Project Packaging <saltproject-packaging@vmware.com> {date}\n\n"
|
||||||
|
)
|
||||||
|
with open("pkg/debian/changelog") as rfp:
|
||||||
wfp.write(rfp.read())
|
wfp.write(rfp.read())
|
||||||
try:
|
try:
|
||||||
with open(tmpchanges, "r") as rfp:
|
with open(tmpchanges) as rfp:
|
||||||
if draft:
|
if draft:
|
||||||
ctx.info(rfp.read())
|
ctx.info(rfp.read())
|
||||||
else:
|
else:
|
||||||
|
@ -163,6 +199,7 @@ def update_deb(ctx: Context, salt_version: str, draft: bool):
|
||||||
finally:
|
finally:
|
||||||
os.remove(tmpchanges)
|
os.remove(tmpchanges)
|
||||||
|
|
||||||
|
|
||||||
@cl.command(
|
@cl.command(
|
||||||
name="update-release-notes",
|
name="update-release-notes",
|
||||||
arguments={
|
arguments={
|
||||||
|
@ -172,27 +209,27 @@ def update_deb(ctx: Context, salt_version: str, draft: bool):
|
||||||
"it will be discovered by running 'python3 salt/version.py'."
|
"it will be discovered by running 'python3 salt/version.py'."
|
||||||
),
|
),
|
||||||
"nargs": "?",
|
"nargs": "?",
|
||||||
"default": DEFAULT_VERSION,
|
"default": None,
|
||||||
},
|
},
|
||||||
"draft": {
|
"draft": {
|
||||||
"help": (
|
"help": ("Do not make any changes, instead output what would be changed."),
|
||||||
"Do not make any changes, instead output what would be changed."
|
|
||||||
),
|
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"default": False,
|
"default": False,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def update_release_notes(ctx: Context, salt_version: str, draft: bool):
|
def update_release_notes(ctx: Context, salt_version: str, draft: bool):
|
||||||
if "+" in version:
|
if salt_version is None:
|
||||||
|
salt_version = version()
|
||||||
|
if "+" in salt_version:
|
||||||
major_version = salt_version.split("+", 1)[0]
|
major_version = salt_version.split("+", 1)[0]
|
||||||
else:
|
else:
|
||||||
major_vesrion = salt_versionversion
|
major_vesrion = salt_version
|
||||||
changes = changelog(salt_version)
|
changes = changelog(salt_version)
|
||||||
changes = "\n".join(changes.split("\n")[2:])
|
changes = "\n".join(changes.split("\n")[2:])
|
||||||
tmpnotes = f"doc/topics/releases/{version}.rst.tmp"
|
tmpnotes = f"doc/topics/releases/{version}.rst.tmp"
|
||||||
try:
|
try:
|
||||||
with open(f"doc/topics/releases/{major_version}.rst", "r") as rfp:
|
with open(f"doc/topics/releases/{major_version}.rst") as rfp:
|
||||||
existing = rfp.read()
|
existing = rfp.read()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
existing = ""
|
existing = ""
|
||||||
|
@ -200,14 +237,14 @@ def update_release_notes(ctx: Context, salt_version: str, draft: bool):
|
||||||
wfp.write(existing)
|
wfp.write(existing)
|
||||||
wfp.write(changes)
|
wfp.write(changes)
|
||||||
try:
|
try:
|
||||||
with open(tmpnotes, "r") as rfp:
|
with open(tmpnotes) as rfp:
|
||||||
if draft:
|
if draft:
|
||||||
ctx.info(rfp.read())
|
ctx.info(rfp.read())
|
||||||
else:
|
else:
|
||||||
with open(f"doc/topics/releases/{version}.rst", "w") as wfp:
|
with open(f"doc/topics/releases/{version}.rst", "w") as wfp:
|
||||||
wfp.write(rfp.read())
|
wfp.write(rfp.read())
|
||||||
finally:
|
finally:
|
||||||
os.remove(tmpchanges)
|
os.remove(tmpnotes)
|
||||||
|
|
||||||
|
|
||||||
@cl.command(
|
@cl.command(
|
||||||
|
@ -219,7 +256,7 @@ def update_release_notes(ctx: Context, salt_version: str, draft: bool):
|
||||||
"it will be discovered by running 'python3 salt/version.py'."
|
"it will be discovered by running 'python3 salt/version.py'."
|
||||||
),
|
),
|
||||||
"nargs": "?",
|
"nargs": "?",
|
||||||
"default": DEFAULT_VERSION,
|
"default": None,
|
||||||
},
|
},
|
||||||
"draft": {
|
"draft": {
|
||||||
"help": (
|
"help": (
|
||||||
|
@ -231,9 +268,11 @@ def update_release_notes(ctx: Context, salt_version: str, draft: bool):
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def update_release_notes(ctx: Context, salt_version: str, draft: bool):
|
def generate_changelog_md(ctx: Context, salt_version: str, draft: bool):
|
||||||
|
if salt_version is None:
|
||||||
|
salt_version = version()
|
||||||
cmd = ["towncrier", "build", "--version={version}"]
|
cmd = ["towncrier", "build", "--version={version}"]
|
||||||
if draft:
|
if draft:
|
||||||
cmd += ["--draft"]
|
cmd += ["--draft"]
|
||||||
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
|
proc = subprocess.run(cmd, stdout=subprocess.PIPE, check=True)
|
||||||
return proc.stdout.decode()
|
return proc.stdout.decode()
|
||||||
|
|
Loading…
Add table
Reference in a new issue