Skip to content

Commit

Permalink
Merge pull request marl#221 from stefansjs/python3.12
Browse files Browse the repository at this point in the history
add support for Python3.12, modernize testing for pytest 8
  • Loading branch information
bmcfee authored Jan 15, 2025
2 parents b10b362 + 9b53cee commit 58a24d5
Show file tree
Hide file tree
Showing 13 changed files with 572 additions and 480 deletions.
16 changes: 7 additions & 9 deletions jams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"""Top-level module for JAMS"""

import os
from pkg_resources import resource_filename
from importlib import resources
from itertools import chain

# Import the necessary modules
from .exceptions import *
Expand All @@ -18,14 +19,11 @@


# Populate the namespace mapping
for _ in util.find_with_extension(resource_filename(__name__, schema.NS_SCHEMA_DIR),
'json'):
schema.add_namespace(_)
for ns in chain(*map(lambda p: p.rglob('*.json'), resources.files('jams.schemata.namespaces').iterdir())):
schema.add_namespace(ns)

# Populate local namespaces

try:
for _ in util.find_with_extension(os.environ['JAMS_SCHEMA_DIR'], 'json'):
schema.add_namespace(_)
except KeyError:
pass
if 'JAMS_SCHEMA_DIR' in os.environ:
for ns in util.find_with_extension(os.environ['JAMS_SCHEMA_DIR'], 'json'):
schema.add_namespace(ns)
9 changes: 3 additions & 6 deletions jams/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import json
import os
import copy
from pkg_resources import resource_filename

import numpy as np
import jsonschema
Expand Down Expand Up @@ -231,11 +230,9 @@ def __get_dtype(typespec):

def __load_jams_schema():
'''Load the schema file from the package.'''

schema_file = os.path.join(SCHEMA_DIR, 'jams_schema.json')

jams_schema = None
with open(resource_filename(__name__, schema_file), mode='r') as fdesc:
abs_schema_dir = os.path.join(os.path.dirname(__file__), SCHEMA_DIR)
schema_file = os.path.join(abs_schema_dir, 'jams_schema.json')
with open(schema_file, mode='r') as fdesc:
jams_schema = json.load(fdesc)

if jams_schema is None:
Expand Down
2 changes: 1 addition & 1 deletion jams/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""Version info"""

short_version = '0.3'
version = '0.3.4'
version = '0.3.5a'
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
addopts = [
"-v",
"--cov-report=term-missing",
"--cov=jams",
]
testpaths = [
"tests"
]
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

18 changes: 8 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,28 @@ def load_source(modname, filename):
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Multimedia :: Sound/Audio :: Analysis",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"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",
"Programming Language :: Python :: 3.13",
],
python_requires=">=3.9",
keywords='audio music json',
license='ISC',
install_requires=[
'pandas',
'sortedcontainers>=2.0.0',
'pyrsistent<0.15; python_version=="3.4"',
'jsonschema>=3.0.0',
'numpy>=1.8.0',
'six',
'decorator',
'mir_eval>=0.5',
'mir_eval>0.7',
],
extras_require={
'display': ['matplotlib>=1.5.0'],
'tests': ['pytest < 4', 'pytest-cov'],
'tests': ['pytest ~= 8.0', 'pytest-cov', 'matplotlib>=3'],
},
scripts=['scripts/jams_to_lab.py']
)
8 changes: 4 additions & 4 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
from jams import NamespaceError


@pytest.mark.xfail(raises=NamespaceError)
def test_bad_target():

ann = jams.Annotation(namespace='tag_open')
ann.append(time=0, duration=1, value='foo', confidence=1)

jams.convert(ann, 'bad namespace')
with pytest.raises(NamespaceError):
jams.convert(ann, 'bad namespace')


@pytest.mark.parametrize('target',
['pitch_hz', 'pitch_midi', 'segment_open',
'tag_open', 'beat', 'chord'])
@pytest.mark.xfail(raises=NamespaceError)
def test_bad_sources(target):

ann = jams.Annotation(namespace='vector')
jams.convert(ann, target)
with pytest.raises(NamespaceError):
jams.convert(ann, target)


@pytest.mark.parametrize('namespace', list(jams.schema.__NAMESPACE__.keys()))
Expand Down
16 changes: 11 additions & 5 deletions tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
@pytest.mark.parametrize('namespace',
['segment_open', 'chord', 'multi_segment',
'pitch_contour', 'beat_position', 'beat',
'onset', 'note_midi', 'tag_open',
pytest.mark.xfail('tempo', raises=NamespaceError)])
'onset', 'note_midi', 'tag_open'])
@pytest.mark.parametrize('meta', [False, True])
def test_display(namespace, meta):

ann = jams.Annotation(namespace=namespace)
jams.display.display(ann, meta=meta)

@pytest.mark.parametrize('namespace', ['tempo'])
@pytest.mark.parametrize('meta', [False, True])
def test_display_exception(namespace, meta):
with pytest.raises(NamespaceError):
ann = jams.Annotation(namespace=namespace)
jams.display.display(ann, meta=meta)


def test_display_multi():

Expand Down Expand Up @@ -69,8 +75,8 @@ def test_display_labeled_events():
jams.display.display(ann)


@pytest.mark.xfail(raises=jams.ParameterError)
def test_display_multi_fail():

anns = jams.AnnotationArray()
jams.display.display_multi(anns)

with pytest.raises(jams.ParameterError):
jams.display.display_multi(anns)
Loading

0 comments on commit 58a24d5

Please sign in to comment.