From 74044b39d359f16c50dca33d376fb8a308bc3fe0 Mon Sep 17 00:00:00 2001 From: Don Cross Date: Sun, 20 Mar 2022 16:47:29 -0400 Subject: [PATCH] More Python/pip package cleanup : version 2.0.17. Generate astronomy.py directly in the package directory. I realized it doesn't make sense to generate it in the parent directory and then copy it; just generate it where it will end up anyway. Updated documentation so people know they can just do pip install astronomy-engine to install Astronomy Engine in their Python project. Removed the GitHub Actions status badge because it is redundant with the checkmark/X indicator. Now that private symbols are no longer exported, I had to fix a couple of places where the unit tests still accessed them. --- README.md | 1 - generate/generate.c | 2 +- generate/makedoc | 6 +++--- generate/makedoc.bat | 6 +++--- generate/pydown/py_prefix.md | 18 ++++++++++++++++-- generate/test.py | 17 ++++++++++++++--- generate/unit_test_python | 2 +- source/python/README.md | 18 ++++++++++++++++-- source/python/astronomy/.gitignore | 1 - source/python/{ => astronomy}/astronomy.py | 0 source/python/publish | 1 - source/python/setup.py | 2 +- 12 files changed, 55 insertions(+), 19 deletions(-) delete mode 100644 source/python/astronomy/.gitignore rename source/python/{ => astronomy}/astronomy.py (100%) diff --git a/README.md b/README.md index d2c876d1..5d66d06a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ -[![build status](https://github.com/cosinekitty/astronomy/actions/workflows/astronomy-engine-tests.yml/badge.svg)](https://github.com/cosinekitty/astronomy/actions) [![npm package](https://img.shields.io/npm/v/astronomy-engine.svg)](https://www.npmjs.com/package/astronomy-engine) [![PyPI version](https://badge.fury.io/py/astronomy-engine.svg)](https://badge.fury.io/py/astronomy-engine) diff --git a/generate/generate.c b/generate/generate.c index 465e053e..78d7d1d3 100644 --- a/generate/generate.c +++ b/generate/generate.c @@ -851,7 +851,7 @@ static int GenerateSource(void) CHECK(GenerateCode(CODEGEN_LANGUAGE_C, "../source/c/astronomy.c", "template/astronomy.c", "output")); CHECK(GenerateCode(CODEGEN_LANGUAGE_CSHARP, "../source/csharp/astronomy.cs", "template/astronomy.cs", "output")); CHECK(GenerateCode(CODEGEN_LANGUAGE_JS, "../source/js/astronomy.ts", "template/astronomy.ts", "output")); - CHECK(GenerateCode(CODEGEN_LANGUAGE_PYTHON, "../source/python/astronomy.py", "template/astronomy.py", "output")); + CHECK(GenerateCode(CODEGEN_LANGUAGE_PYTHON, "../source/python/astronomy/astronomy.py", "template/astronomy.py", "output")); fail: return error; } diff --git a/generate/makedoc b/generate/makedoc index 7674c7c3..b4880bbc 100755 --- a/generate/makedoc +++ b/generate/makedoc @@ -14,7 +14,7 @@ echo "Generating target code." ./generate source || Fail "Problem generating target code." echo "Trimming trailing whitespace in target code." -for file in ../source/c/astronomy.c ../source/js/astronomy.ts ../source/python/astronomy.py ../source/csharp/astronomy.cs; do +for file in ../source/c/astronomy.c ../source/js/astronomy.ts ../source/python/astronomy/astronomy.py ../source/csharp/astronomy.cs; do node trimspace.js ${file} || Fail "Cannot trim whitespace from target file: ${file}" done @@ -111,12 +111,12 @@ else fi echo "Generating Python documentation." -python3 pydown/pydown.py pydown/py_prefix.md ../source/python/astronomy.py ../source/python/README.md || Fail "Error generating Markdown from Python source." +python3 pydown/pydown.py pydown/py_prefix.md ../source/python/astronomy/astronomy.py ../source/python/README.md || Fail "Error generating Markdown from Python source." ./check_internal_links.py ../source/python/README.md || exit 1 echo "Making redundant copies of source in demo folders." cp -v ../source/js/astronomy.browser.js ../demo/browser/ || exit $? cp -v ../source/js/astronomy.js ../demo/nodejs/ || exit $? -cp -v ../source/python/astronomy.py ../demo/python/ || exit $? +cp -v ../source/python/astronomy/astronomy.py ../demo/python/ || exit $? exit 0 diff --git a/generate/makedoc.bat b/generate/makedoc.bat index b95b872c..2cce96fa 100644 --- a/generate/makedoc.bat +++ b/generate/makedoc.bat @@ -25,7 +25,7 @@ if errorlevel 1 ( ) echo.Trimming trailing whitespace in target code. -for %%f in (..\source\c\astronomy.c ..\source\js\astronomy.js ..\source\python\astronomy.py ..\source\csharp\astronomy.cs) do ( +for %%f in (..\source\c\astronomy.c ..\source\js\astronomy.js ..\source\python\astronomy\astronomy.py ..\source\csharp\astronomy.cs) do ( node trimspace.js %%f if errorlevel 1 (exit /b 1) ) @@ -194,7 +194,7 @@ if exist disable_generate_c_docs ( ) echo.Generating Python documentation. -pydown\pydown.py pydown\py_prefix.md ..\source\python\astronomy.py ..\source\python\README.md +pydown\pydown.py pydown\py_prefix.md ..\source\python\astronomy\astronomy.py ..\source\python\README.md if errorlevel 1 (exit /b 1) echo.Making redundant copies of source in demo folders. @@ -205,7 +205,7 @@ if errorlevel 1 (exit /b 1) copy ..\source\js\astronomy.js ..\demo\nodejs\ if errorlevel 1 (exit /b 1) -copy ..\source\python\astronomy.py ..\demo\python\ +copy ..\source\python\astronomy\astronomy.py ..\demo\python\ if errorlevel 1 (exit /b 1) exit /b 0 diff --git a/generate/pydown/py_prefix.md b/generate/pydown/py_prefix.md index 8175d97f..afbcec0c 100644 --- a/generate/pydown/py_prefix.md +++ b/generate/pydown/py_prefix.md @@ -7,8 +7,22 @@ See the [home page](https://github.com/cosinekitty/astronomy) for more info. --- ## Quick Start -To include Astronomy Engine in your own Python program, all you need is -the file `astronomy.py` from this directory. +To include Astronomy Engine in your own Python program, +you can use the [astronomy-engine](https://pypi.org/project/astronomy-engine/) package: + +``` +pip install astronomy-engine +``` + +Alternatively, you can copy the file [astronomy/astronomy.py](astronomy/astronomy.py) +into your project directory. + +With either approach, add the following line toward the top of your program: + +```python +import astronomy +``` + To get started quickly, here are some [examples](../../demo/python/). diff --git a/generate/test.py b/generate/test.py index b4f2ac21..031a44b6 100755 --- a/generate/test.py +++ b/generate/test.py @@ -1143,12 +1143,24 @@ def Refraction(): #----------------------------------------------------------------------------------------------------------- +PlanetOrbitalPeriod = { + astronomy.Body.Mercury: 87.969, + astronomy.Body.Venus: 224.701, + astronomy.Body.Earth: 365.256, + astronomy.Body.Mars: 686.980, + astronomy.Body.Jupiter: 4332.589, + astronomy.Body.Saturn: 10759.22, + astronomy.Body.Uranus: 30685.4, + astronomy.Body.Neptune: 60189.0, + astronomy.Body.Pluto: 90560.0 +} + def PlanetApsis(): start_time = astronomy.Time.Make(1700, 1, 1, 0, 0, 0) body = astronomy.Body.Mercury while body.value <= astronomy.Body.Pluto.value: count = 1 - period = astronomy._PlanetOrbitalPeriod[body.value] + period = PlanetOrbitalPeriod[body] filename = os.path.join('apsides', 'apsis_{}.txt'.format(body.value)) min_interval = -1.0 max_diff_days = 0.0 @@ -1254,7 +1266,6 @@ def LunarEclipseIssue78(): #----------------------------------------------------------------------------------------------------------- def LunarEclipse(): - astronomy._CalcMoonCount = 0 filename = 'eclipse/lunar_eclipse.txt' with open(filename, 'rt') as infile: eclipse = astronomy.SearchLunarEclipse(astronomy.Time.Make(1701, 1, 1, 0, 0, 0)) @@ -1343,7 +1354,7 @@ def LunarEclipse(): # calculate for next iteration eclipse = astronomy.NextLunarEclipse(eclipse.peak) - print("PY LunarEclipse: PASS (verified {}, skipped {}, max_diff_minutes = {}, avg_diff_minutes = {}, moon calcs = {})".format(lnum, skip_count, max_diff_minutes, (sum_diff_minutes / diff_count), astronomy._CalcMoonCount)) + print("PY LunarEclipse: PASS (verified {}, skipped {}, max_diff_minutes = {}, avg_diff_minutes = {})".format(lnum, skip_count, max_diff_minutes, (sum_diff_minutes / diff_count))) return 0 #----------------------------------------------------------------------------------------------------------- diff --git a/generate/unit_test_python b/generate/unit_test_python index 5b47bb87..7017578f 100755 --- a/generate/unit_test_python +++ b/generate/unit_test_python @@ -8,7 +8,7 @@ Fail() [[ "$1" == "" || "$1" == "-v" ]] || Fail "Invalid command line options." python3 --version || Fail "Cannot print python version" -python3 -m pylint --init-hook="import sys; sys.setrecursionlimit(2000)" ../source/python/astronomy.py || Fail "pylint detected problems" +python3 -m pylint --init-hook="import sys; sys.setrecursionlimit(2000)" ../source/python/astronomy/astronomy.py || Fail "pylint detected problems" python3 test.py $1 all || Fail "Failed Python unit tests." for file in temp/py_longitude_*.txt; do ./generate $1 check ${file} || Fail "Failed verification of file ${file}" diff --git a/source/python/README.md b/source/python/README.md index 0c9bd683..256f8008 100644 --- a/source/python/README.md +++ b/source/python/README.md @@ -7,8 +7,22 @@ See the [home page](https://github.com/cosinekitty/astronomy) for more info. --- ## Quick Start -To include Astronomy Engine in your own Python program, all you need is -the file `astronomy.py` from this directory. +To include Astronomy Engine in your own Python program, +you can use the [astronomy-engine](https://pypi.org/project/astronomy-engine/) package: + +``` +pip install astronomy-engine +``` + +Alternatively, you can copy the file [astronomy/astronomy.py](astronomy/astronomy.py) +into your project directory. + +With either approach, add the following line toward the top of your program: + +```python +import astronomy +``` + To get started quickly, here are some [examples](../../demo/python/). diff --git a/source/python/astronomy/.gitignore b/source/python/astronomy/.gitignore deleted file mode 100644 index 2f4b48fc..00000000 --- a/source/python/astronomy/.gitignore +++ /dev/null @@ -1 +0,0 @@ -astronomy.py diff --git a/source/python/astronomy.py b/source/python/astronomy/astronomy.py similarity index 100% rename from source/python/astronomy.py rename to source/python/astronomy/astronomy.py diff --git a/source/python/publish b/source/python/publish index 2a50ac94..08a79732 100755 --- a/source/python/publish +++ b/source/python/publish @@ -1,6 +1,5 @@ #!/bin/bash rm -f dist/* -cp -v astronomy.py astronomy/astronomy.py || exit $? python3 -m build || exit $? python3 -m twine upload --repository astronomy-engine dist/* || exit $? exit 0 diff --git a/source/python/setup.py b/source/python/setup.py index 83103236..8f7dd8ea 100644 --- a/source/python/setup.py +++ b/source/python/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='astronomy-engine', - version='2.0.16', + version='2.0.17', description='Astronomy calculation for Sun, Moon, and planets.', long_description=open('README.md').read(), long_description_content_type='text/markdown',