Skip to content

Generate version string dynamically #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions codebasin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2019-2024 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
import importlib.metadata
import os
import shlex
import warnings
Expand All @@ -19,6 +20,8 @@
DeprecationWarning,
)

__version__ = importlib.metadata.version("codebasin")


class CompileCommand:
"""
Expand Down
11 changes: 6 additions & 5 deletions codebasin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import os
import sys

from codebasin import CodeBase, config, finder, report, util
from codebasin import CodeBase, __version__, config, finder, report, util
from codebasin._detail.logging import Formatter, WarningAggregator

log = logging.getLogger("codebasin")
version = "1.2.0"

_traceback = False

Expand Down Expand Up @@ -59,7 +58,7 @@ def _help_string(*lines: str, is_long=False, is_last=False):
def _main():
# Read command-line arguments
parser = argparse.ArgumentParser(
description="Code Base Investigator " + str(version),
description="Code Base Investigator " + str(__version__),
formatter_class=argparse.RawTextHelpFormatter,
add_help=False,
)
Expand All @@ -72,7 +71,7 @@ def _main():
parser.add_argument(
"--version",
action="version",
version=f"Code Base Investigator {version}",
version=f"Code Base Investigator {__version__}",
help=_help_string("Display version information and exit."),
)
parser.add_argument(
Expand Down Expand Up @@ -180,7 +179,9 @@ def _main():
log.addHandler(file_handler)

if args.debug:
log.debug(f"Code Base Investigator {version}; Python {sys.version}")
log.debug(
f"Code Base Investigator {__version__}; Python {sys.version}",
)

# Inform the user that a log file has been created.
# 'print' instead of 'log' to ensure the message is visible in the output.
Expand Down
13 changes: 4 additions & 9 deletions codebasin/coverage/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@
import os
import sys

from codebasin import CodeBase, config, finder, util
from codebasin import CodeBase, __version__, config, finder, util

# TODO: Refactor to avoid imports from __main__
from codebasin.__main__ import (
Formatter,
WarningAggregator,
_help_string,
version,
)
from codebasin.__main__ import Formatter, WarningAggregator, _help_string
from codebasin.preprocessor import CodeNode

log = logging.getLogger("codebasin")
Expand All @@ -28,7 +23,7 @@ def _build_parser() -> argparse.ArgumentParser:
Build argument parser.
"""
parser = argparse.ArgumentParser(
description="CBI Coverage Tool " + version,
description="CBI Coverage Tool " + __version__,
formatter_class=argparse.RawTextHelpFormatter,
add_help=False,
)
Expand All @@ -42,7 +37,7 @@ def _build_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--version",
action="version",
version=f"CBI Coverage Tool {version}",
version=f"CBI Coverage Tool {__version__}",
help="Display version information and exit.",
)

Expand Down
8 changes: 4 additions & 4 deletions codebasin/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import os
import sys

from codebasin import CodeBase, config, finder, report, util
from codebasin import CodeBase, __version__, config, finder, report, util

# TODO: Refactor to avoid imports from __main__
from codebasin.__main__ import Formatter, _help_string, version
from codebasin.__main__ import Formatter, _help_string

log = logging.getLogger("codebasin")

Expand All @@ -20,7 +20,7 @@ def _build_parser() -> argparse.ArgumentParser:
Build argument parser.
"""
parser = argparse.ArgumentParser(
description="CBI Tree Tool " + version,
description="CBI Tree Tool " + __version__,
formatter_class=argparse.RawTextHelpFormatter,
add_help=False,
)
Expand All @@ -33,7 +33,7 @@ def _build_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--version",
action="version",
version=f"CBI Coverage Tool {version}",
version=f"CBI Tree Tool {__version__}",
help=_help_string("Display version information and exit."),
)
parser.add_argument(
Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
# SPDX-License-Identifier: BSD-3-Clause
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools >= 61.0"]
requires = ["setuptools>=64", "setuptools-scm>=8"]

[project]
authors = [
{"name" = "S. John Pennycook", "email" = "[email protected]"},
]
description = "Code Base Investigator"
version = "1.2.0"
dynamic = ["readme"]
dynamic = ["version", "readme"]
keywords = ["performance", "portability", "productivity"]
name = "codebasin"
requires-python = ">=3.9"
Expand Down Expand Up @@ -61,6 +60,9 @@ include = ["codebasin*"]
[tool.setuptools.dynamic]
readme = {file = ["README.md"]}

[tool.setuptools_scm]
# Deliberately empty to enable setuptools-scm

[tool.coverage.run]
command_line = "-m unittest"
source = ["codebasin"]
Expand Down
Loading