Code cleaning
All checks were successful
Run tests / test-precommit (push) Successful in 56s

This commit is contained in:
Benjamin Renard 2024-04-22 19:20:25 +02:00
parent 81c05a244e
commit 95a013e74b
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

58
gitdch
View file

@ -25,9 +25,7 @@ parser.add_argument("-v", "--verbose", action="store_true", help="Show verbose m
parser.add_argument("-w", "--warning", action="store_true", help="Show warning messages") parser.add_argument("-w", "--warning", action="store_true", help="Show warning messages")
parser.add_argument( parser.add_argument("-l", "--log-file", help="Log file path")
"-l", "--log-file", action="store", type=str, dest="logfile", help="Log file path"
)
parser.add_argument( parser.add_argument(
"-q", "-q",
@ -39,17 +37,13 @@ parser.add_argument(
parser.add_argument( parser.add_argument(
"-p", "-p",
"--path", "--path",
type=str, help=f"Git repository path (default: {DEFAULT_GIT_PATCH})",
dest="git_path",
help="Git repository path (default: %s)" % DEFAULT_GIT_PATCH,
default=DEFAULT_GIT_PATCH, default=DEFAULT_GIT_PATCH,
) )
parser.add_argument( parser.add_argument(
"-o", "-o",
"--output", "--output",
type=str,
dest="output",
help="Generated Debian changelog output path (default: stdout)", help="Generated Debian changelog output path (default: stdout)",
) )
@ -57,7 +51,6 @@ parser.add_argument(
"-A", "-A",
"--append", "--append",
action="store_true", action="store_true",
dest="append",
help=( help=(
"Append mode: if the output changelog file already exists, append " "Append mode: if the output changelog file already exists, append "
"generated changelog lines at the beginning of the file (optional, " "generated changelog lines at the beginning of the file (optional, "
@ -65,72 +58,58 @@ parser.add_argument(
), ),
) )
parser.add_argument("-n", "--package-name", type=str, dest="package_name", help="Package name") parser.add_argument("-n", "--package-name", help="Package name")
parser.add_argument( parser.add_argument(
"-V", "-V",
"--version", "--version",
type=str,
dest="version",
help=("Current version (default: autodetected using git describe " "--always --tags)"), help=("Current version (default: autodetected using git describe " "--always --tags)"),
) )
parser.add_argument( parser.add_argument(
"--version-suffix", type=str, dest="version_suffix", help="Suffix for autodetected version" "--version-suffix",
help="Suffix for autodetected version",
) )
parser.add_argument( parser.add_argument(
"-c", "-c",
"--code-name", "--code-name",
type=str, help=f"Debian code name (default: {DEFAULT_CODE_NAME})",
dest="code_name",
help="Debian code name (default: %s)" % DEFAULT_CODE_NAME,
default=DEFAULT_CODE_NAME, default=DEFAULT_CODE_NAME,
) )
parser.add_argument( parser.add_argument(
"-u", "-u",
"--urgency", "--urgency",
type=str, help=f"Package urgency (default: {DEFAULT_URGENCY})",
dest="urgency",
help="Package urgency (default: %s)" % DEFAULT_URGENCY,
default=DEFAULT_URGENCY, default=DEFAULT_URGENCY,
) )
parser.add_argument( parser.add_argument(
"-N", "-N",
"--maintainer-name", "--maintainer-name",
type=str,
dest="maintainer_name",
help="Maintainer name (default: last commit author name)", help="Maintainer name (default: last commit author name)",
) )
parser.add_argument( parser.add_argument(
"-E", "-E",
"--maintainer-email", "--maintainer-email",
type=str,
dest="maintainer_email",
help="Maintainer email (default: last commit author email)", help="Maintainer email (default: last commit author email)",
) )
parser.add_argument( parser.add_argument(
"-R", "-R",
"--release-notes", "--release-notes",
type=str,
dest="release_notes",
help="Specify an optional Markdown release notes output path", help="Specify an optional Markdown release notes output path",
) )
parser.add_argument( parser.add_argument(
"--revision", "--revision",
type=str,
dest="revision",
help=( help=(
"Specify the revision to use to generate the changelog (see " "Specify the revision to use to generate the changelog (see "
"git-rev-parse for viable options, optional, default: generate the " "git-rev-parse for viable options, optional, default: generate the "
"changelog with all commits of the current branch) " "changelog with all commits of the current branch) "
), ),
default=None,
) )
parser.add_argument( parser.add_argument(
@ -138,7 +117,6 @@ parser.add_argument(
"--clean-tags-regex", "--clean-tags-regex",
action="append", action="append",
type=re.compile, type=re.compile,
dest="clean_tags_regex",
help=( help=(
"Clean tags regex: you could specify regex to clean tag names when " "Clean tags regex: you could specify regex to clean tag names when "
'computing package versions. For instance, to drop a "-eeXXX" suffix ' 'computing package versions. For instance, to drop a "-eeXXX" suffix '
@ -153,7 +131,6 @@ parser.add_argument(
"--exclude", "--exclude",
action="append", action="append",
type=re.compile, type=re.compile,
dest="exclude",
help=( help=(
"Commit exclusion regex: you could specify regex to exclude some " "Commit exclusion regex: you could specify regex to exclude some "
"commits from generated changelog entries. For instance, to exclude " "commits from generated changelog entries. For instance, to exclude "
@ -184,19 +161,19 @@ elif options.verbose:
elif options.warning: elif options.warning:
log_level = logging.WARNING log_level = logging.WARNING
if options.logfile: if options.log_file:
logfile = logging.FileHandler(options.logfile) log_file = logging.FileHandler(options.log_file)
logfile.setFormatter(logformat) log_file.setFormatter(logformat)
logfile.setLevel(log_level if log_level is not None else logging.INFO) log_file.setLevel(log_level if log_level is not None else logging.INFO)
log.addHandler(logfile) log.addHandler(log_file)
if not options.quiet or not options.logfile: if not options.quiet or not options.log_file:
logconsole = logging.StreamHandler() logconsole = logging.StreamHandler()
logconsole.setLevel(log_level if log_level is not None else logging.FATAL) logconsole.setLevel(log_level if log_level is not None else logging.FATAL)
logconsole.setFormatter(logformat) logconsole.setFormatter(logformat)
log.addHandler(logconsole) log.addHandler(logconsole)
repo = git.Repo(options.git_path) repo = git.Repo(options.path)
def clean_deb_version(version_name): def clean_deb_version(version_name):
@ -240,7 +217,7 @@ if options.output and options.append and not options.revision:
"revision." "revision."
) )
# Reset repo object of to avoid BrokenPipeError # Reset repo object of to avoid BrokenPipeError
repo = git.Repo(options.git_path) repo = git.Repo(options.path)
log.info("Generate changelog from git commits") log.info("Generate changelog from git commits")
@ -283,7 +260,10 @@ for commit in repo.iter_commits(rev=options.revision):
if regex.search(commit.summary): if regex.search(commit.summary):
excluded = True excluded = True
log.debug( log.debug(
'Exclude commit %s ("%s", match with "%s")', commit, commit.summary, regex.pattern 'Exclude commit %s ("%s", match with "%s")',
commit,
commit.summary,
regex.pattern,
) )
if not excluded: if not excluded:
messages.append(commit.summary) messages.append(commit.summary)