Skip to content

Commit 53495da

Browse files
committed
closes #180
1 parent 80a3ff8 commit 53495da

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The `pycldf` package adheres to [Semantic Versioning](http://semver.org/spec/v2.
66
## Unreleased
77

88
- Make sure all local media files are copied with `Dataset.copy` as well.
9+
- Allow passing a description to `Dataset.add_table` and `Dataset.add_component`.
910

1011

1112
## [1.41.0] - 2025-02-15

src/pycldf/dataset.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,16 @@ def add_table(self, url: str, *cols: ColSpecType, **kw) -> csvw.Table:
567567
:param cols: Column specifications; anything accepted by :func:`pycldf.dataset.make_column`.
568568
:param kw: Recognized keywords:
569569
- `primaryKey`: specify the column(s) constituting the primary key of the table.
570+
- `description`: a description of the table.
570571
:return: The new table.
571572
"""
572573
t = self.add_component({"url": url, "tableSchema": {"columns": []}}, *cols)
573574
if 'primaryKey' in kw:
574575
t.tableSchema.primaryKey = attr.fields_dict(Schema)['primaryKey'].converter(
575576
kw.pop('primaryKey'))
577+
if kw.get('description'):
578+
t.common_props['dc:description'] = kw.pop('description')
579+
t.common_props.update(kw)
576580
return t
577581

578582
def remove_table(self, table: TableType):
@@ -600,6 +604,9 @@ def add_component(self,
600604
601605
:param component: A component specified by name or as `dict` representing the JSON \
602606
description of the component.
607+
:param kw: Recognized keywords: \
608+
- `url`: a url property for the table;\
609+
- `description`: a description of the table.
603610
"""
604611
if isinstance(component, str):
605612
component = jsonlib.load(pkg_path('components', '{0}{1}'.format(component, MD_SUFFIX)))
@@ -609,6 +616,8 @@ def add_component(self,
609616

610617
if kw.get('url'):
611618
component.url = Link(kw['url'])
619+
if kw.get('description'):
620+
component.common_props['dc:description'] = kw['description']
612621

613622
for other_table in self.tables:
614623
if other_table.url == component.url:

tests/test_dataset.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,17 @@ def test_primary_table(ds, ds_tc):
107107

108108

109109
def test_components(ds):
110-
ds.add_component('LanguageTable')
111-
ds.add_table('custom1.csv', 'id', **{'dc:conformsTo': None})
112-
ds.add_table('custom2.csv', 'id', **{'dc:conformsTo': 'http://example.org'})
110+
t = ds.add_component('LanguageTable', description='desc')
111+
assert t.common_props['dc:description'] == 'desc'
112+
t = ds.add_table('custom1.csv', 'id', **{'dc:conformsTo': None})
113+
assert 'dc:conformsTo' in t.common_props
114+
t = ds.add_table(
115+
'custom2.csv',
116+
'id',
117+
description='desc',
118+
**{'dc:conformsTo': 'http://example.org'})
119+
assert 'dc:conformsTo' in t.common_props
120+
assert t.common_props['dc:description'] == 'desc'
113121
assert len(ds.components) == 1
114122

115123

0 commit comments

Comments
 (0)