Skip to content

Commit 9769691

Browse files
authored
Merge pull request #230 from pynbody/python-3.12
Add python 3.12 to test matrix
2 parents 1d3b019 + bc7cbb0 commit 9769691

File tree

9 files changed

+42
-21
lines changed

9 files changed

+42
-21
lines changed

.github/workflows/build-test.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [ubuntu-latest]
16-
python-version: [3.8, 3.9, "3.10", "3.11"]
16+
python-version: [3.9, "3.10", "3.11", "3.12"]
1717
sqlalchemy-version: ["1.4", "2.0"]
18-
numpy-version: ["1.18", "1.22"]
18+
numpy-version: ["1.22", "1.26"]
1919
TANGOS_TESTING_DB_BACKEND: [sqlite, mysql+pymysql, postgresql+psycopg2]
20+
exclude:
21+
- python-version: "3.12"
22+
sqlalchemy-version: "1.4"
23+
- python-version: "3.12"
24+
numpy-version: "1.22"
25+
2026
runs-on: ${{ matrix.os }}
2127
env:
2228
C: gcc-10
@@ -55,10 +61,10 @@ jobs:
5561
- name: Install python dependencies
5662
run: |
5763
python -m pip install --upgrade pip setuptools wheel
58-
python -m pip install numpy~=${{ matrix.numpy-version}} scipy "matplotlib<3.3.0" pytest h5py pip webtest pyquery sphinx pygments pandas sqlalchemy~=${{ matrix.sqlalchemy-version}} cython pyramid ipython pyramid_mako PyMySQL[rsa] psycopg2-binary
64+
python -m pip install numpy~=${{ matrix.numpy-version}} sqlalchemy~=${{ matrix.sqlalchemy-version}}
5965
- name: Build and install tangos
6066
run: |
61-
python setup.py develop
67+
pip install -e .[test,rmdbs]
6268
- name: Check that tangos can import without pynbody
6369
run: |
6470
python -c "import tangos"

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def get_version(rel_path):
7272
"Programming Language :: Python :: 3.9",
7373
"Programming Language :: Python :: 3.10",
7474
"Programming Language :: Python :: 3.11",
75+
"Programming Language :: Python :: 3.12",
7576
"License :: OSI Approved :: BSD License",
7677
],
7778
author="Andrew Pontzen",
@@ -100,5 +101,9 @@ def get_version(rel_path):
100101
tests_require=tests_require,
101102
test_suite="tests",
102103
long_description=long_description,
103-
long_description_content_type='text/markdown'
104+
long_description_content_type='text/markdown',
105+
extras_require={'test': tests_require,
106+
'rmdbs': ['PyMySQL[rsa]',
107+
'psycopg2-binary']
108+
}
104109
)

tangos/core/halo_data/link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class HaloLink(Base):
1616

1717
halo_from = relationship(SimulationObjectBase, primaryjoin=halo_from_id == SimulationObjectBase.id,
1818
backref=backref('links', cascade_backrefs=False,
19-
lazy='dynamic',
19+
lazy='dynamic', viewonly=True,
2020
primaryjoin=halo_from_id == SimulationObjectBase.id),
2121
cascade='')
2222

2323
halo_to = relationship(SimulationObjectBase, primaryjoin=(halo_to_id == SimulationObjectBase.id),
2424
backref=backref('reverse_links', cascade_backrefs=False,
25-
lazy='dynamic',
25+
lazy='dynamic', viewonly=True,
2626
primaryjoin=halo_to_id == SimulationObjectBase.id),
2727
cascade='')
2828

tangos/core/halo_data/property.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class HaloProperty(Base):
1515
# n.b. backref defined below
1616
halo = relationship(SimulationObjectBase, cascade='',
1717
backref=backref('all_properties',overlaps='properties,deprecated_properties',
18-
cascade_backrefs=False),
18+
cascade_backrefs=False, viewonly=True),
1919
overlaps='properties,deprecated_properties')
2020

2121
data_float = Column(DOUBLE_PRECISION)
@@ -27,8 +27,10 @@ class HaloProperty(Base):
2727

2828
deprecated = Column(Boolean, default=False, nullable=False)
2929

30-
creator = relationship(creator.Creator, backref=backref(
31-
'properties', cascade_backrefs=False, lazy='dynamic'), cascade='save-update')
30+
creator = relationship(creator.Creator,
31+
backref=backref('properties', cascade_backrefs=False,
32+
lazy='dynamic', viewonly=True),
33+
cascade='save-update')
3234
creator_id = Column(Integer, ForeignKey('creators.id'))
3335

3436
def __init__(self, halo, name, data):

tangos/properties/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import functools
22
import importlib
33
import os
4+
import sys
45
import warnings
6+
from importlib.metadata import entry_points
57

68
import numpy as np
7-
import pkg_resources
8-
9-
from tangos.util import timing_monitor
109

1110
from .. import input_handlers, parallel_tasks
1211
from ..log import logger
12+
from ..util import timing_monitor
1313

1414

1515
class PropertyCalculationMetaClass(type):
@@ -569,6 +569,12 @@ def instantiate_class(simulation, property_name, silent_fail=False):
569569
else:
570570
return instance[0]
571571

572+
def _get_entry_points():
573+
if sys.version_info >= (3, 10):
574+
return entry_points(group='tangos.property_modules')
575+
else:
576+
return entry_points().get('tangos.property_modules', [])
577+
572578
def _import_configured_property_modules():
573579
if "PYTEST_CURRENT_TEST" in os.environ:
574580
warnings.warn("Not importing external property modules during testing", ImportWarning)
@@ -582,7 +588,7 @@ def _import_configured_property_modules():
582588
except ImportError:
583589
warnings.warn("Failed to import requested property module %r. Some properties may be unavailable."%pm,
584590
ImportWarning)
585-
for module in pkg_resources.iter_entry_points('tangos.property_modules'):
591+
for module in _get_entry_points():
586592
module.load()
587593

588594
_import_configured_property_modules()

tangos/testing/db_diff.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ def compare_timestep(self, ts):
104104

105105

106106
def _joined_links_load(self, parent):
107-
return object_session(parent).query(core.HaloLink).with_parent(parent, type(parent).all_links).\
108-
options(joinedload(core.HaloLink.halo_to))
107+
return (object_session(parent).query(core.HaloLink).where(
108+
core.HaloLink.halo_from_id == parent.id
109+
).options(joinedload(core.HaloLink.halo_to)))
109110

110111
def _joined_properties_load(self, parent):
111-
return object_session(parent).query(core.HaloProperty).with_parent(parent, type(parent).all_properties).\
112-
options(undefer("*")).options(joinedload(core.HaloProperty.name))
112+
return object_session(parent).query(core.HaloProperty).where(
113+
core.HaloProperty.halo_id == parent.id
114+
).options(undefer("*")).options(joinedload(core.HaloProperty.name))
113115

114116
def compare_object(self, obj):
115117
obj1 = get_object(obj, self.session1)

tangos/tools/consistent_trees_importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def store_ids(self, ts, id_to_tree_id):
113113
props = []
114114
for o in objs.values():
115115
if isinstance(o, PhantomHalo):
116-
tree_id = id_to_tree_id.get(-o.finder_id, None)
116+
tree_id = id_to_tree_id.get(-int(o.finder_id), None)
117117
else:
118118
tree_id = id_to_tree_id.get(o.finder_id, None)
119119
if tree_id is not None:

tests/test_consistent_trees.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _create_dummy_simsnap():
2020
f['pos'].units="Mpc"
2121
f['vel'] = np.zeros((2097152, 3)).view(pynbody.array.SimArray)
2222
f['vel'].units = "km s^-1"
23-
f['mass'] = np.zeros(2097152).view(pynbody.array.SimArray)
23+
f['mass'] = np.ones(2097152).view(pynbody.array.SimArray)
2424
f['mass'].units="Msol"
2525
f.properties['boxsize'] = pynbody.units.Unit("50 Mpc")
2626
return f

tests/test_stat_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_import_properties_is_only_numeric_or_array():
140140

141141
property = importer._create_property(db_name, halo, np.array([42.0, 42.0, 42.0]))
142142
assert property.data_is_array() == True
143-
assert property.data.dtype == np.floating
143+
assert np.issubdtype(property.data.dtype, np.floating)
144144
npt.assert_allclose(property.data, np.array([42.0, 42.0, 42.0]))
145145

146146
# Importing a string should fail

0 commit comments

Comments
 (0)