Skip to content

Commit

Permalink
Merge pull request #302 from rsagroup/conda-package
Browse files Browse the repository at this point in the history
Conda packaging
  • Loading branch information
JasperVanDenBosch authored Mar 7, 2023
2 parents 2361bc5 + baf73dc commit 1d548a4
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 4 deletions.
61 changes: 61 additions & 0 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% set name = "rsatoolbox" %}
{% set version = "0.1.2" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/rsatoolbox-{{ version }}.tar.gz
sha256: fee6e0134c345f4d7e7f2d7bdde20b13724e9d0d32f89e8b22b7fc17ed21ef9a

build:
skip: true # [py<37 or py>310 or py2k]
script: {{ PYTHON }} -m pip install . -vv
number: 0

requirements:
build:
- {{ compiler('c') }}
host:
- python
- cython # >=3.0.0a11
- numpy >=1.21.2
- scipy
- setuptools
- setuptools-scm
- pip
run:
- python
- {{ pin_compatible('numpy') }}
- {{ pin_compatible('scipy') }}
- pandas
- scikit-learn
- scikit-image
- matplotlib-base
- h5py
- joblib
- tqdm
- coverage


test:
imports:
- rsatoolbox
commands:
- pip check
- python -m unittest -v rsatoolbox.test
requires:
- pip

about:
home: https://github.com/rsagroup/rsatoolbox
summary: Representational Similarity Analysis (RSA) in Python
license: MIT
license_file: LICENSE
doc_url: https://rsatoolbox.readthedocs.io/
dev_url: https://github.com/rsagroup/rsatoolbox

extra:
recipe-maintainers:
- ilogue
4 changes: 4 additions & 0 deletions .github/workflows/testbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
run: pip install .
- name: Install test dependencies
run: pip install -r tests/requirements.txt
- name: Skeleton tests
run: python -m unittest -v rsatoolbox.test
- name: Unit tests
run: pytest

Expand Down Expand Up @@ -64,6 +66,8 @@ jobs:
if: matrix.os == 'windows-latest'
- name: Install test dependencies
run: pip install -r tests/requirements.txt
- name: Skeleton tests
run: python -m unittest -v rsatoolbox.test
- name: Unit tests
run: pytest
- name: Check package compliance
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ To install the latest stable version of rsatoolbox with pip:
pip install rsatoolbox
```

or with conda:

```sh
conda install -c conda-forge rsatoolbox
```


here is a simple code sample:

Expand Down
7 changes: 7 additions & 0 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ To get the bleeding edge or "pre-release" version:
pip install --pre rsatoolbox
Or if you're using a Conda environment:

.. code-block:: sh
conda install -c conda-forge rsatoolbox
To use rsatoolbox:

.. code-block:: python
Expand Down
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
coverage
numpy>=1.21.2
scipy
scikit-learn
scikit-image
tqdm
h5py
pandas
matplotlib
h5py
tqdm
joblib
pandas
102 changes: 102 additions & 0 deletions src/rsatoolbox/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""Skeleton test module
The full collection of unit and acceptance tests for rsatoolbox is kept
in a separate package that is not part of our distributables. It can be run
by checking out the rsatoolbox git repository.
The tests in this module are a limited number of basic so-called skeleton
tests, which check that the library and all its dependencies are installed
correctly. It is not exhaustive and assumes that unittests have passed
for other most package formats.
If rsatoolbox is installed, the tests can be run with:
`python -m unittest rsatoolbox.test`
These tests have to:
- not have any dependencies outside of direct rsatoolbox runtime dependencies
- be fast (a few seconds)
- test interfaces that depend on external packages
- test compiled code
In other words they have to check that all the moving parts are there,
without looking at very specific calculation outcomes.
"""
# pylint: disable=import-outside-toplevel
from unittest import TestCase


class SkeletonTests(TestCase):
"""Toolbox skeleton tests to ensure correct packaging and installation
"""

def setUp(self):
"""Create basic RDMs and Dataset objects for all tests
"""
from numpy import asarray, ones
from numpy.testing import assert_almost_equal
from rsatoolbox.data.dataset import Dataset
from rsatoolbox.rdm.rdms import RDMs
self.data = Dataset(asarray([[0, 0], [1, 1], [2.0, 2.0]]))
self.rdms = RDMs(asarray([[1.0, 2, 3], [3, 4, 5]]))
self.larger_rdms = RDMs(ones([3, 10]))
self.array = asarray
self.arrayAlmostEqual = assert_almost_equal

def test_calc_compiled(self):
"""Covers similarity calculation with compiled code
"""
from rsatoolbox.rdm.calc_unbalanced import calc_rdm_unbalanced
rdms = calc_rdm_unbalanced(self.data)
self.arrayAlmostEqual(rdms.dissimilarities, self.array([[1, 4, 1]]))

def test_model_fit(self):
"""Covers model fitting with scipy
"""
from rsatoolbox.model.model import ModelWeighted
from rsatoolbox.model.fitter import fit_optimize
theta = fit_optimize(ModelWeighted('F', self.rdms), self.rdms)
self.arrayAlmostEqual(theta, [0.88, 0.47], decimal=2)

def test_plotting_with_mpl(self):
"""Covers Matplotlib usage
"""
from rsatoolbox.vis.rdm_plot import show_rdm
show_rdm(self.rdms)

def test_mds(self):
"""Covers sklearn and Matplotlib usage
"""
from rsatoolbox.vis.scatter_plot import show_MDS
show_MDS(self.rdms)

def test_evaluate(self):
"""Covers tqdm usage and evaluate functionality
"""
from rsatoolbox.inference import eval_fixed
from rsatoolbox.model import ModelFixed
model = ModelFixed('G', self.array(list(range(10))))
result = eval_fixed(model, self.larger_rdms)
self.assertAlmostEqual(result.test_zero()[0], 0)

def test_pandas_io(self):
"""Covers pandas usage
"""
df = self.rdms.to_df()
self.arrayAlmostEqual(
self.array(df.loc[:, 'dissimilarity'].values),
self.rdms.dissimilarities.ravel()
)

def test_hdf_io(self):
"""Covers h5py library use
"""
from io import BytesIO
from rsatoolbox.rdm.rdms import load_rdm
fhandle = BytesIO()
self.rdms.save(fhandle, file_type='hdf5')
reconstituted_rdms = load_rdm(fhandle, file_type='hdf5')
self.arrayAlmostEqual(
self.rdms.dissimilarities,
reconstituted_rdms.dissimilarities
)

0 comments on commit 1d548a4

Please sign in to comment.