Skip to content

Commit

Permalink
fixes python version 3.12 (#250)
Browse files Browse the repository at this point in the history
* fixes #249
* fixes upper boundary for the python version and makes all dependencies open to new versions
* fixes github action for testing and configuring poetry
* add setuptools as dependencies as this mitigates the missing distutils package in python 3.12
* restricts Jinja2 version to non-vulnarable one
* change minimal python version to 3.9
* fixes doctest outputs to be compliant to improved xarray output
* small fix to README.rst
* make codecov working again
  • Loading branch information
derNarr authored Apr 25, 2024
1 parent d8b4647 commit 60b1d6b
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and upload releases
name: Build and upload releases (sdist only)

on:
release:
Expand All @@ -10,21 +10,21 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.11']
python-version: ['3.12']
# os: [ubuntu-latest, macOS-latest, windows-latest]
# python-version: ['3.8', '3.9', '3.10', '3.11']
poetry-version: [1.6]
poetry-version: ['1.8']
fail-fast: false
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run image
uses: abatilo/actions-poetry@v2.1.3
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install package
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/python-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
poetry-version: [1.2]
python-version: ['3.9', '3.10', '3.11', '3.12']
poetry-version: ['1.8']
fail-fast: false
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run image
uses: abatilo/actions-poetry@v2.1.3
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Configure test PyPI
Expand Down
41 changes: 11 additions & 30 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,27 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: ['3.8', '3.11']
poetry-version: [1.1.13]
python-version: ['3.9', '3.12']
poetry-version: ["1.8"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
id: full-python-version
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
- name: Display Python version
run: python -c "import sys; print('-'.join(str(v) for v in sys.version_info))"

- name: Setup poetry
uses: abatilo/actions-poetry@v2.1.3
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Update PATH
if: ${{ runner.os != 'Windows' }}
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Update Path for Windows
if: ${{ runner.os == 'Windows' }}
run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH

- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-cache-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
- name: Install dependencies and pyndl
run: poetry install

- name: Run linux tests
Expand All @@ -62,11 +43,11 @@ jobs:

- name: Run tests on other distributions (skip linux-only tests)
if: ${{ runner.os != 'Linux' }}
run: poetry run pytest --no-linux
run: poetry run pytest --no-linux --cov=pyndl --cov-report=xml --disable-pytest-warnings

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
token: ${{ secrets.CODECOV_TOKEN }}
env_vars: OS,PYTHON
3 changes: 0 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ Pyndl - Naive Discriminative Learning in Python
.. image:: https://codecov.io/gh/quantling/pyndl/branch/main/graph/badge.svg?token=2GWUXRA9PD
:target: https://codecov.io/gh/quantling/pyndl

.. image:: https://img.shields.io/lgtm/grade/python/g/quantling/pyndl.svg?logo=lgtm&logoWidth=18
:target: https://lgtm.com/projects/g/quantling/pyndl/context:python

.. image:: https://img.shields.io/pypi/pyversions/pyndl.svg
:target: https://pypi.python.org/pypi/pyndl/

Expand Down
40 changes: 20 additions & 20 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Let's start:
>>> weights = ndl.ndl(events='docs/data/lexample.tab.gz', alpha=0.1,
... betas=(0.1, 0.1), method='threading')
>>> weights # doctest: +ELLIPSIS
<xarray.DataArray (outcomes: 8, cues: 15)>
<xarray.DataArray (outcomes: 8, cues: 15)>...
...
``weights`` is an ``xarray.DataArray`` of dimension ``len(outcomes)``,
Expand All @@ -139,21 +139,21 @@ methods
.. code-block:: python
>>> weights[1, 5] # doctest: +ELLIPSIS
<xarray.DataArray ()>
<xarray.DataArray ()>...
...
>>> weights.loc[{'outcomes': 'plural', 'cues': 's#'}] # doctest: +ELLIPSIS
<xarray.DataArray ()>
<xarray.DataArray ()>...
array(0.076988...)
Coordinates:
outcomes <U6 'plural'
cues <U2 's#'
outcomes <U6 ... 'plural'
cues <U2 ... 's#'
...
>>> weights.loc['plural'].loc['s#'] # doctest: +ELLIPSIS
<xarray.DataArray ()>
<xarray.DataArray ()>...
array(0.076988...)
Coordinates:
outcomes <U6 'plural'
cues <U2 's#'
outcomes <U6 ... 'plural'
cues <U2 ... 's#'
...
return the weight of the cue 's#' (the unigram 's' being the word-final) for
Expand All @@ -168,13 +168,13 @@ weight matrix by specifying the ``weight`` argument:
>>> weights2 = ndl.ndl(events='docs/data/lexample.tab.gz', alpha=0.1,
... betas=(0.1, 0.1), method='threading', weights=weights)
>>> weights2 # doctest: +ELLIPSIS
<xarray.DataArray (outcomes: 8, cues: 15)>
<xarray.DataArray (outcomes: 8, cues: 15)>...
array([[ 0.24...
...
...]])
Coordinates:
* outcomes (outcomes) <U6 'hand' 'plural'...
* cues (cues) <U2 '#h' 'ha' 'an' 'nd'...
* outcomes (outcomes) <U6 ... 'hand' 'plural'...
* cues (cues) <U2 ... '#h' 'ha' 'an' 'nd'...
Attributes:...
date:...
event_path:...
Expand Down Expand Up @@ -235,7 +235,7 @@ If you prefer to get a ``xarray.DataArray`` returned you can set the flag ``make
... alphas=alphas_cues, betas=(0.1, 0.1),
... make_data_array=True)
>>> weights # doctest: +ELLIPSIS
<xarray.DataArray (outcomes: 8, cues: 15)>
<xarray.DataArray (outcomes: 8, cues: 15)>...
...
Expand Down Expand Up @@ -449,27 +449,27 @@ gets apparent.
... 'cue_vector_dimensions': ['dim1', 'dim2', 'dim3']}]
>>> weights_ndl = weights_ndl.loc[{'outcomes': ['A', 'B', 'C', 'D'], 'cues': ['a', 'b', 'c']}]
>>> print(weights_wh) # doctest: +ELLIPSIS
<xarray.DataArray (outcome_vector_dimensions: 4, cue_vector_dimensions: 3)>
<xarray.DataArray (outcome_vector_dimensions: 4, cue_vector_dimensions: 3)>...
array([[0.06706..., 0. , 0. ],
[0. , 0.03940..., 0. ],
[0.0094... , 0. , 0.03940...],
[0.01 , 0. , 0. ]])
Coordinates:
* outcome_vector_dimensions (outcome_vector_dimensions) <U4 'dim1' ... 'dim4'
* cue_vector_dimensions (cue_vector_dimensions) <U4 'dim1' 'dim2' 'dim3'
outcomes <U1 'A'
cues <U1 'a'
* outcome_vector_dimensions (outcome_vector_dimensions) <U4 ... 'dim1' ...
* cue_vector_dimensions (cue_vector_dimensions) <U4 ... 'dim1' ...
outcomes <U1 ... 'A'
cues <U1 ... 'a'
Attributes: (12/15)
...
>>> print(weights_ndl) # doctest: +ELLIPSIS
<xarray.DataArray (outcomes: 4, cues: 3)>
<xarray.DataArray (outcomes: 4, cues: 3)>...
array([[0.06706..., 0. , 0. ],
[0. , 0.03940..., 0. ],
[0.0094... , 0. , 0.03940...],
[0.01 , 0. , 0. ]])
Coordinates:
* outcomes (outcomes) <U1 'A' 'B' 'C' 'D'
* cues (cues) <U1 'a' 'b' 'c'
* outcomes (outcomes) <U1 ... 'A' 'B' 'C' 'D'
* cues (cues) <U1 ... 'a' 'b' 'c'
Attributes: (12/17)
...
Expand Down
46 changes: 24 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyndl"
version = "1.2.2"
version = "1.2.3"
description = "Naive discriminative learning implements learning and classification models based on the Rescorla-Wagner equations."

license = "MIT"
Expand Down Expand Up @@ -28,29 +28,31 @@ classifiers = ['Development Status :: 5 - Production/Stable',
'Topic :: Scientific/Engineering :: Information Analysis',]

[tool.poetry.dependencies]
python = ">=3.8,<3.12" # Compatible python versions must be declared here
numpy = "^1.23.1"
scipy = "^1.9.0"
pandas = "^1.4.3"
xarray = "^2022.6.0"
netCDF4 = "^1.6.0"
Cython = "^3.0.0"
python = ">=3.9,<3.13" # Compatible python versions must be declared here
numpy = ">=1.24.1"
scipy = ">=1.13.0"
pandas = ">=1.4.3"
xarray = ">=2022.6.0"
netCDF4 = ">=1.6.0"
Cython = ">=3.0.0"
toml = ">=0.10.2"
setuptools = ">=69.2.0"

[tool.poetry.dev-dependencies]
pytest = "^7.0"
pytest-cov = "^2.4"
pydocstyle = "^6.1.1"
flake8 = "^4.0.1"
sphinx = "^1.4"
sphinx_rtd_theme = "^1.0.0"
notebook = "^6.4.10"
seaborn = "^0.12.1"
numpydoc = "^1.2"
sphinx-copybutton = "^0.5.1"
pylint = "^2.0.0"
nbsphinx = "^0.8.8"
vulture = "^2.3"
Jinja2 = "<3.1.0"
pytest = ">=7.0"
pytest-cov = ">=2.4"
pydocstyle = ">=6.1.1"
flake8 = ">=4.0.1"
sphinx = ">=1.4"
sphinx_rtd_theme = ">=1.0.0"
notebook = ">=6.4.10"
seaborn = ">=0.12.1"
numpydoc = ">=1.2"
sphinx-copybutton = ">=0.5.1"
pylint = ">=2.0.0"
nbsphinx = ">=0.8.8"
vulture = ">=2.3"
Jinja2 = ">=3.1.3"

[tool.pytest.ini_options]
addopts = '--doctest-glob "*.rst"'
Expand Down

0 comments on commit 60b1d6b

Please sign in to comment.