Browse Source

fix: use importlib.metadata to get versions

tags/v0.10.10
Jérôme Deuchnord 2 years ago
parent
commit
ea428c8877
7 changed files with 42 additions and 35 deletions
  1. +1
    -1
      Makefile
  2. +3
    -5
      kosmorro/__main__.py
  3. +3
    -3
      kosmorro/dumper.py
  4. +19
    -19
      kosmorro/locales/messages.pot
  5. +8
    -0
      kosmorro/utils.py
  6. +7
    -7
      poetry.lock
  7. +1
    -0
      pyproject.toml

+ 1
- 1
Makefile View File

@@ -1,5 +1,5 @@
black: black:
poetry run black kosmorro tests setup.py
poetry run black kosmorro tests


.PHONY: tests .PHONY: tests
tests: tests:


+ 3
- 5
kosmorro/__main__.py View File

@@ -21,14 +21,12 @@ import sys


from babel.dates import format_date from babel.dates import format_date
from kosmorrolib import Position, get_ephemerides, get_events, get_moon_phase from kosmorrolib import Position, get_ephemerides, get_events, get_moon_phase
from kosmorrolib.__version__ import __version__ as kosmorrolib_version
from kosmorrolib.exceptions import OutOfRangeDateError from kosmorrolib.exceptions import OutOfRangeDateError
from datetime import date from datetime import date


from . import dumper, environment, debug from . import dumper, environment, debug
from .date import parse_date from .date import parse_date
from .utils import colored, set_colors_activated
from .__version__ import __version__ as kosmorro_version
from .utils import KOSMORRO_VERSION, KOSMORROLIB_VERSION, colored, set_colors_activated
from .exceptions import UnavailableFeatureError, OutOfRangeDateError as DateRangeError from .exceptions import UnavailableFeatureError, OutOfRangeDateError as DateRangeError
from kosmorro.i18n.utils import _ from kosmorro.i18n.utils import _


@@ -198,12 +196,12 @@ def output_version() -> bool:
sys.version_info[1], sys.version_info[1],
sys.version_info[2], sys.version_info[2],
) )
print("Kosmorro %s" % kosmorro_version)
print("Kosmorro %s" % KOSMORRO_VERSION)
print( print(
_( _(
"Running on Python {python_version} " "Running on Python {python_version} "
"with Kosmorrolib v{kosmorrolib_version}" "with Kosmorrolib v{kosmorrolib_version}"
).format(python_version=python_version, kosmorrolib_version=kosmorrolib_version)
).format(python_version=python_version, kosmorrolib_version=KOSMORROLIB_VERSION)
) )


return True return True


+ 3
- 3
kosmorro/dumper.py View File

@@ -32,14 +32,14 @@ from termcolor import colored
from kosmorrolib import AsterEphemerides, Event, EventType from kosmorrolib import AsterEphemerides, Event, EventType
from kosmorrolib.model import ASTERS, MoonPhase from kosmorrolib.model import ASTERS, MoonPhase


from .i18n.utils import _, FULL_DATE_FORMAT, SHORT_DATETIME_FORMAT, TIME_FORMAT
from .i18n.utils import _
from .i18n import strings from .i18n import strings
from .__version__ import __version__ as version
from .exceptions import ( from .exceptions import (
CompileError, CompileError,
UnavailableFeatureError as KosmorroUnavailableFeatureError, UnavailableFeatureError as KosmorroUnavailableFeatureError,
) )
from .debug import debug_print from .debug import debug_print
from .utils import KOSMORRO_VERSION




class Dumper(ABC): class Dumper(ABC):
@@ -301,7 +301,7 @@ class _LatexDumper(Dumper):
def add_strings( def add_strings(
self, document: str, kosmorro_logo_path: str, moon_phase_graphics: str self, document: str, kosmorro_logo_path: str, moon_phase_graphics: str
) -> str: ) -> str:
document = document.replace("+++KOSMORRO-VERSION+++", version)
document = document.replace("+++KOSMORRO-VERSION+++", KOSMORRO_VERSION)
document = document.replace("+++KOSMORRO-LOGO+++", kosmorro_logo_path) document = document.replace("+++KOSMORRO-LOGO+++", kosmorro_logo_path)
document = document.replace("+++DOCUMENT-TITLE+++", _("Overview of your sky")) document = document.replace("+++DOCUMENT-TITLE+++", _("Overview of your sky"))
document = document.replace( document = document.replace(


+ 19
- 19
kosmorro/locales/messages.pot View File

@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PROJECT VERSION\n" "Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-03-19 13:28+0100\n"
"POT-Creation-Date: 2022-03-20 11:00+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,98 +17,98 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.9.1\n" "Generated-By: Babel 2.9.1\n"


#: kosmorro/__main__.py:63
#: kosmorro/__main__.py:61
msgid "" msgid ""
"Save the planet and paper!\n" "Save the planet and paper!\n"
"Consider printing your PDF document only if really necessary, and use the" "Consider printing your PDF document only if really necessary, and use the"
" other side of the sheet." " other side of the sheet."
msgstr "" msgstr ""


#: kosmorro/__main__.py:72
#: kosmorro/__main__.py:70
msgid "" msgid ""
"PDF output will not contain the ephemerides, because you didn't provide " "PDF output will not contain the ephemerides, because you didn't provide "
"the observation coordinates." "the observation coordinates."
msgstr "" msgstr ""


#: kosmorro/__main__.py:117
#: kosmorro/__main__.py:115
msgid "The file could not be saved in \"{path}\": {error}" msgid "The file could not be saved in \"{path}\": {error}"
msgstr "" msgstr ""


#: kosmorro/__main__.py:131
#: kosmorro/__main__.py:129
msgid "Please provide a file path to export in this format (--output)." msgid "Please provide a file path to export in this format (--output)."
msgstr "" msgstr ""


#: kosmorro/__main__.py:164
#: kosmorro/__main__.py:162
msgid "Moon phase can only be computed between {min_date} and {max_date}" msgid "Moon phase can only be computed between {min_date} and {max_date}"
msgstr "" msgstr ""


#: kosmorro/__main__.py:203
#: kosmorro/__main__.py:201
msgid "Running on Python {python_version} with Kosmorrolib v{kosmorrolib_version}" msgid "Running on Python {python_version} with Kosmorrolib v{kosmorrolib_version}"
msgstr "" msgstr ""


#: kosmorro/__main__.py:216
#: kosmorro/__main__.py:214
msgid "" msgid ""
"Compute the ephemerides and the events for a given date and a given " "Compute the ephemerides and the events for a given date and a given "
"position on Earth." "position on Earth."
msgstr "" msgstr ""


#: kosmorro/__main__.py:219
#: kosmorro/__main__.py:217
msgid "" msgid ""
"By default, only the events will be computed for today.\n" "By default, only the events will be computed for today.\n"
"To compute also the ephemerides, latitude and longitude arguments are " "To compute also the ephemerides, latitude and longitude arguments are "
"needed." "needed."
msgstr "" msgstr ""


#: kosmorro/__main__.py:232
#: kosmorro/__main__.py:230
msgid "Show the program version" msgid "Show the program version"
msgstr "" msgstr ""


#: kosmorro/__main__.py:240
#: kosmorro/__main__.py:238
msgid "The format to output the information to" msgid "The format to output the information to"
msgstr "" msgstr ""


#: kosmorro/__main__.py:247
#: kosmorro/__main__.py:245
msgid "" msgid ""
"The observer's latitude on Earth. Can also be set in the " "The observer's latitude on Earth. Can also be set in the "
"KOSMORRO_LATITUDE environment variable." "KOSMORRO_LATITUDE environment variable."
msgstr "" msgstr ""


#: kosmorro/__main__.py:257
#: kosmorro/__main__.py:255
msgid "" msgid ""
"The observer's longitude on Earth. Can also be set in the " "The observer's longitude on Earth. Can also be set in the "
"KOSMORRO_LONGITUDE environment variable." "KOSMORRO_LONGITUDE environment variable."
msgstr "" msgstr ""


#: kosmorro/__main__.py:267
#: kosmorro/__main__.py:265
msgid "" msgid ""
"The date for which the ephemerides must be calculated. Can be in the " "The date for which the ephemerides must be calculated. Can be in the "
"YYYY-MM-DD format or an interval in the \"[+-]YyMmDd\" format (with Y, M," "YYYY-MM-DD format or an interval in the \"[+-]YyMmDd\" format (with Y, M,"
" and D numbers). Defaults to current date." " and D numbers). Defaults to current date."
msgstr "" msgstr ""


#: kosmorro/__main__.py:278
#: kosmorro/__main__.py:276
msgid "" msgid ""
"The timezone to display the hours in (e.g. 2 for UTC+2 or -3 for UTC-3). " "The timezone to display the hours in (e.g. 2 for UTC+2 or -3 for UTC-3). "
"Can also be set in the KOSMORRO_TIMEZONE environment variable." "Can also be set in the KOSMORRO_TIMEZONE environment variable."
msgstr "" msgstr ""


#: kosmorro/__main__.py:287
#: kosmorro/__main__.py:285
msgid "Disable the colors in the console." msgid "Disable the colors in the console."
msgstr "" msgstr ""


#: kosmorro/__main__.py:294
#: kosmorro/__main__.py:292
msgid "" msgid ""
"A file to export the output to. If not given, the standard output is " "A file to export the output to. If not given, the standard output is "
"used. This argument is needed for PDF format." "used. This argument is needed for PDF format."
msgstr "" msgstr ""


#: kosmorro/__main__.py:303
#: kosmorro/__main__.py:301
msgid "" msgid ""
"Do not generate a graph to represent the rise and set times in the PDF " "Do not generate a graph to represent the rise and set times in the PDF "
"format." "format."
msgstr "" msgstr ""


#: kosmorro/__main__.py:311
#: kosmorro/__main__.py:309
msgid "Show debugging messages" msgid "Show debugging messages"
msgstr "" msgstr ""




+ 8
- 0
kosmorro/utils.py View File

@@ -2,6 +2,14 @@


from termcolor import colored as do_color from termcolor import colored as do_color


try:
from importlib.metadata import version
except ImportError:
from importlib_metadata import version

KOSMORRO_VERSION = version("kosmorro")
KOSMORROLIB_VERSION = version("kosmorrolib")



global _COLORS_ACTIVATED global _COLORS_ACTIVATED




+ 7
- 7
poetry.lock View File

@@ -98,7 +98,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
name = "importlib-metadata" name = "importlib-metadata"
version = "4.11.3" version = "4.11.3"
description = "Read metadata from Python packages" description = "Read metadata from Python packages"
category = "dev"
category = "main"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"


@@ -259,7 +259,7 @@ six = ">=1.5"


[[package]] [[package]]
name = "pytz" name = "pytz"
version = "2021.3"
version = "2022.1"
description = "World timezone definitions, modern and historical" description = "World timezone definitions, modern and historical"
category = "main" category = "main"
optional = false optional = false
@@ -346,7 +346,7 @@ python-versions = ">=3.6"
name = "typing-extensions" name = "typing-extensions"
version = "4.1.1" version = "4.1.1"
description = "Backported and Experimental Type Hints for Python 3.6+" description = "Backported and Experimental Type Hints for Python 3.6+"
category = "dev"
category = "main"
optional = false optional = false
python-versions = ">=3.6" python-versions = ">=3.6"


@@ -354,7 +354,7 @@ python-versions = ">=3.6"
name = "zipp" name = "zipp"
version = "3.7.0" version = "3.7.0"
description = "Backport of pathlib-compatible object wrapper for zip files" description = "Backport of pathlib-compatible object wrapper for zip files"
category = "dev"
category = "main"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"


@@ -365,7 +365,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = ">=3.7,<3.11" python-versions = ">=3.7,<3.11"
content-hash = "4c2045cb19d088e3205728efd723e8255ded94f211f21ca7f64aea90c05fe3ad"
content-hash = "4973cb3aa5b8437ba3e2cd3c9daee2a168e242b534b6aa9b039b79af7dd2e270"


[metadata.files] [metadata.files]
atomicwrites = [ atomicwrites = [
@@ -484,8 +484,8 @@ python-dateutil = [
{file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"},
] ]
pytz = [ pytz = [
{file = "pytz-2021.3-py2.py3-none-any.whl", hash = "sha256:3672058bc3453457b622aab7a1c3bfd5ab0bdae451512f6cf25f64ed37f5b87c"},
{file = "pytz-2021.3.tar.gz", hash = "sha256:acad2d8b20a1af07d4e4c9d2e9285c5ed9104354062f275f3fcd88dcef4f1326"},
{file = "pytz-2022.1-py2.py3-none-any.whl", hash = "sha256:e68985985296d9a66a881eb3193b0906246245294a881e7c8afe623866ac6a5c"},
{file = "pytz-2022.1.tar.gz", hash = "sha256:1e760e2fe6a8163bc0b3d9a19c4f84342afa0a2affebfaa84b01b978a02ecaa7"},
] ]
sgp4 = [ sgp4 = [
{file = "sgp4-2.20-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:b2169cd536355fc67e3870acea34c4fc22b2ccecab2c0bf45a01edfe646fe3d0"}, {file = "sgp4-2.20-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:b2169cd536355fc67e3870acea34c4fc22b2ccecab2c0bf45a01edfe646fe3d0"},


+ 1
- 0
pyproject.toml View File

@@ -21,6 +21,7 @@ termcolor = "^1.1"
kosmorrolib = "^1.0" kosmorrolib = "^1.0"
python-dateutil = "^2.8" python-dateutil = "^2.8"
Babel = "^2.9" Babel = "^2.9"
importlib-metadata = "^4.11"


[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
black = "^21.12b0" black = "^21.12b0"


Loading…
Cancel
Save