|
22 | 22 | # SOFTWARE. |
23 | 23 |
|
24 | 24 | """A library that provides a Python interface to the Ballchasing API.""" |
25 | | -from __future__ import absolute_import |
| 25 | +import sys |
26 | 26 |
|
27 | | -__author__ = 'Rolv-Arild Braaten' |
28 | | - |
29 | | -__copyright__ = 'Copyright (c) 2020 Rolv-Arild Braaten' |
30 | | -__license__ = 'Apache License 2.0' |
31 | | -__version__ = '0.1.22' |
32 | | -__url__ = 'https://github.com/Rolv-Arild/python-ballchasing' |
33 | | -__download_url__ = 'https://pypi.python.org/pypi/python-ballchasing' |
34 | | -__description__ = 'A Python wrapper around the Ballchasing API' |
| 27 | +# In Python 3.8+, importlib.metadata is in the standard library. |
| 28 | +# For older versions, a backport is available as importlib_metadata. |
| 29 | +if sys.version_info >= (3, 8): |
| 30 | + from importlib.metadata import version, metadata |
| 31 | +else: |
| 32 | + from importlib_metadata import version, metadata |
35 | 33 |
|
36 | | -from .api import Api # noqa |
37 | | -from .constants import ( # noqa |
| 34 | +try: |
| 35 | + # This will read the version from the installed package's metadata |
| 36 | + # (which is defined in pyproject.toml) |
| 37 | + __version__ = version("python-ballchasing") |
| 38 | + |
| 39 | + # You can also get other metadata in a similar way |
| 40 | + pkg_metadata = metadata("python-ballchasing") |
| 41 | + __author__ = pkg_metadata.get("Author-Email") |
| 42 | + __description__ = pkg_metadata.get("Summary") |
| 43 | +except Exception: |
| 44 | + # If the package is not installed (e.g., when running in a development |
| 45 | + # environment without an editable install), you can fall back to defaults. |
| 46 | + __version__ = "0.0.0-dev" |
| 47 | + __description__ = 'A Python wrapper around the Ballchasing API' |
| 48 | + __author__ = 'Rolv-Arild Braaten <[email protected]>' |
| 49 | + |
| 50 | +# Import the main classes and constants to make them easily accessible to users. |
| 51 | +from .api import BallchasingApi |
| 52 | + |
| 53 | +Api = BallchasingApi # For importing like `import ballchasing; api = ballchasing.Api` |
| 54 | + |
| 55 | +from .constants import ( |
38 | 56 | Playlist, |
39 | 57 | Rank, |
40 | 58 | Season, |
|
0 commit comments