Skip to content

Commit

Permalink
Merge pull request #69 from mattpitkin/setup_update
Browse files Browse the repository at this point in the history
Update setup methods and Python version requirements
  • Loading branch information
siyuan-chen authored Jul 24, 2024
2 parents d9deb06 + a2c0e7d commit 5bdf286
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 145 deletions.
17 changes: 0 additions & 17 deletions .flake8

This file was deleted.

15 changes: 7 additions & 8 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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', '3.12']

steps:
- name: Checkout repository
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -60,7 +59,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: |
Expand All @@ -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: |
Expand Down Expand Up @@ -114,4 +113,4 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/*
twine upload dist/*
3 changes: 3 additions & 0 deletions libstempo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_version.py
*.so
*.cpp
7 changes: 5 additions & 2 deletions libstempo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
__version__ = "2.4.7"

import os
from ._find_tempo2 import find_tempo2_runtime

Expand All @@ -14,3 +12,8 @@


from libstempo.libstempo import * # noqa F401,F402,F403

try:
from ._version import version as __version__
except ModuleNotFoundError:
__version__ = ""
40 changes: 14 additions & 26 deletions libstempo/libstempo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
# what is the default encoding here?
string = lambda s: s.decode()
string_dtype = 'U'

if sys.version_info[0] < 3:
from itertools import izip as zip

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
Expand Down Expand Up @@ -81,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):
Expand Down Expand Up @@ -902,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))

Expand Down Expand Up @@ -957,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

Expand Down
2 changes: 1 addition & 1 deletion libstempo/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions libstempo/toasim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -524,7 +521,6 @@ def add_cgw(

# no evolution
else:

# monochromatic
omega = w0
omega_p = omega
Expand Down Expand Up @@ -681,7 +677,6 @@ def add_ecc_cgw(

# pulsar term #####
if psrTerm:

# convert units
pd *= eu.KPC2S # convert from kpc to seconds

Expand Down Expand Up @@ -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)
Expand All @@ -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!")
Expand Down
123 changes: 108 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,124 @@
# 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.0; python_version > "3.8"',
'numpy<2.0; python_version == "3.8"',
]
build-backend = "setuptools.build_meta"

[project]
name = "libstempo"
description = "A Python wrapper for tempo2"
authors = [{name = "Michele Vallisneri", email = "[email protected]"}]
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.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

dynamic = [
"version",
]

requires-python = ">=3.8, <4"
dependencies = [
'numpy<2.0; python_version == "3.8"',
'numpy; python_version > "3.8"',
"scipy",
"matplotlib",
"ephem",
]

[project.optional-dependencies]
astropy = [
"astropy",
]
dev = [
"black",
"flake8",
"Flake8-pyproject",
"pre-commit",
"wheel",
"coverage",
"pytest",
"pytest-cov",
"jupyter",
]

[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?$'
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
| dist
| docs
| .libstempo
| libstempo/_version\.py
)/
)
'''

[build-system]
requires = [
"setuptools>=40.8.0",
"wheel", # ephem package likes to have wheel installed
"Cython>=0.22",
"oldest-supported-numpy",
[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",
]
build-backend = "setuptools.build_meta"
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

9 changes: 0 additions & 9 deletions requirements_dev.txt

This file was deleted.

Loading

0 comments on commit 5bdf286

Please sign in to comment.