Skip to content

Commit 5bdf286

Browse files
authored
Merge pull request #69 from mattpitkin/setup_update
Update setup methods and Python version requirements
2 parents d9deb06 + a2c0e7d commit 5bdf286

File tree

13 files changed

+171
-145
lines changed

13 files changed

+171
-145
lines changed

.flake8

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

.github/workflows/ci_tests.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
os: [ubuntu-latest, macos-latest]
23-
python-version: ['3.7', '3.8', '3.9', '3.10']
23+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
2424

2525
steps:
2626
- name: Checkout repository
@@ -33,7 +33,7 @@ jobs:
3333
if: runner.os == 'macOS'
3434
run: |
3535
brew unlink gcc && brew link gcc
36-
brew install automake
36+
brew install automake libtool
3737
./install_tempo2.sh
3838
- name: Install tempo2 on linux
3939
if: runner.os == 'Linux'
@@ -42,8 +42,7 @@ jobs:
4242
- name: Install dependencies and package
4343
run: |
4444
python -m pip install --upgrade pip
45-
python -m pip install -r requirements_dev.txt
46-
pip install -e .[astropy]
45+
pip install -e .[astropy,dev]
4746
- name: Run lint
4847
run: make lint
4948
- name: Test with pytest
@@ -60,7 +59,7 @@ jobs:
6059
- name: Set up Python
6160
uses: actions/setup-python@v2
6261
with:
63-
python-version: '3.7'
62+
python-version: '3.10'
6463
- name: Install tempo2 on mac
6564
if: runner.os == 'macOS'
6665
run: |
@@ -73,8 +72,8 @@ jobs:
7372
./install_tempo2.sh
7473
- name: Build
7574
run: |
76-
python -m pip install --upgrade pip setuptools wheel
77-
pip install -r requirements.txt
75+
python -m pip install --upgrade pip setuptools wheel build
76+
python -m build --sdist --outdir dist
7877
make dist
7978
- name: Test the sdist
8079
run: |
@@ -114,4 +113,4 @@ jobs:
114113
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
115114
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
116115
run: |
117-
twine upload dist/*
116+
twine upload dist/*

libstempo/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_version.py
2+
*.so
3+
*.cpp

libstempo/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
__version__ = "2.4.7"
2-
31
import os
42
from ._find_tempo2 import find_tempo2_runtime
53

@@ -14,3 +12,8 @@
1412

1513

1614
from libstempo.libstempo import * # noqa F401,F402,F403
15+
16+
try:
17+
from ._version import version as __version__
18+
except ModuleNotFoundError:
19+
__version__ = ""

libstempo/libstempo.pyx

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,12 @@ import os, sys, math, re, time
44
from packaging import version
55

66
import collections
7+
from collections import OrderedDict
78

8-
try:
9-
from collections import OrderedDict
10-
except ImportError:
11-
# this is for Python 2.6 compatibility, we may be able to drop it
12-
from ordereddict import OrderedDict
13-
14-
# Python 2/3 compatibility
9+
# what is the default encoding here?
10+
string = lambda s: s.decode()
11+
string_dtype = 'U'
1512

16-
if sys.version_info[0] < 3:
17-
from itertools import izip as zip
18-
19-
string = lambda s: s
20-
string_dtype = 'S'
21-
else:
22-
# what is the default encoding here?
23-
string = lambda s: s.decode()
24-
string_dtype = 'U'
25-
26-
# get zip-as-iterator behavior in Python 2
27-
try:
28-
import itertools.izip as zip
29-
except ImportError:
30-
pass
3113

3214
from libc cimport stdlib, stdio
3315
from libc.string cimport strncpy, memset
@@ -81,6 +63,12 @@ from functools import wraps
8163

8264
from . import utils
8365

66+
# set long double format for ARM64 compatibility
67+
try:
68+
NP_LONG_DOUBLE_FORMAT = numpy.float128
69+
except AttributeError:
70+
NP_LONG_DOUBLE_FORMAT = numpy.double
71+
8472
# return numpy array as astropy table with unit
8573
def dimensionfy(unit):
8674
def dimensionfy_decorator(func):
@@ -902,12 +890,12 @@ cdef class tempopulsar:
902890
toas = self.__input_toas
903891

904892
if toas is not None:
905-
if isinstance(toas, (list, numpy.ndarray, tuple, float, numpy.float128)):
906-
toamjd = numpy.atleast_1d(toas).astype(numpy.float128)
893+
if isinstance(toas, (list, numpy.ndarray, tuple, float, NP_LONG_DOUBLE_FORMAT)):
894+
toamjd = numpy.atleast_1d(toas).astype(NP_LONG_DOUBLE_FORMAT)
907895
else:
908896
# check if using an astropy time object
909897
try:
910-
toamjd = numpy.atleast_1d(toas.mjd).astype(numpy.float128) # make sure in MJD
898+
toamjd = numpy.atleast_1d(toas.mjd).astype(NP_LONG_DOUBLE_FORMAT) # make sure in MJD
911899
except Exception as e:
912900
raise TypeError("Input TOAs are not of an allowed type: {}".format(e))
913901

@@ -957,7 +945,7 @@ cdef class tempopulsar:
957945
npjump = numpy.asarray(_jump)
958946
npfdjump = numpy.asarray(_fdjump)
959947

960-
days = numpy.floor(toas).astype(numpy.float128)
948+
days = numpy.floor(toas).astype(NP_LONG_DOUBLE_FORMAT)
961949
npsatday[:] = days
962950
npsatsec[:] = toas - days
963951

libstempo/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def plothist(
120120

121121
for i in range(p):
122122
# figure out how big the multiplot needs to be
123-
if type(append) == int: # need this since isinstance(False,int) == True
123+
if type(append) is int: # need this since isinstance(False,int) == True
124124
q = append
125125
elif isinstance(append, (list, tuple)):
126126
q = len(append)

libstempo/toasim.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def add_dipole_gwb(
6363
dipoledir=None,
6464
dipolemag=None,
6565
):
66-
6766
"""Add a stochastic background from inspiraling binaries distributed
6867
according to a pure dipole distribution, using the tempo2
6968
code that underlies the GWdipolebkgrd plugin.
@@ -502,7 +501,6 @@ def add_cgw(
502501

503502
# evolution
504503
if evolve:
505-
506504
# calculate time dependent frequency at earth and pulsar
507505
omega = w0 * (1 - fac1 * toas) ** (-3 / 8)
508506
omega_p = w0 * (1 - fac1 * tp) ** (-3 / 8)
@@ -513,7 +511,6 @@ def add_cgw(
513511

514512
# use approximation that frequency does not evlolve over observation time
515513
elif phase_approx:
516-
517514
# frequencies
518515
omega = w0
519516
omega_p = w0 * (1 + fac1 * pd * (1 - cosMu)) ** (-3 / 8)
@@ -524,7 +521,6 @@ def add_cgw(
524521

525522
# no evolution
526523
else:
527-
528524
# monochromatic
529525
omega = w0
530526
omega_p = omega
@@ -681,7 +677,6 @@ def add_ecc_cgw(
681677

682678
# pulsar term #####
683679
if psrTerm:
684-
685680
# convert units
686681
pd *= eu.KPC2S # convert from kpc to seconds
687682

@@ -855,7 +850,6 @@ def createGWB(
855850

856851
# strain amplitude
857852
if userSpec is None:
858-
859853
f1yr = 1 / 3.16e7
860854
alpha = -0.5 * (gam - 3)
861855
hcf = Amp * (f / f1yr) ** (alpha)
@@ -864,7 +858,6 @@ def createGWB(
864858
hcf /= (1 + (f / f0) ** (power * si)) ** (1 / power)
865859

866860
elif userSpec is not None:
867-
868861
freqs = userSpec[:, 0]
869862
if len(userSpec[:, 0]) != len(freqs):
870863
raise ValueError("Number of supplied spectral points does not match number of frequencies!")

pyproject.toml

Lines changed: 108 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,124 @@
1+
# to create a new release, do the following:
2+
# install the build and twine packages
3+
# $ pip install build twine
4+
# create a git tag with the new version number, e.g.,
5+
# $ git tag -a v3.5.0 -m "Version 3.5.0"
6+
# build the source distribution
7+
# $ python -m build --sdist --outdir .
8+
# Upload to PyPI with:
9+
# $ twine upload --repository libstempo libstempo-*.tar.gz
10+
11+
[build-system]
12+
requires = [
13+
"setuptools>=61",
14+
"setuptools_scm[toml]>=6.2",
15+
"wheel", # ephem package likes to have wheel installed
16+
"cython",
17+
'numpy>=2.0.0; python_version > "3.8"',
18+
'numpy<2.0; python_version == "3.8"',
19+
]
20+
build-backend = "setuptools.build_meta"
21+
22+
[project]
23+
name = "libstempo"
24+
description = "A Python wrapper for tempo2"
25+
authors = [{name = "Michele Vallisneri", email = "[email protected]"}]
26+
urls = { Homepage = "https://github.com/vallis/libstempo" }
27+
readme = "README.md"
28+
license = { text = "MIT" }
29+
classifiers=[
30+
"Intended Audience :: Developers",
31+
"Intended Audience :: Science/Research",
32+
"License :: OSI Approved :: MIT License",
33+
"Operating System :: MacOS",
34+
"Operating System :: POSIX :: Linux",
35+
"Programming Language :: Python :: 3",
36+
"Programming Language :: Python :: 3.8",
37+
"Programming Language :: Python :: 3.9",
38+
"Programming Language :: Python :: 3.10",
39+
"Programming Language :: Python :: 3.11",
40+
"Programming Language :: Python :: 3.12",
41+
]
42+
43+
dynamic = [
44+
"version",
45+
]
46+
47+
requires-python = ">=3.8, <4"
48+
dependencies = [
49+
'numpy<2.0; python_version == "3.8"',
50+
'numpy; python_version > "3.8"',
51+
"scipy",
52+
"matplotlib",
53+
"ephem",
54+
]
55+
56+
[project.optional-dependencies]
57+
astropy = [
58+
"astropy",
59+
]
60+
dev = [
61+
"black",
62+
"flake8",
63+
"Flake8-pyproject",
64+
"pre-commit",
65+
"wheel",
66+
"coverage",
67+
"pytest",
68+
"pytest-cov",
69+
"jupyter",
70+
]
71+
72+
[tool.setuptools]
73+
include-package-data = true
74+
75+
[tool.setuptools.packages.find]
76+
include = [
77+
"libstempo*",
78+
]
79+
80+
[tool.setuptools_scm]
81+
write_to = "libstempo/_version.py"
82+
183
[tool.black]
284
line-length = 120
3-
target_version = ['py38']
4-
include = '\.pyi?$'
85+
target_version = ['py39']
86+
include = '\\.pyi?$'
587
exclude = '''
6-
788
(
889
/(
9-
\.eggs # exclude a few common directories in the
10-
| \.git # root of the project
11-
| \.hg
12-
| \.mypy_cache
13-
| \.tox
90+
\\.eggs # exclude a few common directories in the
91+
| \\.git # root of the project
92+
| \\.hg
93+
| \\.mypy_cache
94+
| \\.tox
1495
| _build
1596
| buck-out
1697
| build
1798
| dist
1899
| docs
19100
| .libstempo
101+
| libstempo/_version\.py
20102
)/
21103
)
22104
'''
23105

24-
[build-system]
25-
requires = [
26-
"setuptools>=40.8.0",
27-
"wheel", # ephem package likes to have wheel installed
28-
"Cython>=0.22",
29-
"oldest-supported-numpy",
106+
[tool.flake8]
107+
max-line-length = 120
108+
max-complexity = 45
109+
ignore = [
110+
"E203",
111+
"W503", # line break before binary operator; conflicts with black
112+
"E722", # bare except ok
113+
"E731", # lambda expressions ok
114+
"E741", # undescriptive variable ok
115+
]
116+
exclude = [
117+
".git",
118+
".tox",
119+
"__pycache__",
120+
"build",
121+
"dist",
122+
"docs",
123+
".libstempo",
30124
]
31-
build-backend = "setuptools.build_meta"

requirements.txt

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

requirements_dev.txt

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

0 commit comments

Comments
 (0)