Skip to content

Commit 0fb8b0f

Browse files
author
chad
committed
Add Python 3.11-3.13 compatibility
1 parent c7ff782 commit 0fb8b0f

13 files changed

Lines changed: 62 additions & 54 deletions

File tree

.github/workflows/python-package-version-test.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.9", "3.10"]
19+
python-version: ["3.10", "3.11", "3.12", "3.13"]
2020

2121
steps:
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2323
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v3
24+
uses: actions/setup-python@v5
2525
with:
2626
python-version: ${{ matrix.python-version }}
2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
3030
python -m pip install ruff pytest
31-
pip install torch==2.6.0
3231
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3332
- name: Lint with ruff
3433
run: |

.github/workflows/python-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
runs-on: ubuntu-latest
2222

2323
steps:
24-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2525
- name: Set up Python
26-
uses: actions/setup-python@v3
26+
uses: actions/setup-python@v5
2727
with:
2828
python-version: '3.x'
2929
- name: Install dependencies

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<img src="https://raw.githubusercontent.com/lab-v2/pyreason/main/media/pyreason_logo.jpg"/>
22

3-
[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/)
43
[![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-3100/)
4+
[![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-3110/)
5+
[![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/release/python-3120/)
6+
[![Python 3.13](https://img.shields.io/badge/python-3.13-blue.svg)](https://www.python.org/downloads/release/python-3130/)
57
[![Documentation Status](https://readthedocs.org/projects/pyreason/badge/?version=latest)](https://pyreason.readthedocs.io/en/latest/?badge=latest)
68
[![pypi](https://github.com/lab-v2/pyreason/actions/workflows/python-publish.yml/badge.svg)](https://github.com/lab-v2/pyreason/actions/workflows/python-publish.yml)
79
[![Tests](https://github.com/lab-v2/pyreason/actions/workflows/python-package-version-test.yml/badge.svg)](https://github.com/lab-v2/pyreason/actions/workflows/python-package-version-test.yml)
@@ -43,7 +45,7 @@ PyReason can be installed as a python library using
4345
```bash
4446
pip install pyreason
4547
```
46-
The Python versions that are currently supported are `3.7`, `3.8`, `3.9`, `3.10`. If you want multi-core parallel support only `3.9` and `3.10` versions work due to limited numba support.
48+
The Python versions that are currently supported are `3.10`, `3.11`, `3.12`, and `3.13`.
4749

4850
## 4. Bibtex
4951
If you used this software in your work please cite our paper

docs/source/installation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Installation
22
==========
33

4-
PyReason is currently compatible with Python 3.9 and 3.10. To install PyReason, you can use pip:
4+
PyReason is currently compatible with Python 3.10, 3.11, 3.12, and 3.13. To install PyReason, you can use pip:
55

66
.. code:: bash
77
@@ -12,7 +12,7 @@ Make sure you're using the correct version of Python. You can create a conda env
1212

1313
.. code:: bash
1414
15-
conda create -n pyreason-env python=3.10
15+
conda create -n pyreason-env python=3.13
1616
1717
PyReason uses a JIT compiler called `Numba <https://numba.pydata.org/>`_ to speed up the reasoning process. This means that
1818
the first time PyReason is imported it will have to compile certain functions which will result in faster runtimes later on.

docs/source/tutorials/installation.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Prerequisites
1313

1414
.. note::
1515

16-
Use python version 3.9 or 3.10 .
16+
Use Python version 3.10, 3.11, 3.12, or 3.13.
1717

1818

1919
Step-by-Step Guide
@@ -50,19 +50,19 @@ Step-by-Step Guide
5050

5151
.. code-block:: bash
5252
53-
pyenv install 3.8
53+
pyenv install 3.13
5454
5555
4. Create a Virtual Environment
5656

5757
.. code-block:: bash
5858
59-
pyenv virtualenv 3.8 pyreason_venv_3.8
59+
pyenv virtualenv 3.13 pyreason_venv_3.13
6060
6161
5. Activate the Virtual Environment
6262

6363
.. code-block:: bash
6464
65-
pyenv activate pyreason_venv_3.8
65+
pyenv activate pyreason_venv_3.13
6666
6767
6. Install pyreason Using `pip`
6868

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ['setuptools>=42']
2+
requires = ['setuptools>=42', 'setuptools_scm[toml]>=8']
33
build-backend = 'setuptools.build_meta'
44

55
[tool.ruff.lint]

pyreason/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ruff: noqa: F403 F405 (Ignore Pyreason import * for public api)
22
# Set numba environment variable
33
import os
4+
import sys
45
package_path = os.path.abspath(os.path.dirname(__file__))
56
cache_path = os.path.join(package_path, 'cache')
67
cache_status_path = os.path.join(package_path, '.cache_status.yaml')
@@ -9,20 +10,21 @@
910

1011
from pyreason.pyreason import *
1112
import yaml
12-
from importlib.metadata import version
13-
from pkg_resources import get_distribution, DistributionNotFound
13+
from importlib.metadata import PackageNotFoundError, version
1414

1515
try:
16-
__version__ = get_distribution(__name__).version
17-
except DistributionNotFound:
16+
__version__ = version(__name__)
17+
except PackageNotFoundError:
1818
# package is not installed
1919
pass
2020

2121

2222
with open(cache_status_path) as file:
2323
cache_status = yaml.safe_load(file)
2424

25-
if not cache_status['initialized']:
25+
running_tests = 'pytest' in sys.modules or 'unittest' in sys.modules
26+
27+
if not cache_status['initialized'] and not running_tests:
2628
print('Imported PyReason for the first time. Initializing caches for faster runtimes ... this will take a minute')
2729
graph_path = os.path.join(package_path, 'examples', 'hello-world', 'friends_graph.graphml')
2830

@@ -37,9 +39,6 @@
3739
print('PyReason initialized!')
3840
print()
3941

40-
# Update cache status (skip under test runners to keep repo file clean)
41-
import sys
42-
if 'pytest' not in sys.modules and 'unittest' not in sys.modules:
43-
cache_status['initialized'] = True
44-
with open(cache_status_path, 'w') as file:
45-
yaml.dump(cache_status, file)
42+
cache_status['initialized'] = True
43+
with open(cache_status_path, 'w') as file:
44+
yaml.dump(cache_status, file)

pyreason/scripts/interpretation/interpretation.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,15 +1376,15 @@ def get_rule_edge_clause_grounding(clause_var_1, clause_var_2, groundings, groun
13761376
# We replace Y by the sources of Z
13771377
elif clause_var_1 not in groundings and clause_var_2 in groundings:
13781378
for n in groundings[clause_var_2]:
1379-
es = numba.typed.List([(nn, n) for nn in reverse_neighbors[n]])
1380-
edge_groundings.extend(es)
1379+
for nn in reverse_neighbors[n]:
1380+
edge_groundings.append((nn, n))
13811381

13821382
# Case 3:
13831383
# We replace Z by the neighbors of Y
13841384
elif clause_var_1 in groundings and clause_var_2 not in groundings:
13851385
for n in groundings[clause_var_1]:
1386-
es = numba.typed.List([(n, nn) for nn in neighbors[n]])
1387-
edge_groundings.extend(es)
1386+
for nn in neighbors[n]:
1387+
edge_groundings.append((n, nn))
13881388

13891389
# Case 4:
13901390
# We have seen both variables before
@@ -1396,8 +1396,9 @@ def get_rule_edge_clause_grounding(clause_var_1, clause_var_2, groundings, groun
13961396
else:
13971397
groundings_clause_var_2_set = set(groundings[clause_var_2])
13981398
for n in groundings[clause_var_1]:
1399-
es = numba.typed.List([(n, nn) for nn in neighbors[n] if nn in groundings_clause_var_2_set])
1400-
edge_groundings.extend(es)
1399+
for nn in neighbors[n]:
1400+
if nn in groundings_clause_var_2_set:
1401+
edge_groundings.append((n, nn))
14011402

14021403
return edge_groundings
14031404

pyreason/scripts/interpretation/interpretation_fp.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,15 +1496,15 @@ def get_rule_edge_clause_grounding(clause_var_1, clause_var_2, groundings, groun
14961496
# We replace Y by the sources of Z
14971497
elif clause_var_1 not in groundings and clause_var_2 in groundings:
14981498
for n in groundings[clause_var_2]:
1499-
es = numba.typed.List([(nn, n) for nn in reverse_neighbors[n]])
1500-
edge_groundings.extend(es)
1499+
for nn in reverse_neighbors[n]:
1500+
edge_groundings.append((nn, n))
15011501

15021502
# Case 3:
15031503
# We replace Z by the neighbors of Y
15041504
elif clause_var_1 in groundings and clause_var_2 not in groundings:
15051505
for n in groundings[clause_var_1]:
1506-
es = numba.typed.List([(n, nn) for nn in neighbors[n]])
1507-
edge_groundings.extend(es)
1506+
for nn in neighbors[n]:
1507+
edge_groundings.append((n, nn))
15081508

15091509
# Case 4:
15101510
# We have seen both variables before
@@ -1516,8 +1516,9 @@ def get_rule_edge_clause_grounding(clause_var_1, clause_var_2, groundings, groun
15161516
else:
15171517
groundings_clause_var_2_set = set(groundings[clause_var_2])
15181518
for n in groundings[clause_var_1]:
1519-
es = numba.typed.List([(n, nn) for nn in neighbors[n] if nn in groundings_clause_var_2_set])
1520-
edge_groundings.extend(es)
1519+
for nn in neighbors[n]:
1520+
if nn in groundings_clause_var_2_set:
1521+
edge_groundings.append((n, nn))
15211522

15221523
return edge_groundings
15231524

pyreason/scripts/interpretation/interpretation_parallel.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,15 +1376,15 @@ def get_rule_edge_clause_grounding(clause_var_1, clause_var_2, groundings, groun
13761376
# We replace Y by the sources of Z
13771377
elif clause_var_1 not in groundings and clause_var_2 in groundings:
13781378
for n in groundings[clause_var_2]:
1379-
es = numba.typed.List([(nn, n) for nn in reverse_neighbors[n]])
1380-
edge_groundings.extend(es)
1379+
for nn in reverse_neighbors[n]:
1380+
edge_groundings.append((nn, n))
13811381

13821382
# Case 3:
13831383
# We replace Z by the neighbors of Y
13841384
elif clause_var_1 in groundings and clause_var_2 not in groundings:
13851385
for n in groundings[clause_var_1]:
1386-
es = numba.typed.List([(n, nn) for nn in neighbors[n]])
1387-
edge_groundings.extend(es)
1386+
for nn in neighbors[n]:
1387+
edge_groundings.append((n, nn))
13881388

13891389
# Case 4:
13901390
# We have seen both variables before
@@ -1396,8 +1396,9 @@ def get_rule_edge_clause_grounding(clause_var_1, clause_var_2, groundings, groun
13961396
else:
13971397
groundings_clause_var_2_set = set(groundings[clause_var_2])
13981398
for n in groundings[clause_var_1]:
1399-
es = numba.typed.List([(n, nn) for nn in neighbors[n] if nn in groundings_clause_var_2_set])
1400-
edge_groundings.extend(es)
1399+
for nn in neighbors[n]:
1400+
if nn in groundings_clause_var_2_set:
1401+
edge_groundings.append((n, nn))
14011402

14021403
return edge_groundings
14031404

0 commit comments

Comments
 (0)