diff --git a/Makefile b/Makefile index c371814..d3480fa 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ black: - poetry run black kosmorro tests setup.py + poetry run black kosmorro tests .PHONY: tests tests: diff --git a/kosmorro/__main__.py b/kosmorro/__main__.py index 70ed03b..29863e7 100644 --- a/kosmorro/__main__.py +++ b/kosmorro/__main__.py @@ -21,14 +21,12 @@ import sys from babel.dates import format_date 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 datetime import date from . import dumper, environment, debug 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 kosmorro.i18n.utils import _ @@ -198,12 +196,12 @@ def output_version() -> bool: sys.version_info[1], sys.version_info[2], ) - print("Kosmorro %s" % kosmorro_version) + print("Kosmorro %s" % KOSMORRO_VERSION) print( _( "Running on Python {python_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 diff --git a/kosmorro/dumper.py b/kosmorro/dumper.py index 6758501..844bf99 100644 --- a/kosmorro/dumper.py +++ b/kosmorro/dumper.py @@ -32,14 +32,14 @@ from termcolor import colored from kosmorrolib import AsterEphemerides, Event, EventType 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 .__version__ import __version__ as version from .exceptions import ( CompileError, UnavailableFeatureError as KosmorroUnavailableFeatureError, ) from .debug import debug_print +from .utils import KOSMORRO_VERSION class Dumper(ABC): @@ -301,7 +301,7 @@ class _LatexDumper(Dumper): def add_strings( self, document: str, kosmorro_logo_path: str, moon_phase_graphics: 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("+++DOCUMENT-TITLE+++", _("Overview of your sky")) document = document.replace( diff --git a/kosmorro/locales/messages.pot b/kosmorro/locales/messages.pot index bf05028..7814bb9 100644 --- a/kosmorro/locales/messages.pot +++ b/kosmorro/locales/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,98 +17,98 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.9.1\n" -#: kosmorro/__main__.py:63 +#: kosmorro/__main__.py:61 msgid "" "Save the planet and paper!\n" "Consider printing your PDF document only if really necessary, and use the" " other side of the sheet." msgstr "" -#: kosmorro/__main__.py:72 +#: kosmorro/__main__.py:70 msgid "" "PDF output will not contain the ephemerides, because you didn't provide " "the observation coordinates." msgstr "" -#: kosmorro/__main__.py:117 +#: kosmorro/__main__.py:115 msgid "The file could not be saved in \"{path}\": {error}" msgstr "" -#: kosmorro/__main__.py:131 +#: kosmorro/__main__.py:129 msgid "Please provide a file path to export in this format (--output)." msgstr "" -#: kosmorro/__main__.py:164 +#: kosmorro/__main__.py:162 msgid "Moon phase can only be computed between {min_date} and {max_date}" msgstr "" -#: kosmorro/__main__.py:203 +#: kosmorro/__main__.py:201 msgid "Running on Python {python_version} with Kosmorrolib v{kosmorrolib_version}" msgstr "" -#: kosmorro/__main__.py:216 +#: kosmorro/__main__.py:214 msgid "" "Compute the ephemerides and the events for a given date and a given " "position on Earth." msgstr "" -#: kosmorro/__main__.py:219 +#: kosmorro/__main__.py:217 msgid "" "By default, only the events will be computed for today.\n" "To compute also the ephemerides, latitude and longitude arguments are " "needed." msgstr "" -#: kosmorro/__main__.py:232 +#: kosmorro/__main__.py:230 msgid "Show the program version" msgstr "" -#: kosmorro/__main__.py:240 +#: kosmorro/__main__.py:238 msgid "The format to output the information to" msgstr "" -#: kosmorro/__main__.py:247 +#: kosmorro/__main__.py:245 msgid "" "The observer's latitude on Earth. Can also be set in the " "KOSMORRO_LATITUDE environment variable." msgstr "" -#: kosmorro/__main__.py:257 +#: kosmorro/__main__.py:255 msgid "" "The observer's longitude on Earth. Can also be set in the " "KOSMORRO_LONGITUDE environment variable." msgstr "" -#: kosmorro/__main__.py:267 +#: kosmorro/__main__.py:265 msgid "" "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," " and D numbers). Defaults to current date." msgstr "" -#: kosmorro/__main__.py:278 +#: kosmorro/__main__.py:276 msgid "" "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." msgstr "" -#: kosmorro/__main__.py:287 +#: kosmorro/__main__.py:285 msgid "Disable the colors in the console." msgstr "" -#: kosmorro/__main__.py:294 +#: kosmorro/__main__.py:292 msgid "" "A file to export the output to. If not given, the standard output is " "used. This argument is needed for PDF format." msgstr "" -#: kosmorro/__main__.py:303 +#: kosmorro/__main__.py:301 msgid "" "Do not generate a graph to represent the rise and set times in the PDF " "format." msgstr "" -#: kosmorro/__main__.py:311 +#: kosmorro/__main__.py:309 msgid "Show debugging messages" msgstr "" diff --git a/kosmorro/utils.py b/kosmorro/utils.py index 4ee8da8..2d42e82 100644 --- a/kosmorro/utils.py +++ b/kosmorro/utils.py @@ -2,6 +2,14 @@ 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 diff --git a/poetry.lock b/poetry.lock index 9f4b9c6..46bda78 100644 --- a/poetry.lock +++ b/poetry.lock @@ -98,7 +98,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" name = "importlib-metadata" version = "4.11.3" description = "Read metadata from Python packages" -category = "dev" +category = "main" optional = false python-versions = ">=3.7" @@ -259,7 +259,7 @@ six = ">=1.5" [[package]] name = "pytz" -version = "2021.3" +version = "2022.1" description = "World timezone definitions, modern and historical" category = "main" optional = false @@ -346,7 +346,7 @@ python-versions = ">=3.6" name = "typing-extensions" version = "4.1.1" description = "Backported and Experimental Type Hints for Python 3.6+" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" @@ -354,7 +354,7 @@ python-versions = ">=3.6" name = "zipp" version = "3.7.0" description = "Backport of pathlib-compatible object wrapper for zip files" -category = "dev" +category = "main" optional = false python-versions = ">=3.7" @@ -365,7 +365,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = ">=3.7,<3.11" -content-hash = "4c2045cb19d088e3205728efd723e8255ded94f211f21ca7f64aea90c05fe3ad" +content-hash = "4973cb3aa5b8437ba3e2cd3c9daee2a168e242b534b6aa9b039b79af7dd2e270" [metadata.files] atomicwrites = [ @@ -484,8 +484,8 @@ python-dateutil = [ {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, ] 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 = [ {file = "sgp4-2.20-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:b2169cd536355fc67e3870acea34c4fc22b2ccecab2c0bf45a01edfe646fe3d0"}, diff --git a/pyproject.toml b/pyproject.toml index 3a25a9a..5aa1eae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ termcolor = "^1.1" kosmorrolib = "^1.0" python-dateutil = "^2.8" Babel = "^2.9" +importlib-metadata = "^4.11" [tool.poetry.dev-dependencies] black = "^21.12b0"