Skip to content

Commit

Permalink
Move info text into separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
gutzbenj committed Mar 9, 2024
1 parent 12cf213 commit 046410e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
46 changes: 44 additions & 2 deletions wetterdienst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2021, earthobservations developers.
# Distributed under the MIT License. See LICENSE for more info.
from dataclasses import asdict, dataclass
from textwrap import dedent

from wetterdienst import boot
from wetterdienst.api import Wetterdienst
from wetterdienst.boot import get_info_text
from wetterdienst.metadata.kind import Kind
from wetterdienst.metadata.parameter import Parameter
from wetterdienst.metadata.period import Period
Expand All @@ -16,10 +18,50 @@
__version__ = boot.get_version(__appname__)


@dataclass
class Author:
name: str
email: str
github_handle: str


class Info:
def __init__(self):
self.__version__ = __version__
self.authors = [
Author("Benjamin Gutzmann", "gutzemann@gmail.com", "gutzbenj"),
Author("Andreas Motl", "andreas.motl@panodata.org", "amotl"),
]
self.documentation = "https://wetterdienst.readthedocs.io"
self.repository = "https://github.com/earthobservations/wetterdienst"
self.cache_dir = Settings().cache_dir

def __str__(self):
return dedent(f"""
===========================================
Wetterdienst - Open weather data for humans
===========================================
version: {self.__version__}
authors: {', '.join([f"{author.name} <{author.email}>" for author in self.authors])}
documentation: {self.documentation}
repository: {self.repository}
cache_dir (default): {self.cache_dir}
""").strip()

def to_dict(self):
return {
"version": self.__version__,
"authors": [asdict(author) for author in self.authors],
"documentation": self.documentation,
"repository": self.repository,
"cache_dir": self.cache_dir,
}


__all__ = [
"__appname__",
"__version__",
"get_info_text",
"Info",
"Kind",
"Parameter",
"Period",
Expand Down
18 changes: 0 additions & 18 deletions wetterdienst/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2023, earthobservations developers.
# Distributed under the MIT License. See LICENSE for more info.
from textwrap import dedent


def get_version(appname):
Expand All @@ -12,20 +11,3 @@ def get_version(appname):
return version(appname)
except PackageNotFoundError: # pragma: no cover
return "unknown"


def get_info_text() -> str:
"""Print basic information about the wetterdienst package"""
from wetterdienst import Settings, __version__

info = f"""
===========================================
Wetterdienst - Open weather data for humans
===========================================
version: {__version__}
authors: Benjamin Gutzmann <gutzemann@gmail.com>, Andreas Motl <andreas.motl@panodata.org>"
documentation: https://wetterdienst.readthedocs.io
repository: https://github.com/earthobservations/wetterdienst
cache_dir (default): {Settings().cache_dir}
"""
return dedent(info).strip()
5 changes: 2 additions & 3 deletions wetterdienst/ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,9 @@ def cache():

@cli.command("info", section=basic_section)
def info():
from wetterdienst import get_info_text
from wetterdienst import Info

info_text = get_info_text()
print(info_text) # noqa: T201
print(Info()) # noqa: T201
return


Expand Down

0 comments on commit 046410e

Please sign in to comment.