From e187707412255bc4873d219ffe594d9f00655978 Mon Sep 17 00:00:00 2001 From: Don Cross Date: Sun, 5 Jun 2022 15:03:02 -0400 Subject: [PATCH] Patch version numbers using a Python program. It turns out that "sed" does not work on Mac OS, and I wasn't even trying to patch the version numbers on Windows. I decided to write a Python program for this task, so it will work identically on all 3 operating systems. --- generate/makedoc | 9 +- generate/makedoc.bat | 2 + generate/patch_version_numbers.py | 36 ++++++++ source/csharp/astronomy.csproj | 134 +++++++++++++++--------------- source/python/setup.py | 2 +- 5 files changed, 107 insertions(+), 76 deletions(-) create mode 100755 generate/patch_version_numbers.py diff --git a/generate/makedoc b/generate/makedoc index dd8ec80e..ea7274c8 100755 --- a/generate/makedoc +++ b/generate/makedoc @@ -5,14 +5,7 @@ Fail() exit 1 } -VERSION=$(cat version.txt) || Fail "Could not set VERSION environment variable." -[[ -z "${VERSION}" ]] && Fail "VERSION is blank." -echo "Patching version numbers to: ${VERSION}" -sed -i 's/2b-v[^\-]*-blue/2b-v'${VERSION}'-blue/' ../README.md || Fail "Cannot patch version in README.md" -sed -i 's/"version": "[^"]*"/"version": "'${VERSION}'"/' ../source/js/package.json || Fail "Cannot patch version in package.json" -sed -i 's+[^<]*+'${VERSION}'+' ../source/csharp/astronomy.csproj || Fail "Cannot patch version in astronomy.csproj" -sed -i 's/version="[^"]*"/version="'${VERSION}'"/' ../source/python/setup.py || Fail "Cannot patch version in setup.py" -sed -i 's/version = "[^"]*"/version = "'${VERSION}'"/' ../source/kotlin/build.gradle.kts || Fail "Cannot patch version in build.gradle.kts" +./patch_version_numbers.py || Fail "Error updating version numbers." echo "Trimming trailing whitespace in source code." for file in template/astronomy.{c,cs,ts,py} ../source/c/astronomy.h; do diff --git a/generate/makedoc.bat b/generate/makedoc.bat index 2cce96fa..7ea0564b 100644 --- a/generate/makedoc.bat +++ b/generate/makedoc.bat @@ -11,6 +11,8 @@ if not exist "!GENEXE!" ( exit /b 1 ) +patch_version_numbers.py || exit /b 1 + echo.Trimming trailing whitespace in source code. for %%f in (template\astronomy.c ..\source\c\astronomy.h) do ( node trimspace.js %%f diff --git a/generate/patch_version_numbers.py b/generate/patch_version_numbers.py new file mode 100755 index 00000000..6bd649ad --- /dev/null +++ b/generate/patch_version_numbers.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +import sys + +def Patch(version, filename, prefix, suffix): + with open(filename, 'rt') as infile: + text = infile.read() + pindex = text.find(prefix) + if pindex < 0: + print('patch_version_numbers.py: ERROR: Cannot find prefix "{}" in file: {}'.format(prefix, filename)) + return 1 + pindex += len(prefix) + sindex = text.find(suffix, pindex) + if sindex < 0: + print('patch_version_numbers.py: ERROR: Cannot find suffix "{}" in file: {}'.format(suffix, filename)) + return 1 + updated = text[:pindex] + version + text[sindex:] + if text != updated: + print('patch_version_numbers.py: UPDATING: {}'.format(filename)) + with open(filename, 'wt') as outfile: + outfile.write(updated) + return 0 + +def PatchVersionNumbers(): + with open('version.txt', 'rt') as infile: + version = infile.read().strip() + print('patch_version_numbers.py: Version = {}'.format(version)) + return ( + Patch(version, '../README.md', '2b-v', '-blue') | + Patch(version, '../source/js/package.json', '"version": "', '"') | + Patch(version, '../source/csharp/astronomy.csproj', '', '') | + Patch(version, '../source/python/setup.py', "version='", "'") | + Patch(version, '../source/kotlin/build.gradle.kts', 'version = "', '"') + ) + +if __name__ == '__main__': + sys.exit(PatchVersionNumbers()) diff --git a/source/csharp/astronomy.csproj b/source/csharp/astronomy.csproj index be7059e7..d6ff0e78 100644 --- a/source/csharp/astronomy.csproj +++ b/source/csharp/astronomy.csproj @@ -1,67 +1,67 @@ - - - netstandard2.0 - true - true - CosineKitty.AstronomyEngine - 2.1.2 - https://github.com/cosinekitty/astronomy - Don Cross - Astronomy Engine - Copyright (c) 2019-2022 Don Cross <cosinekitty@gmail.com> - MIT - -Astronomy Engine calculates Sun, Moon, and planet positions. -It predicts lunar phases, eclipses, transits, oppositions, conjunctions, equinoxes, solstices, -rise/set times, and other events. It provides vector and angular coordinate transforms among -equatorial, ecliptic, horizontal, and galactic orientations. - -- Provides calculations for the Sun, Moon, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, and Pluto. - -- Calculates all supported objects for any calendar date and time for millennia before or after the present. - -- Provides heliocentric and geocentric Cartesian vectors of all the above bodies. - -- Determines apparent horizon-based positions for an observer anywhere on the Earth, given that observer's latitude, longitude, and elevation in meters. Optionally corrects for atmospheric refraction. - -- Calculates rise, set, and culmination times of Sun, Moon, and planets. - -- Finds civil, nautical, and astronomical twilight times (dusk and dawn). - -- Finds date and time of Moon phases: new, first quarter, full, third quarter (or anywhere in between as expressed in degrees of ecliptic longitude). - -- Predicts lunar and solar eclipses. - -- Predicts transits of Mercury and Venus. - -- Predicts lunar apogee and perigee dates, times, and distances. - -- Predicts date and time of equinoxes and solstices for a given calendar year. - -- Determines apparent visual magnitudes of all the supported celestial bodies. - -- Predicts dates of planetary conjunctions, oppositions, and apsides. - -- Predicts dates of Venus' peak visual magnitude. - -- Predicts dates of maximum elongation for Mercury and Venus. - -- Calculates the positions of Jupiter's four largest moons: Io, Europa, Ganymede, and Callisto. - -- Allows custom simulation of the movements of user-defined small bodies, such as asteroids and comets, through the Solar System. - -- Converts angular and vector coordinates among the following orientations: - Equatorial J2000, - Equatorial equator-of-date, - Ecliptic J2000, - Topocentric Horizontal, - Galactic (IAU 1958). - -- Determines which constellation contains a given point in the sky. - -- Calculates libration of the Moon. - -- Calculates axis orientation and rotation angles for the Sun, Moon, and planets. - - - + + + netstandard2.0 + true + true + CosineKitty.AstronomyEngine + 2.1.2 + https://github.com/cosinekitty/astronomy + Don Cross + Astronomy Engine + Copyright (c) 2019-2022 Don Cross <cosinekitty@gmail.com> + MIT + +Astronomy Engine calculates Sun, Moon, and planet positions. +It predicts lunar phases, eclipses, transits, oppositions, conjunctions, equinoxes, solstices, +rise/set times, and other events. It provides vector and angular coordinate transforms among +equatorial, ecliptic, horizontal, and galactic orientations. + +- Provides calculations for the Sun, Moon, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, and Pluto. + +- Calculates all supported objects for any calendar date and time for millennia before or after the present. + +- Provides heliocentric and geocentric Cartesian vectors of all the above bodies. + +- Determines apparent horizon-based positions for an observer anywhere on the Earth, given that observer's latitude, longitude, and elevation in meters. Optionally corrects for atmospheric refraction. + +- Calculates rise, set, and culmination times of Sun, Moon, and planets. + +- Finds civil, nautical, and astronomical twilight times (dusk and dawn). + +- Finds date and time of Moon phases: new, first quarter, full, third quarter (or anywhere in between as expressed in degrees of ecliptic longitude). + +- Predicts lunar and solar eclipses. + +- Predicts transits of Mercury and Venus. + +- Predicts lunar apogee and perigee dates, times, and distances. + +- Predicts date and time of equinoxes and solstices for a given calendar year. + +- Determines apparent visual magnitudes of all the supported celestial bodies. + +- Predicts dates of planetary conjunctions, oppositions, and apsides. + +- Predicts dates of Venus' peak visual magnitude. + +- Predicts dates of maximum elongation for Mercury and Venus. + +- Calculates the positions of Jupiter's four largest moons: Io, Europa, Ganymede, and Callisto. + +- Allows custom simulation of the movements of user-defined small bodies, such as asteroids and comets, through the Solar System. + +- Converts angular and vector coordinates among the following orientations: + Equatorial J2000, + Equatorial equator-of-date, + Ecliptic J2000, + Topocentric Horizontal, + Galactic (IAU 1958). + +- Determines which constellation contains a given point in the sky. + +- Calculates libration of the Moon. + +- Calculates axis orientation and rotation angles for the Sun, Moon, and planets. + + + diff --git a/source/python/setup.py b/source/python/setup.py index 707f85ae..baa09abb 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.1.2", + version='2.1.2', description='Astronomy calculation for Sun, Moon, and planets.', long_description=open('README.md').read(), long_description_content_type='text/markdown',