Skip to content

Commit

Permalink
simplify build info field
Browse files Browse the repository at this point in the history
  • Loading branch information
StardustDL committed Mar 13, 2024
1 parent af19245 commit 602efaf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
26 changes: 8 additions & 18 deletions src/aexpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

__version__ = "0.4.3"

COMMIT_ID = "<GIT_COMMIT>"
SHORT_COMMIT_ID = COMMIT_ID[:7]

try:
BUILD_DATE = datetime.fromisoformat("<BUILD_DATE>")
except Exception:
BUILD_DATE = datetime.now()


LOGGING_FORMAT = "%(levelname)s %(asctime)s %(name)s [%(pathname)s:%(lineno)d:%(funcName)s]\n%(message)s\n"
LOGGING_DATEFMT = "%Y-%m-%d,%H:%M:%S"
Expand Down Expand Up @@ -33,24 +41,6 @@ def getWorkingDirectory():
return pathlib.Path(os.getcwd()).resolve()


@cache
def getCommitId() -> str:
return "<GIT_COMMIT>"


@cache
def getShortCommitId() -> str:
return getCommitId()[:7]


@cache
def getBuildDate():
try:
return datetime.fromisoformat("<BUILD_DATE>")
except:
return datetime.now()


@cache
def runInContainer():
return bool(os.getenv("RUN_IN_CONTAINER", False))
Expand Down
8 changes: 4 additions & 4 deletions src/aexpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

from . import (
__version__,
getBuildDate,
getShortCommitId,
BUILD_DATE,
SHORT_COMMIT_ID,
initializeLogging,
runInContainer,
)
Expand Down Expand Up @@ -109,8 +109,8 @@ def exitWithContext[T: Product](context: ProduceContext[T]):
def versionMessage():
parts = [
"%(prog)s v%(version)s",
getShortCommitId(),
str(getBuildDate().date()),
SHORT_COMMIT_ID,
str(BUILD_DATE),
]
if runInContainer():
parts.append("in-container")
Expand Down
4 changes: 2 additions & 2 deletions src/aexpy/services.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from contextlib import contextmanager
from logging import Logger

from . import __version__, getShortCommitId
from . import __version__, SHORT_COMMIT_ID
from .diffing import Differ
from .environments import ExecutionEnvironment, ExecutionEnvironmentBuilder
from .extracting import Extractor
Expand All @@ -14,7 +14,7 @@

class ServiceProvider:
def __init__(self, name: str | None = None) -> None:
self.name = name or f"aexpy@{__version__}-{getShortCommitId()}"
self.name = name or f"aexpy@{__version__}-{SHORT_COMMIT_ID}"

def environmentBuilder(
self, /, logger: Logger | None = None
Expand Down

0 comments on commit 602efaf

Please sign in to comment.