Issues (2)

tyrannosaurus/__init__.py (2 issues)

1
"""
2
Metadata for Tyrannosaurus.
3
4
Original source: https://github.com/dmyersturnbull/tyrannosaurus
5
Copyright 2020–2021 Douglas Myers-Turnbull
6
Licensed under the Apache License, Version 2.0 (the "License");
7
you may not use this file except in compliance with the License.
8
You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
9
"""
10
import logging
11
12
from datetime import datetime, timezone
13
from importlib.metadata import PackageNotFoundError
14
from importlib.metadata import metadata as __load
15
from pathlib import Path
16
17
18
pkg = Path(__file__).absolute().parent.name
19
logger = logging.getLogger(pkg)
20
metadata = None
21
try:
22
    metadata = __load(pkg)
23
    __status__ = "Development"
24
    __copyright__ = "Copyright 2020–2021"
25
    __date__ = "2020-09-25"
26
    __uri__ = metadata["home-page"]
27
    __title__ = metadata["name"]
28
    __summary__ = metadata["summary"]
29
    __license__ = metadata["license"]
30
    __version__ = metadata["version"]
31
    __author__ = metadata["author"]
32
    __maintainer__ = metadata["maintainer"]
33
    __contact__ = metadata["maintainer"]
34
except PackageNotFoundError:  # pragma: no cover
35
    logger.error(f"Could not load package metadata for {pkg}. Is it installed?")
36
37
38
class TyrannoInfo:
39
    copyright = __copyright__
0 ignored issues
show
The variable __copyright__ does not seem to be defined for all execution paths.
Loading history...
40
    version = __version__
0 ignored issues
show
The variable __version__ does not seem to be defined for all execution paths.
Loading history...
41
    now_utc = datetime.now(timezone.utc)
42
    now = now_utc.astimezone()
43
    today = now.date()
44
    datestamp = now.strftime("%Y-%m-%d")
45
    timestamp = now.strftime("%Y-%m-%dT%H-%M-%S")
46
    pretty_timestamp_utc = (
47
        now_utc.replace(microsecond=0).isoformat().replace("T", " ").replace("+00:00", " Z")
48
    )
49
    pretty_timestamp_with_offset = now.strftime("%Y-%m-%d %H-%M-%S") + " " + now.isoformat()[-6:]
50
51
52
if __name__ == "__main__":  # pragma: no cover
53
    if metadata is not None:
54
        print(f"{pkg} (v{metadata['version']})")
55
    else:
56
        print(f"Unknown project info for {pkg}")
57