From aabcd29ad5da2369a2015e0d53b7b0ea919da3e6 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Tue, 2 Jul 2024 21:33:00 +0100 Subject: [PATCH 01/20] ci_tests.yaml: try installing libtool with homebrew --- .github/workflows/ci_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 320e5e3..daafaa4 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -33,7 +33,7 @@ jobs: if: runner.os == 'macOS' run: | brew unlink gcc && brew link gcc - brew install automake + brew install automake libtool ./install_tempo2.sh - name: Install tempo2 on linux if: runner.os == 'Linux' @@ -114,4 +114,4 @@ jobs: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - twine upload dist/* \ No newline at end of file + twine upload dist/* From e09d4ead0cd2ea61a7ac23b55e42f83b78df32a1 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Tue, 2 Jul 2024 21:37:25 +0100 Subject: [PATCH 02/20] ci_tests.yml: remove Python 3.7 tests but add 3.11 --- .github/workflows/ci_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index daafaa4..7fb9e3b 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.8', '3.9', '3.10', '3.11'] steps: - name: Checkout repository @@ -60,7 +60,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.7' + python-version: '3.10' - name: Install tempo2 on mac if: runner.os == 'macOS' run: | From c127a45464a37057752f72c8379af18e1c0d8a63 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Tue, 2 Jul 2024 21:58:46 +0100 Subject: [PATCH 03/20] tests: set long double type to np.double for ARM64 --- tests/test_fakepulsar.py | 11 ++++++++--- tests/test_pulsar.py | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/test_fakepulsar.py b/tests/test_fakepulsar.py index 74091a6..b7a2928 100644 --- a/tests/test_fakepulsar.py +++ b/tests/test_fakepulsar.py @@ -13,11 +13,16 @@ TMP_DIR = Path("test_fake_output") TMP_DIR.mkdir(exist_ok=True) +try: + NP_LONG_DOUBLE_TYPE = np.float128 +except AttributeError: + NP_LONG_DOUBLE_TYPE = np.double + class TestFakePulsar(unittest.TestCase): @classmethod def setUpClass(cls): - cls.obstimes = np.arange(53000, 54800, 10, dtype=np.float128) + cls.obstimes = np.arange(53000, 54800, 10, dtype=NP_LONG_DOUBLE_TYPE) cls.toaerr = 1e-3 cls.freq = 1440.0 cls.observatory = "ao" @@ -133,7 +138,7 @@ def test_astropy_array(self): self.assertEqual(len(self.obstimes), psr.nobs) self.assertTrue(np.all(self.obstimes == self.fakepsr.stoas)) self.assertTrue(np.all(psr.stoas == self.fakepsr.stoas)) - self.assertEqual(psr.stoas[0].dtype, np.float128) + self.assertEqual(psr.stoas[0].dtype, NP_LONG_DOUBLE_TYPE) def test_single_values(self): """ @@ -151,7 +156,7 @@ def test_single_values(self): self.assertEqual(psr.nobs, 1) self.assertEqual(len(psr.stoas), 1) self.assertTrue(np.all(self.fakepsr.stoas[0] == psr.stoas[0])) - self.assertEqual(psr.stoas[0].dtype, np.float128) + self.assertEqual(psr.stoas[0].dtype, NP_LONG_DOUBLE_TYPE) def test_toa_errs(self): """ diff --git a/tests/test_pulsar.py b/tests/test_pulsar.py index 63697bf..41ccd74 100644 --- a/tests/test_pulsar.py +++ b/tests/test_pulsar.py @@ -10,6 +10,11 @@ TMP_DIR = Path("test_output") TMP_DIR.mkdir(exist_ok=True) +try: + NP_LONG_DOUBLE_TYPE = np.float128 +except AttributeError: + NP_LONG_DOUBLE_TYPE = np.double + class TestDeterministicSignals(unittest.TestCase): @classmethod @@ -29,7 +34,7 @@ def test_attrs(self): self.assertTrue(np.all(self.psr.stoas > 50000) and np.all(self.psr.stoas < 59000)) self.assertTrue(np.all(self.psr.toaerrs > 0.01) and np.all(self.psr.toaerrs < 10)) self.assertTrue(np.all(self.psr.freqs > 700) and np.all(self.psr.freqs < 4000)) - self.assertEqual(self.psr.stoas[0].dtype, np.float128) + self.assertEqual(self.psr.stoas[0].dtype, NP_LONG_DOUBLE_TYPE) def test_toas(self): self.assertTrue(np.all(self.psr.toas() != self.psr.stoas)) From 76774186501f1d93efaa035556097deb2f62040b Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 3 Jul 2024 21:55:35 +0100 Subject: [PATCH 04/20] Various distribution updates: - move project information from setup.py to pyproject.toml - set Python 3.9 as minimum supported version (in line with new NumPy version support) - switch versioning to use setuptools_scm (version created from git tag) --- libstempo/.gitignore | 3 ++ libstempo/__init__.py | 7 ++- libstempo/libstempo.pyx | 26 ++--------- pyproject.toml | 95 ++++++++++++++++++++++++++++++++--------- requirements.txt | 6 --- requirements_dev.txt | 9 ---- setup.py | 69 +++++++++--------------------- 7 files changed, 107 insertions(+), 108 deletions(-) create mode 100644 libstempo/.gitignore delete mode 100644 requirements.txt delete mode 100644 requirements_dev.txt diff --git a/libstempo/.gitignore b/libstempo/.gitignore new file mode 100644 index 0000000..7c56ea5 --- /dev/null +++ b/libstempo/.gitignore @@ -0,0 +1,3 @@ +_version.py +*.so +*.cpp diff --git a/libstempo/__init__.py b/libstempo/__init__.py index 054bc7a..339ba23 100644 --- a/libstempo/__init__.py +++ b/libstempo/__init__.py @@ -1,5 +1,3 @@ -__version__ = "2.4.7" - import os from ._find_tempo2 import find_tempo2_runtime @@ -14,3 +12,8 @@ from libstempo.libstempo import * # noqa F401,F402,F403 + +try: + from ._version import version as __version__ +except ModuleNotFoundError: + __version__ = "" \ No newline at end of file diff --git a/libstempo/libstempo.pyx b/libstempo/libstempo.pyx index 4e8a951..8f6afa1 100644 --- a/libstempo/libstempo.pyx +++ b/libstempo/libstempo.pyx @@ -4,30 +4,12 @@ import os, sys, math, re, time from packaging import version import collections +from collections import OrderedDict -try: - from collections import OrderedDict -except ImportError: - # this is for Python 2.6 compatibility, we may be able to drop it - from ordereddict import OrderedDict - -# Python 2/3 compatibility - -if sys.version_info[0] < 3: - from itertools import izip as zip +# what is the default encoding here? +string = lambda s: s.decode() +string_dtype = 'U' - string = lambda s: s - string_dtype = 'S' -else: - # what is the default encoding here? - string = lambda s: s.decode() - string_dtype = 'U' - -# get zip-as-iterator behavior in Python 2 -try: - import itertools.izip as zip -except ImportError: - pass from libc cimport stdlib, stdio from libc.string cimport strncpy, memset diff --git a/pyproject.toml b/pyproject.toml index 37f283e..67aabe6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,82 @@ +[build-system] +requires = [ + "setuptools>=61", + "setuptools_scm[toml]>=6.2", + "wheel", # ephem package likes to have wheel installed + "cython", + "numpy>=2.0.0rc1", +] +build-backend = "setuptools.build_meta" + +[project] +name = "libstempo" +description = "A Python wrapper for tempo2" +authors = [{name = "Michele Vallisneri", email = "vallis@vallis.org"}] +urls = { Homepage = "https://github.com/vallis/libstempo" } +readme = "README.md" +license = { text = "MIT" } +classifiers=[ + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Operating System :: MacOS", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] + +dynamic = [ + "version", +] + +requires-python = ">=3.9, <4" +dependencies = [ + "numpy>=1.15.0", + "scipy>=1.2.0", + "matplotlib>=3.3.2", + "ephem>=3.7.7.1", +] + +[project.optional-dependencies] +astropy = [ + "astropy>=4.1", +] +dev = [ + "black~=22.3.0", + "flake8~=3.7.7", + "pre-commit~=1.15.2", + "wheel>=0.29.0", + "coverage>=4.5.3", + "pytest>=4.0.0", + "pytest-cov>=2.7.0", + "jupyter>=1.0.0", +] + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.packages.find] +include = [ + "libstempo*", +] + +[tool.setuptools_scm] +write_to = "libstempo/_version.py" + [tool.black] line-length = 120 -target_version = ['py38'] -include = '\.pyi?$' -exclude = ''' - +target_version = ['py39'] +include = "\\.pyi?$" +exclude = """ ( /( - \.eggs # exclude a few common directories in the - | \.git # root of the project - | \.hg - | \.mypy_cache - | \.tox + \\.eggs # exclude a few common directories in the + | \\.git # root of the project + | \\.hg + | \\.mypy_cache + | \\.tox | _build | buck-out | build @@ -19,13 +85,4 @@ exclude = ''' | .libstempo )/ ) -''' - -[build-system] -requires = [ - "setuptools>=40.8.0", - "wheel", # ephem package likes to have wheel installed - "Cython>=0.22", - "oldest-supported-numpy", -] -build-backend = "setuptools.build_meta" +""" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 0448f44..0000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -Cython>=0.22 -numpy>=1.15.0 -scipy>=1.2.0 -matplotlib>=3.3.2 -astropy>=4.2 -ephem>=3.7.7.1 diff --git a/requirements_dev.txt b/requirements_dev.txt deleted file mode 100644 index fcd9c20..0000000 --- a/requirements_dev.txt +++ /dev/null @@ -1,9 +0,0 @@ -pip>=21.0.1 -black~=22.3.0 -flake8~=3.7.7 -pre-commit~=1.15.2 -wheel>=0.29.0 -coverage>=4.5.3 -pytest>=4.0.0 -pytest-cov>=2.7.0 -jupyter>=1.0.0 diff --git a/setup.py b/setup.py index 8677944..1bf6120 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,6 @@ from pathlib import Path import numpy -from Cython.Build import cythonize from setuptools import Extension, setup @@ -66,54 +65,24 @@ def _get_tempo2_install_location(): else: linkArgs = [] -setup( - name="libstempo", - version="2.4.7", # remember to change it in __init__.py - description="A Python wrapper for tempo2", - author="Michele Vallisneri", - author_email="vallis@vallis.org", - url="https://github.com/vallis/libstempo", - license="MIT", - long_description=open("README.md").read(), - long_description_content_type="text/markdown", - classifiers=[ - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: MIT License", - "Operating System :: MacOS", - "Operating System :: POSIX :: Linux", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - ], - packages=["libstempo"], - package_dir={"libstempo": "libstempo"}, - package_data={"libstempo": ["data/*", "ecc_vs_nharm.txt"]}, - py_modules=[ - "libstempo.like", - "libstempo.multinest", - "libstempo.emcee", - "libstempo.plot", - "libstempo.toasim", - "libstempo.spharmORFbasis", - "libstempo.eccUtils", - ], - setup_requires=["cython>=0.22", "numpy<2.0"], - install_requires=["numpy>=1.15.0,<2.0", "scipy>=1.2.0", "matplotlib>=3.3.2", "ephem>=3.7.7.1"], - extras_require={"astropy": ["astropy>=4.1"]}, - python_requires=">=3.7", - ext_modules=cythonize( - Extension( - "libstempo.libstempo", - ["libstempo/libstempo.pyx"], - language="c++", - include_dirs=[TEMPO2 + "/include", numpy.get_include()], - libraries=["tempo2", "tempo2pred"], - library_dirs=[TEMPO2 + "/lib"], - extra_compile_args=["-Wno-unused-function"], - extra_link_args=linkArgs, - ) + +ext_modules = [ + Extension( + "libstempo.libstempo", + ["libstempo/libstempo.pyx"], + language="c++", + include_dirs=[TEMPO2 + "/include", numpy.get_include()], + libraries=["tempo2", "tempo2pred"], + library_dirs=[TEMPO2 + "/lib"], + extra_compile_args=["-Wno-unused-function"], + extra_link_args=linkArgs, ), +] + +# add language level = 3 +for e in ext_modules: + e.cython_directives = {"language_level": "3"} + +setup( + ext_modules=ext_modules, ) From bda209c72a2bc6898bd6fca4cfd293278530185f Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 3 Jul 2024 22:11:59 +0100 Subject: [PATCH 05/20] pyproject.toml: add pypi upload info, remove some minimal dependency pinning that will be unneccsary for Python >=3.9 --- pyproject.toml | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 67aabe6..6236767 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,20 @@ +# to create a new release, do the following: +# install the build and twine packages +# $ pip install build twine +# create a git tag with the new version number, e.g., +# $ git tag -a v3.5.0 -m "Version 3.5.0" +# build the source distribution +# $ python -m build --sdist --outdir . +# Upload to PyPI with: +# $ twine upload --repository libstempo libstempo-*.tar.gz + [build-system] requires = [ "setuptools>=61", "setuptools_scm[toml]>=6.2", "wheel", # ephem package likes to have wheel installed "cython", - "numpy>=2.0.0rc1", + "numpy>=2.0.0", ] build-backend = "setuptools.build_meta" @@ -33,25 +43,25 @@ dynamic = [ requires-python = ">=3.9, <4" dependencies = [ - "numpy>=1.15.0", - "scipy>=1.2.0", - "matplotlib>=3.3.2", - "ephem>=3.7.7.1", + "numpy", + "scipy", + "matplotlib", + "ephem", ] [project.optional-dependencies] astropy = [ - "astropy>=4.1", + "astropy", ] dev = [ - "black~=22.3.0", - "flake8~=3.7.7", - "pre-commit~=1.15.2", - "wheel>=0.29.0", - "coverage>=4.5.3", - "pytest>=4.0.0", - "pytest-cov>=2.7.0", - "jupyter>=1.0.0", + "black", + "flake8", + "pre-commit", + "wheel", + "coverage", + "pytest", + "pytest-cov", + "jupyter", ] [tool.setuptools] @@ -85,4 +95,4 @@ exclude = """ | .libstempo )/ ) -""" \ No newline at end of file +""" From 4e239a19056dcf3e2c48b7a6476b824b3895f4b9 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 3 Jul 2024 22:18:06 +0100 Subject: [PATCH 06/20] Re-allow Python 3.8 --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6236767..86182e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ classifiers=[ "Operating System :: MacOS", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -41,7 +42,7 @@ dynamic = [ "version", ] -requires-python = ">=3.9, <4" +requires-python = ">=3.8, <4" dependencies = [ "numpy", "scipy", From bdb01c760f994d1ce561ce2710655639b9660106 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 3 Jul 2024 22:37:32 +0100 Subject: [PATCH 07/20] Update github action --- .github/workflows/ci_tests.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 7fb9e3b..1a6cd3b 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -42,8 +42,7 @@ jobs: - name: Install dependencies and package run: | python -m pip install --upgrade pip - python -m pip install -r requirements_dev.txt - pip install -e .[astropy] + pip install -e .[astropy,dev] - name: Run lint run: make lint - name: Test with pytest @@ -73,8 +72,8 @@ jobs: ./install_tempo2.sh - name: Build run: | - python -m pip install --upgrade pip setuptools wheel - pip install -r requirements.txt + python -m pip install --upgrade pip setuptools wheel build + python -m build --sdist --outdir dist make dist - name: Test the sdist run: | From 0585bde044206f6b2106f6690cc9df3bffe3b91f Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 3 Jul 2024 22:44:32 +0100 Subject: [PATCH 08/20] Switch back to requiring Python 3.9 --- .github/workflows/ci_tests.yml | 2 +- pyproject.toml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 1a6cd3b..123b35a 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ['3.9', '3.10', '3.11'] steps: - name: Checkout repository diff --git a/pyproject.toml b/pyproject.toml index 86182e5..6236767 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,6 @@ classifiers=[ "Operating System :: MacOS", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -42,7 +41,7 @@ dynamic = [ "version", ] -requires-python = ">=3.8, <4" +requires-python = ">=3.9, <4" dependencies = [ "numpy", "scipy", From f1ba9185cf29134f89bc2eafdfae932d0c4b21d0 Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Thu, 4 Jul 2024 09:32:54 +0100 Subject: [PATCH 09/20] Update pyproject.toml: try and keep Python 3.8 support --- pyproject.toml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6236767..0417bcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,8 @@ requires = [ "setuptools_scm[toml]>=6.2", "wheel", # ephem package likes to have wheel installed "cython", - "numpy>=2.0.0", + 'numpy>=2.0.0; python_version > "3.8"', + 'numpy<2.0; python_version == "3.8", ] build-backend = "setuptools.build_meta" @@ -32,6 +33,7 @@ classifiers=[ "Operating System :: MacOS", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -41,9 +43,10 @@ dynamic = [ "version", ] -requires-python = ">=3.9, <4" +requires-python = ">=3.8, <4" dependencies = [ - "numpy", + 'numpy<2.0; python_version == "3.8"', + 'numpy; python_version > "3.8"', "scipy", "matplotlib", "ephem", From b2d21aad283d67c3aeca8473c3e1f3ddf968dc12 Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Thu, 4 Jul 2024 09:33:28 +0100 Subject: [PATCH 10/20] Update ci_tests.yml: re-add Python 3.8 check --- .github/workflows/ci_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 123b35a..1a6cd3b 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - python-version: ['3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11'] steps: - name: Checkout repository From f5949d562afe7e4b4cafb87f7f6388a51af4ce7d Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Thu, 4 Jul 2024 09:36:54 +0100 Subject: [PATCH 11/20] Update pyproject.toml: close quote --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0417bcc..6a26f12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ requires = [ "wheel", # ephem package likes to have wheel installed "cython", 'numpy>=2.0.0; python_version > "3.8"', - 'numpy<2.0; python_version == "3.8", + 'numpy<2.0; python_version == "3.8"', ] build-backend = "setuptools.build_meta" From cd9698b283f677a5dd686f1b68a297f9ef22e11a Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Thu, 4 Jul 2024 09:48:51 +0100 Subject: [PATCH 12/20] ci_tests.yml: run lint before installation --- .github/workflows/ci_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 1a6cd3b..48ade00 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -39,12 +39,12 @@ jobs: if: runner.os == 'Linux' run: | ./install_tempo2.sh + - name: Run lint + run: make lint - name: Install dependencies and package run: | python -m pip install --upgrade pip pip install -e .[astropy,dev] - - name: Run lint - run: make lint - name: Test with pytest run: make test From 856f1735d2a200601316d6ffcfc79f86551e6132 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Thu, 4 Jul 2024 09:49:00 +0100 Subject: [PATCH 13/20] Apply black --- libstempo/__init__.py | 2 +- libstempo/toasim.py | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/libstempo/__init__.py b/libstempo/__init__.py index 339ba23..e672189 100644 --- a/libstempo/__init__.py +++ b/libstempo/__init__.py @@ -16,4 +16,4 @@ try: from ._version import version as __version__ except ModuleNotFoundError: - __version__ = "" \ No newline at end of file + __version__ = "" diff --git a/libstempo/toasim.py b/libstempo/toasim.py index 1a93ff3..2e7d352 100644 --- a/libstempo/toasim.py +++ b/libstempo/toasim.py @@ -63,7 +63,6 @@ def add_dipole_gwb( dipoledir=None, dipolemag=None, ): - """Add a stochastic background from inspiraling binaries distributed according to a pure dipole distribution, using the tempo2 code that underlies the GWdipolebkgrd plugin. @@ -502,7 +501,6 @@ def add_cgw( # evolution if evolve: - # calculate time dependent frequency at earth and pulsar omega = w0 * (1 - fac1 * toas) ** (-3 / 8) omega_p = w0 * (1 - fac1 * tp) ** (-3 / 8) @@ -513,7 +511,6 @@ def add_cgw( # use approximation that frequency does not evlolve over observation time elif phase_approx: - # frequencies omega = w0 omega_p = w0 * (1 + fac1 * pd * (1 - cosMu)) ** (-3 / 8) @@ -524,7 +521,6 @@ def add_cgw( # no evolution else: - # monochromatic omega = w0 omega_p = omega @@ -681,7 +677,6 @@ def add_ecc_cgw( # pulsar term ##### if psrTerm: - # convert units pd *= eu.KPC2S # convert from kpc to seconds @@ -855,7 +850,6 @@ def createGWB( # strain amplitude if userSpec is None: - f1yr = 1 / 3.16e7 alpha = -0.5 * (gam - 3) hcf = Amp * (f / f1yr) ** (alpha) @@ -864,7 +858,6 @@ def createGWB( hcf /= (1 + (f / f0) ** (power * si)) ** (1 / power) elif userSpec is not None: - freqs = userSpec[:, 0] if len(userSpec[:, 0]) != len(freqs): raise ValueError("Number of supplied spectral points does not match number of frequencies!") From a0857ad80021ff990c7dc5b6ec96998407decbab Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Thu, 4 Jul 2024 10:13:13 +0100 Subject: [PATCH 14/20] exclude _version.py from black-ification --- .github/workflows/ci_tests.yml | 4 ++-- pyproject.toml | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 48ade00..1a6cd3b 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -39,12 +39,12 @@ jobs: if: runner.os == 'Linux' run: | ./install_tempo2.sh - - name: Run lint - run: make lint - name: Install dependencies and package run: | python -m pip install --upgrade pip pip install -e .[astropy,dev] + - name: Run lint + run: make lint - name: Test with pytest run: make test diff --git a/pyproject.toml b/pyproject.toml index 6a26f12..fc01913 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,8 +81,8 @@ write_to = "libstempo/_version.py" [tool.black] line-length = 120 target_version = ['py39'] -include = "\\.pyi?$" -exclude = """ +include = '\\.pyi?$' +exclude = ''' ( /( \\.eggs # exclude a few common directories in the @@ -96,6 +96,7 @@ exclude = """ | dist | docs | .libstempo + | libstempo/_version\.py )/ ) -""" +''' From 0e1829459472dffcec6a1c09eab8e80956bda6b0 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Thu, 4 Jul 2024 10:29:03 +0100 Subject: [PATCH 15/20] Move flake8 config into pyproject.toml and require flake8-pyproject package --- .flake8 | 17 ----------------- pyproject.toml | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 17 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index c65bcc8..0000000 --- a/.flake8 +++ /dev/null @@ -1,17 +0,0 @@ -[flake8] -max-line-length = 120 -max-complexity = 45 -ignore = - E203 - W503 # line break before binary operator; conflicts with black - E722 # bare except ok - E731 # lambda expressions ok - E741 # undescriptive variable ok -exclude = - .git - .tox - __pycache__ - build - dist - docs - .libstempo \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index fc01913..6b9bace 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,7 @@ astropy = [ dev = [ "black", "flake8", + "Flake8-pyproject", "pre-commit", "wheel", "coverage", @@ -100,3 +101,23 @@ exclude = ''' )/ ) ''' + +[tool.flake8] +max-line-length = 120 +max-complexity = 45 +ignore = [ + "E203", + "W503", # line break before binary operator; conflicts with black + "E722", # bare except ok + "E731", # lambda expressions ok + "E741", # undescriptive variable ok +] +exclude = [ + ".git", + ".tox", + "__pycache__", + "build", + "dist", + "docs", + ".libstempo", +] From bc989a5a1e33565129e8eff4a973f678f607c5e5 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Thu, 4 Jul 2024 10:45:41 +0100 Subject: [PATCH 16/20] libstempo/plot.py: fix following flake8 run --- libstempo/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstempo/plot.py b/libstempo/plot.py index 03121ef..4a2ec27 100644 --- a/libstempo/plot.py +++ b/libstempo/plot.py @@ -120,7 +120,7 @@ def plothist( for i in range(p): # figure out how big the multiplot needs to be - if type(append) == int: # need this since isinstance(False,int) == True + if type(append) is int: # need this since isinstance(False,int) == True q = append elif isinstance(append, (list, tuple)): q = len(append) From 8146f850bba49ee72fa741155c001a603a931a0f Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Thu, 4 Jul 2024 16:42:08 +0100 Subject: [PATCH 17/20] libstempo.pyx: set long double format to be ARM64 compatible --- libstempo/libstempo.pyx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libstempo/libstempo.pyx b/libstempo/libstempo.pyx index 8f6afa1..d90fc42 100644 --- a/libstempo/libstempo.pyx +++ b/libstempo/libstempo.pyx @@ -63,6 +63,12 @@ from functools import wraps from . import utils +# set long double format for ARM64 compatibility +try: + NP_LONG_DOUBLE_FORMAT = numpy.float128 +except AttributeError: + NP_LONG_DOUBLE_FORMAT = numpy.double + # return numpy array as astropy table with unit def dimensionfy(unit): def dimensionfy_decorator(func): @@ -884,12 +890,12 @@ cdef class tempopulsar: toas = self.__input_toas if toas is not None: - if isinstance(toas, (list, numpy.ndarray, tuple, float, numpy.float128)): - toamjd = numpy.atleast_1d(toas).astype(numpy.float128) + if isinstance(toas, (list, numpy.ndarray, tuple, float, NP_LONG_DOUBLE_FORMAT)): + toamjd = numpy.atleast_1d(toas).astype(NP_LONG_DOUBLE_FORMAT) else: # check if using an astropy time object try: - toamjd = numpy.atleast_1d(toas.mjd).astype(numpy.float128) # make sure in MJD + toamjd = numpy.atleast_1d(toas.mjd).astype(NP>_LONG_DOUBLE_FORMAT) # make sure in MJD except Exception as e: raise TypeError("Input TOAs are not of an allowed type: {}".format(e)) @@ -939,7 +945,7 @@ cdef class tempopulsar: npjump = numpy.asarray(_jump) npfdjump = numpy.asarray(_fdjump) - days = numpy.floor(toas).astype(numpy.float128) + days = numpy.floor(toas).astype(NP_LONG_DOUBLE_FORMAT) npsatday[:] = days npsatsec[:] = toas - days From 026b631b190db2d23667c6e17f23c108a612541c Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Thu, 4 Jul 2024 16:52:31 +0100 Subject: [PATCH 18/20] libstempo.pyx: fix typo --- libstempo/libstempo.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstempo/libstempo.pyx b/libstempo/libstempo.pyx index d90fc42..f95da2f 100644 --- a/libstempo/libstempo.pyx +++ b/libstempo/libstempo.pyx @@ -895,7 +895,7 @@ cdef class tempopulsar: else: # check if using an astropy time object try: - toamjd = numpy.atleast_1d(toas.mjd).astype(NP>_LONG_DOUBLE_FORMAT) # make sure in MJD + toamjd = numpy.atleast_1d(toas.mjd).astype(NP_LONG_DOUBLE_FORMAT) # make sure in MJD except Exception as e: raise TypeError("Input TOAs are not of an allowed type: {}".format(e)) From 44129eefcf8d2794d6b2350cecd1652f8c44a966 Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Fri, 19 Jul 2024 08:49:11 +0100 Subject: [PATCH 19/20] Update ci_tests.yml: add Python 3.12 to test suite --- .github/workflows/ci_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 1a6cd3b..5eb7810 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -20,7 +20,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: - name: Checkout repository From a2c0e7da31e4328e3c51002c8b910a52006a0be3 Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Fri, 19 Jul 2024 08:50:00 +0100 Subject: [PATCH 20/20] Update pyproject.toml: add Python 3.12 to the classifiers --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 6b9bace..084c15a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,7 @@ classifiers=[ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] dynamic = [