Skip to content

Commit 1fe90d2

Browse files
authored
fix: enhance forward compatibility with Kosmorrolib (#189)
1 parent 9500efe commit 1fe90d2

File tree

4 files changed

+88
-93
lines changed

4 files changed

+88
-93
lines changed

.github/workflows/commitlint.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

_kosmorro/dumper.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ def stringify_ephemerides(self) -> str:
149149
data = []
150150

151151
for ephemeris in self.ephemerides:
152-
name = self.style(strings.from_object(ephemeris.object.identifier), "th")
152+
object_name = strings.from_object(ephemeris.object.identifier)
153+
if object_name is None:
154+
continue
155+
156+
name = self.style(object_name, "th")
153157

154158
if ephemeris.rise_time is not None:
155159
time_fmt = (
@@ -197,16 +201,10 @@ def stringify_ephemerides(self) -> str:
197201
)
198202

199203
def get_events(self, events: [Event]) -> str:
200-
def get_event_description(ev: Event):
201-
description = strings.from_event(ev)
202-
203-
if ev.details is not None:
204-
description += " ({:s})".format(ev.details)
205-
return description
206-
207204
data = []
208205

209206
for event in events:
207+
description = strings.from_event(event)
210208
time_fmt = (
211209
TIME_FORMAT
212210
if event.start_time.day == self.date.day
@@ -215,7 +213,7 @@ def get_event_description(ev: Event):
215213
data.append(
216214
[
217215
self.style(event.start_time.strftime(time_fmt), "th"),
218-
get_event_description(event),
216+
description,
219217
]
220218
)
221219

@@ -340,9 +338,13 @@ def add_strings(
340338
document = document.replace("+++EVENTS+++", self._make_events())
341339

342340
for aster in ASTERS:
341+
object_name = strings.from_object(aster.identifier)
342+
if object_name is None:
343+
continue
344+
343345
document = document.replace(
344346
"+++ASTER_%s+++" % aster.skyfield_name.upper().split(" ")[0],
345-
strings.from_object(aster.identifier),
347+
object_name,
346348
)
347349

348350
return document
@@ -384,15 +386,17 @@ def _make_ephemerides(self) -> str:
384386
aster_set = "-"
385387

386388
if not self.show_graph:
387-
latex.append(
388-
r"\object{%s}{%s}{%s}{%s}"
389-
% (
390-
strings.from_object(ephemeris.object.identifier),
391-
aster_rise,
392-
aster_culmination,
393-
aster_set,
389+
object_name = strings.from_object(ephemeris.object.identifier)
390+
if object_name is not None:
391+
latex.append(
392+
r"\object{%s}{%s}{%s}{%s}"
393+
% (
394+
object_name,
395+
aster_rise,
396+
aster_culmination,
397+
aster_set,
398+
)
394399
)
395-
)
396400
else:
397401
if ephemeris.rise_time is not None:
398402
raise_hour = ephemeris.rise_time.hour
@@ -438,9 +442,13 @@ def _make_events(self) -> str:
438442
latex = []
439443

440444
for event in self.events:
445+
event_name = strings.from_event(event)
446+
if event_name is None:
447+
continue
448+
441449
latex.append(
442450
r"\event{%s}{%s}"
443-
% (event.start_time.strftime(TIME_FORMAT), strings.from_event(event))
451+
% (event.start_time.strftime(TIME_FORMAT), event_name)
444452
)
445453

446454
return "".join(latex)

_kosmorro/i18n/strings.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,29 @@
55
from kosmorrolib import EventType, MoonPhaseType, ObjectIdentifier, Event
66

77

8-
def from_event(event: Event) -> str:
9-
return {
10-
EventType.OPPOSITION: _("%s is in opposition"),
11-
EventType.CONJUNCTION: _("%s and %s are in conjunction"),
12-
EventType.OCCULTATION: _("%s occults %s"),
13-
EventType.MAXIMAL_ELONGATION: _("Elongation of %s is maximal"),
14-
EventType.MOON_PERIGEE: _("%s is at its perigee"),
15-
EventType.MOON_APOGEE: _("%s is at its apogee"),
16-
}.get(event.event_type) % tuple([from_object(o.identifier) for o in event.objects])
8+
def from_event(event: Event, with_description: bool = True) -> str:
9+
string, details = {
10+
EventType.OPPOSITION: (_("%s is in opposition"), None),
11+
EventType.CONJUNCTION: (_("%s and %s are in conjunction"), None),
12+
EventType.OCCULTATION: (_("%s occults %s"), None),
13+
EventType.MAXIMAL_ELONGATION: (_("Elongation of %s is maximal"), ('{:.3n}°'.format(event.details['deg']) if type(event.details) is dict else event.details)),
14+
EventType.MOON_PERIGEE: (_("%s is at its perigee"), None),
15+
EventType.MOON_APOGEE: (_("%s is at its apogee"), None),
16+
}.get(event.event_type)
17+
18+
if string is None:
19+
return None
20+
21+
string = string % tuple([from_object(o.identifier) for o in event.objects])
22+
23+
if details is not None and with_description:
24+
return '%s (%s)' % (string, details)
25+
26+
return string
1727

1828

1929
def from_moon_phase(moon_phase: MoonPhaseType) -> str:
20-
return {
30+
string = {
2131
MoonPhaseType.NEW_MOON: _("New Moon"),
2232
MoonPhaseType.WAXING_CRESCENT: _("Waxing Crescent"),
2333
MoonPhaseType.FIRST_QUARTER: _("First Quarter"),
@@ -26,7 +36,12 @@ def from_moon_phase(moon_phase: MoonPhaseType) -> str:
2636
MoonPhaseType.WANING_GIBBOUS: _("Waning Gibbous"),
2737
MoonPhaseType.LAST_QUARTER: _("Last Quarter"),
2838
MoonPhaseType.WANING_CRESCENT: _("Waning Crescent"),
29-
}.get(moon_phase, _("Unknown phase"))
39+
}.get(moon_phase)
40+
41+
if string is None:
42+
raise RuntimeError("Unknown moon phase: %s." % moon_phase)
43+
44+
return string
3045

3146

3247
def from_object(identifier: ObjectIdentifier) -> str:
@@ -41,4 +56,4 @@ def from_object(identifier: ObjectIdentifier) -> str:
4156
ObjectIdentifier.URANUS: _("Uranus"),
4257
ObjectIdentifier.NEPTUNE: _("Neptune"),
4358
ObjectIdentifier.PLUTO: _("Pluto"),
44-
}.get(identifier, _("Unknown object"))
59+
}.get(identifier)

_kosmorro/locales/messages.pot

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: kosmorro 0.10.0\n"
1010
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
11-
"POT-Creation-Date: 2021-06-06 11:58+0200\n"
11+
"POT-Creation-Date: 2021-06-20 15:59+0200\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -39,72 +39,72 @@ msgstr ""
3939
msgid "Note: All the hours are given in the UTC{offset} timezone."
4040
msgstr ""
4141

42-
#: _kosmorro/dumper.py:189 _kosmorro/dumper.py:325
42+
#: _kosmorro/dumper.py:193 _kosmorro/dumper.py:323
4343
msgid "Object"
4444
msgstr ""
4545

46-
#: _kosmorro/dumper.py:190 _kosmorro/dumper.py:326
46+
#: _kosmorro/dumper.py:194 _kosmorro/dumper.py:324
4747
msgid "Rise time"
4848
msgstr ""
4949

50-
#: _kosmorro/dumper.py:191 _kosmorro/dumper.py:328
50+
#: _kosmorro/dumper.py:195 _kosmorro/dumper.py:326
5151
msgid "Culmination time"
5252
msgstr ""
5353

54-
#: _kosmorro/dumper.py:192 _kosmorro/dumper.py:330
54+
#: _kosmorro/dumper.py:196 _kosmorro/dumper.py:328
5555
msgid "Set time"
5656
msgstr ""
5757

58-
#: _kosmorro/dumper.py:226
58+
#: _kosmorro/dumper.py:224
5959
msgid "Moon phase is unavailable for this date."
6060
msgstr ""
6161

62-
#: _kosmorro/dumper.py:230 _kosmorro/dumper.py:334
62+
#: _kosmorro/dumper.py:228 _kosmorro/dumper.py:332
6363
msgid "Moon phase:"
6464
msgstr ""
6565

66-
#: _kosmorro/dumper.py:234
66+
#: _kosmorro/dumper.py:232
6767
msgid "{next_moon_phase} on {next_moon_phase_date} at {next_moon_phase_time}"
6868
msgstr ""
6969

70-
#: _kosmorro/dumper.py:298
70+
#: _kosmorro/dumper.py:296
7171
msgid "Overview of your sky"
7272
msgstr ""
7373

74-
#: _kosmorro/dumper.py:306
74+
#: _kosmorro/dumper.py:304
7575
msgid ""
7676
"This document summarizes the ephemerides and the events of {date}. It "
7777
"aims to help you to prepare your observation session. All the hours are "
7878
"given in {timezone}."
7979
msgstr ""
8080

81-
#: _kosmorro/dumper.py:316
81+
#: _kosmorro/dumper.py:314
8282
msgid ""
8383
"Don't forget to check the weather forecast before you go out with your "
8484
"equipment."
8585
msgstr ""
8686

87-
#: _kosmorro/dumper.py:323
87+
#: _kosmorro/dumper.py:321
8888
msgid "Ephemerides of the day"
8989
msgstr ""
9090

91-
#: _kosmorro/dumper.py:332
91+
#: _kosmorro/dumper.py:330
9292
msgid "hours"
9393
msgstr ""
9494

95-
#: _kosmorro/dumper.py:339
95+
#: _kosmorro/dumper.py:337
9696
msgid "Expected events"
9797
msgstr ""
9898

99-
#: _kosmorro/dumper.py:484
99+
#: _kosmorro/dumper.py:492
100100
msgid ""
101101
"Building PDF was not possible, because some dependencies are not "
102102
"installed.\n"
103103
"Please look at the documentation at https://kosmorro.space/cli/generate-"
104104
"pdf/ for more information."
105105
msgstr ""
106106

107-
#: _kosmorro/dumper.py:537
107+
#: _kosmorro/dumper.py:545
108108
#, python-format
109109
msgid ""
110110
"An error occurred during the compilation of the PDF.\n"
@@ -253,86 +253,78 @@ msgstr ""
253253
msgid "%s is at its apogee"
254254
msgstr ""
255255

256-
#: _kosmorro/i18n/strings.py:21
256+
#: _kosmorro/i18n/strings.py:31
257257
msgid "New Moon"
258258
msgstr ""
259259

260-
#: _kosmorro/i18n/strings.py:22
260+
#: _kosmorro/i18n/strings.py:32
261261
msgid "Waxing Crescent"
262262
msgstr ""
263263

264-
#: _kosmorro/i18n/strings.py:23
264+
#: _kosmorro/i18n/strings.py:33
265265
msgid "First Quarter"
266266
msgstr ""
267267

268-
#: _kosmorro/i18n/strings.py:24
268+
#: _kosmorro/i18n/strings.py:34
269269
msgid "Waxing Gibbous"
270270
msgstr ""
271271

272-
#: _kosmorro/i18n/strings.py:25
272+
#: _kosmorro/i18n/strings.py:35
273273
msgid "Full Moon"
274274
msgstr ""
275275

276-
#: _kosmorro/i18n/strings.py:26
276+
#: _kosmorro/i18n/strings.py:36
277277
msgid "Waning Gibbous"
278278
msgstr ""
279279

280-
#: _kosmorro/i18n/strings.py:27
280+
#: _kosmorro/i18n/strings.py:37
281281
msgid "Last Quarter"
282282
msgstr ""
283283

284-
#: _kosmorro/i18n/strings.py:28
284+
#: _kosmorro/i18n/strings.py:38
285285
msgid "Waning Crescent"
286286
msgstr ""
287287

288-
#: _kosmorro/i18n/strings.py:29
289-
msgid "Unknown phase"
290-
msgstr ""
291-
292-
#: _kosmorro/i18n/strings.py:34
288+
#: _kosmorro/i18n/strings.py:49
293289
msgid "Sun"
294290
msgstr ""
295291

296-
#: _kosmorro/i18n/strings.py:35
292+
#: _kosmorro/i18n/strings.py:50
297293
msgid "Moon"
298294
msgstr ""
299295

300-
#: _kosmorro/i18n/strings.py:36
296+
#: _kosmorro/i18n/strings.py:51
301297
msgid "Mercury"
302298
msgstr ""
303299

304-
#: _kosmorro/i18n/strings.py:37
300+
#: _kosmorro/i18n/strings.py:52
305301
msgid "Venus"
306302
msgstr ""
307303

308-
#: _kosmorro/i18n/strings.py:38
304+
#: _kosmorro/i18n/strings.py:53
309305
msgid "Mars"
310306
msgstr ""
311307

312-
#: _kosmorro/i18n/strings.py:39
308+
#: _kosmorro/i18n/strings.py:54
313309
msgid "Jupiter"
314310
msgstr ""
315311

316-
#: _kosmorro/i18n/strings.py:40
312+
#: _kosmorro/i18n/strings.py:55
317313
msgid "Saturn"
318314
msgstr ""
319315

320-
#: _kosmorro/i18n/strings.py:41
316+
#: _kosmorro/i18n/strings.py:56
321317
msgid "Uranus"
322318
msgstr ""
323319

324-
#: _kosmorro/i18n/strings.py:42
320+
#: _kosmorro/i18n/strings.py:57
325321
msgid "Neptune"
326322
msgstr ""
327323

328-
#: _kosmorro/i18n/strings.py:43
324+
#: _kosmorro/i18n/strings.py:58
329325
msgid "Pluto"
330326
msgstr ""
331327

332-
#: _kosmorro/i18n/strings.py:44
333-
msgid "Unknown object"
334-
msgstr ""
335-
336328
#: _kosmorro/i18n/utils.py:27
337329
msgid "{day_of_week} {month} {day_number}, {year}"
338330
msgstr ""

0 commit comments

Comments
 (0)