From ada1e96cf8e12860197afc9a2c86519fbc18db53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=A9=20Cassiop=C3=A9e=20Gauthier?= Date: Fri, 1 Nov 2024 17:30:04 -0400 Subject: [PATCH] Initial commit --- .gitignore | 2 + LICENSE.txt | 9 +++++ README.md | 23 +++++++++++ pyproject.toml | 62 ++++++++++++++++++++++++++++++ src/phase_of_the_moon/__about__.py | 7 ++++ src/phase_of_the_moon/__init__.py | 9 +++++ src/phase_of_the_moon/main.py | 30 +++++++++++++++ tests/__init__.py | 6 +++ tests/test_phase_of_the_moon.py | 23 +++++++++++ 9 files changed, 171 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 src/phase_of_the_moon/__about__.py create mode 100644 src/phase_of_the_moon/__init__.py create mode 100644 src/phase_of_the_moon/main.py create mode 100644 tests/__init__.py create mode 100644 tests/test_phase_of_the_moon.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac8d7b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +dist diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..35dbc77 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2024-present Zoé Cassiopée Gauthier + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1c4fb64 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Phase Of The Moon + +[![PyPI - Version](https://img.shields.io/pypi/v/phase-of-the-moon.svg)](https://pypi.org/project/phase-of-the-moon) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/phase-of-the-moon.svg)](https://pypi.org/project/phase-of-the-moon) + +Displays a message either during a full moon or during a new moon. The calculation is based on the Nethack `phase_of_the_moon` function. + +----- + +## Table of Contents + +- [Installation](#installation) +- [License](#license) + +## Installation + +```console +pip install phase-of-the-moon +``` + +## License + +`phase-of-the-moon` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..718f66a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,62 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "phase-of-the-moon" +dynamic = ["version"] +description = 'Displays a message depending on the current phase of the moon.' +readme = "README.md" +requires-python = ">=3.8" +license = "MIT" +keywords = [] +authors = [ + { name = "Zoé Cassiopée Gauthier", email = "zoe.gauthier@blorp.dev" }, +] +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +dependencies = [] + +[project.urls] +Source = "https://git.blorp.dev/zo/phase-of-the-moon" + +[project.scripts] +nh-phase-of-the-moon = "phase_of_the_moon:main" + +[tool.hatch.version] +path = "src/phase_of_the_moon/__about__.py" + +[tool.hatch.envs.types] +extra-dependencies = [ + "mypy>=1.0.0", +] +[tool.hatch.envs.types.scripts] +check = "mypy --install-types --non-interactive {args:src/phase_of_the_moon tests}" + +[tool.coverage.run] +source_pkgs = ["phase_of_the_moon", "tests"] +branch = true +parallel = true +omit = [ + "src/phase_of_the_moon/__about__.py", +] + +[tool.coverage.paths] +phase_of_the_moon = ["src/phase_of_the_moon", "*/phase-of-the-moon/src/phase_of_the_moon"] +tests = ["tests", "*/phase-of-the-moon/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] diff --git a/src/phase_of_the_moon/__about__.py b/src/phase_of_the_moon/__about__.py new file mode 100644 index 0000000..7284c6b --- /dev/null +++ b/src/phase_of_the_moon/__about__.py @@ -0,0 +1,7 @@ +# Copyright 2024 Zoé Cassiopée Gauthier. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. + +__version__ = "0.0.1" diff --git a/src/phase_of_the_moon/__init__.py b/src/phase_of_the_moon/__init__.py new file mode 100644 index 0000000..d3173e5 --- /dev/null +++ b/src/phase_of_the_moon/__init__.py @@ -0,0 +1,9 @@ +# Copyright 2024 Zoé Cassiopée Gauthier. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. + +from phase_of_the_moon.main import main + +__all__ = ["main"] diff --git a/src/phase_of_the_moon/main.py b/src/phase_of_the_moon/main.py new file mode 100644 index 0000000..42f2bfa --- /dev/null +++ b/src/phase_of_the_moon/main.py @@ -0,0 +1,30 @@ +# Copyright 2024 Zoé Cassiopée Gauthier. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. + +import datetime as dt + +NEW_MOON = 0 +FULL_MOON = 4 + + +def phase_of_the_moon(local_time: dt.datetime) -> int: + tt = local_time.timetuple() + day_of_year = tt.tm_yday + golden_number = (tt.tm_year % 19) + 1 + epact = (11 * golden_number + 18) % 30 + if (epact == 25 and golden_number > 11) or epact == 24: + epact += 1 + return (((((day_of_year + epact) * 6) + 11) % 177) // 22) & 7 + + +def main(): + today = dt.datetime.now() + moon_phase = phase_of_the_moon(today) + + if moon_phase == NEW_MOON: + print("Be careful! New moon tonight.") + elif moon_phase == FULL_MOON: + print("You are lucky! Full moon tonight.") diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..84ec282 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,6 @@ +# Copyright 2024 Zoé Cassiopée Gauthier. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. + diff --git a/tests/test_phase_of_the_moon.py b/tests/test_phase_of_the_moon.py new file mode 100644 index 0000000..ca92f45 --- /dev/null +++ b/tests/test_phase_of_the_moon.py @@ -0,0 +1,23 @@ +# Copyright 2024 Zoé Cassiopée Gauthier. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. + +import datetime as dt + +from phase_of_the_moon.main import phase_of_the_moon, NEW_MOON, FULL_MOON + +def test_new_moon(): + local_time = dt.datetime(1996, 9, 13) + assert phase_of_the_moon(local_time) == NEW_MOON + +def test_full_moon(): + local_time = dt.datetime(1998, 3, 13) + assert phase_of_the_moon(local_time) == FULL_MOON + +def test_any_other_moon_phase(): + local_time = dt.datetime(2000, 1, 1) + moon_phase = phase_of_the_moon(local_time) + assert moon_phase != FULL_MOON + assert moon_phase != NEW_MOON