Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

The `pycldf` package adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## unreleased

- Switch from `pybtex` to `simplepybtex`.
- Make `Dataset.add_sources` accept a `BibliographyData` object from either `pybtex` or `simplepybtex`.
- More informative error message when `Dataset.add_sources` gets the wrong type of object.

## [1.42.0] - 2025-04-07

Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ install_requires =
clldutils>=3.9
uritemplate>=3.0
python-dateutil
# pybtex requires setuptools, but doesn't seem to declare this.
setuptools
pybtex
simplepybtex
newick
commonnexus>=1.2.0
python-frontmatter
Expand Down
17 changes: 11 additions & 6 deletions src/pycldf/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from urllib.request import urlopen, urlretrieve

from csvw.metadata import is_url
from pybtex import database
from pybtex.database.output.bibtex import Writer as BaseWriter
from simplepybtex import database
from simplepybtex.database.output.bibtex import Writer as BaseWriter
from clldutils.source import Source as BaseSource
from clldutils.source import ID_PATTERN

Expand Down Expand Up @@ -58,10 +58,10 @@ def __repr__(self):
@classmethod
def from_entry(cls, key, entry, **_kw):
"""
Create a `cls` instance from a `pybtex` entry object.
Create a `cls` instance from a `simplepybtex` entry object.

:param key: BibTeX citation key of the entry
:param entry: `pybtex.database.Entry` instance
:param entry: `simplepybtex.database.Entry` instance
:param _kw: Non-bib-metadata keywords to be passed for `cls` instantiation
:return: `cls` instance
"""
Expand Down Expand Up @@ -220,10 +220,15 @@ def expand_refs(self, refs: typing.Iterable[str], **kw) -> typing.Iterable[Refer
def _add_entries(self, data, **kw):
if isinstance(data, Source):
entries = [(data.id, data.entry)]
elif isinstance(data, database.BibliographyData):
elif hasattr(data, 'entries'):
entries = data.entries.items()
else:
raise ValueError(data)
msg = (
'expected `clldutils.source.Source`,'
' `pybtex.database.BibliographyData`,'
' or `simplepybtex.database.BibliographyData`;'
f' got {type(data)}')
raise TypeError(data)

for key, entry in entries:
if kw.get('_check_id', False) and not ID_PATTERN.match(key):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from urllib.error import HTTPError

import pytest
from pybtex.database import Entry
from simplepybtex.database import Entry

from pycldf.sources import Sources, Source, Reference

Expand Down Expand Up @@ -74,7 +74,7 @@ def test_Sources(bib):
refs = ['huber2005[1-6]', 'Obrazy', 'Elegie[34]']
assert src.format_refs(*list(src.expand_refs(refs))) == refs
assert '%s' % src['huber2005'] == 'Huber, Herrmann. 2005. y.'
with pytest.raises(ValueError):
with pytest.raises(TypeError):
src.add(5)

with pytest.raises(ValueError):
Expand Down