Skip to content

Commit

Permalink
Merge branch 'main' into jlf/fix-package-build
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Louis Fuchs authored Mar 14, 2024
2 parents 83e5005 + 73a909e commit a4a2565
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 72 deletions.
58 changes: 0 additions & 58 deletions TODO

This file was deleted.

18 changes: 18 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# CHANGELOG

- CHANGELOG convert to toml
- CHANGELOG.rst rename to CHANGELOG.md
- CHANELOG.md generate from toml
- RPM_SPEC generate changelog from toml

# Docs

- Remove sphinx-doc tags from documentation -> currently deferred

# Release

- remove pyp2rpm and just put a spec into build-rpm, like in venv-rpm (maybe)

- venv-rpm hardcodes version 2.0.0 in some places

- review rpm build and improve it later
58 changes: 49 additions & 9 deletions pyaptly/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import logging
import os
import subprocess
import sys
import traceback
from pathlib import Path

from colorama import Fore, init
from subprocess import PIPE, CalledProcessError # noqa: F401
from tempfile import NamedTemporaryFile
from typing import Optional, Sequence

from colorama import Fore, init

_DEFAULT_KEYSERVER: str = "hkps://keys.openpgp.org"
_PYTEST_KEYSERVER: Optional[str] = None

Expand All @@ -19,7 +22,7 @@
Command call
cmd: {cmd} {color_begin}-> {returncode}{color_end}
""".strip()
OUTPUT_LOG = " {out_type}: '{output}'"
OUTPUT_LOG = " {out_type}:{white_space}'{output}'"
_indent = " " * 15

_isatty_cache: bool | None = None
Expand All @@ -28,6 +31,13 @@
lg = logging.getLogger(__name__)


def write_traceback(): # pragma: no cover
with NamedTemporaryFile("w", delete=False) as tmp:
tmp.write(traceback.format_exc())
tmp.close()
return tmp.name


def isatty():
global _isatty_cache
if _isatty_cache is None:
Expand Down Expand Up @@ -75,27 +85,48 @@ def run_command(
"""
added_stdout = False
added_stderr = False
# TODO assert PIPE or None
if "stdout" not in kwargs:
kwargs["stdout"] = PIPE
added_stdout = True
else:
assert kwargs["stdout"] in (PIPE, None)
if "stderr" not in kwargs:
kwargs["stderr"] = PIPE
added_stderr = True
else:
assert kwargs["stdout"] in (PIPE, None) # pragma: no cover
# If we want to log stdout/err before raising CalledProcessError we have to
# check ourselves
check = False
if "check" in kwargs:
check = kwargs["check"]
del kwargs["check"]
result = None
tb = ""
if decode and "encoding" not in kwargs:
kwargs["encoding"] = "UTF-8"
try:
result = subprocess.run(cmd_args, **kwargs)
if check and result.returncode:
raise CalledProcessError(
result.returncode,
result.args,
output=result.stdout,
stderr=result.stderr,
)
except Exception:
if "pytest" not in sys.modules:
tb = write_traceback() # pragma: no cover
raise
finally:
if result:
log_msg = format_run_result(result, result.returncode)
log_msg = format_run_result(result, result.returncode, tb)
if result.returncode == 0:
lg.info(log_msg)
else:
if not hide_error or lg.root.level <= 20:
lg.error(log_msg)
# Do not change returned result by debug mode
# This function should not alter the returned result
if added_stdout:
delattr(result, "stdout")
if added_stderr:
Expand Down Expand Up @@ -132,7 +163,7 @@ def indent_out(output: bytes | str) -> str:
return "\n".join(result)


def format_run_result(result: subprocess.CompletedProcess, returncode: int):
def format_run_result(result: subprocess.CompletedProcess, returncode: int, tb: str):
"""Format a CompletedProcess result log."""
color_begin = ""
color_end = ""
Expand All @@ -153,11 +184,20 @@ def format_run_result(result: subprocess.CompletedProcess, returncode: int):
stderr=indent_out(result.stderr),
)
]
for out_type, output in [("stdout", result.stdout), ("stderr", result.stderr)]:
for out_type, output in [
("stdout", result.stdout),
("stderr", result.stderr),
("traceback", tb),
]:
output = output.strip()
if output:
output = indent_out(output)
msg.append(OUTPUT_LOG.format(out_type=out_type, output=output))
white_space = " " * (11 - len(out_type))
msg.append(
OUTPUT_LOG.format(
out_type=out_type, white_space=white_space, output=output
)
)
pass
return "\n".join(msg)

Expand Down
5 changes: 0 additions & 5 deletions tools/venv-rpm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Version: 2.0.0^{revision}
Release: 1%{{?dist}}
Summary: Automates the creation and managment of aptly mirrors and snapshots based on toml input files
License: AGPL-3.0-or-later
BuildArch: noarch
Requires: python3.11
%description
Expand Down Expand Up @@ -41,10 +40,6 @@ rm -rf /opt/pyaptly

def main():
os.chdir("/source")
macros = Path("/root/.rpmmacros")
with macros.open("w", encoding="UTF-8") as f:
f.write("%_binaries_in_noarch_packages_terminate_build 0")
f.write("\n")
run(["dnf", "install", "-y", "rpm-build", "python3.11", "git"], check=True)
date = datetime.now().strftime("%a %b %d %Y")
build_id = run(
Expand Down

0 comments on commit a4a2565

Please sign in to comment.