Skip to content

Commit 9798a9e

Browse files
authored
Merge pull request #13 from martindurant/data-stubs
Add data stubs
2 parents e981aad + 848f89d commit 9798a9e

5 files changed

Lines changed: 46 additions & 6 deletions

File tree

src/projspec/content/data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Contents specifying datasets"""
2+
3+
from projspec.content import BaseContent
4+
5+
6+
class FrictionlessData(BaseContent):
7+
# typically in a datapackage.json spec
8+
...
9+
10+
11+
class IntakeCatalog(BaseContent):
12+
# typically in a catalog.yaml free-floating file
13+
...

src/projspec/proj/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ def _repr_html_(self):
202202
def from_dict(dic):
203203
from projspec.utils import from_dict
204204

205+
if not dic.get("klass", "") == "project":
206+
raise ValueError("Not a project dict")
205207
proj = object.__new__(Project)
206208
proj.specs = from_dict(dic["specs"], proj)
207209
proj.children = from_dict(dic["children"], proj)

src/projspec/proj/datapackage.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from projspec.proj import ProjectSpec
2+
3+
4+
class DataPackage(ProjectSpec):
5+
# by frictionless data
6+
7+
spec_doc = "https://datapackage.org/standard/data-package/#structure"
8+
# e.g., as exported by zenodo
9+
# only tabular data; docs suggest csv, xls, json filetypes; JSON
10+
# can be inline in the metadata. sqlite and yaml are also mentioned.
11+
12+
def match(self) -> bool:
13+
return "datapackage.json" in self.proj.basenames
14+
15+
# pythonic API
16+
# https://framework.frictionlessdata.io/docs/framework/actions.html

src/projspec/proj/uv.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,18 @@ def parse(self):
154154
if lock:
155155
pkg = [f"python {lock['requires-python']}"]
156156
# TODO: check for source= packages as opposed to pip wheel installs
157-
pkg.extend(
158-
[
159-
f"{_['name']} =={_.get('version', '')}"
160-
for _ in lock["package"]
161-
]
162-
)
157+
pkg.extend([f"{_['name']}{_vers(_)}" for _ in lock["package"]])
163158
self.contents.environment["lockfile"] = Environment(
164159
proj=self.proj,
165160
stack=Stack.PIP,
166161
precision=Precision.LOCK,
167162
packages=pkg,
168163
artifacts={self._artifacts["virtual_env"]["default"]},
169164
)
165+
166+
167+
def _vers(s: dict) -> str:
168+
# TODO: this may be useful elsewhere
169+
if s.get("version"):
170+
return f" =={s.get('version')}"
171+
return ""

tests/test_basic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os.path
33
import pickle
44

5+
import pytest
6+
57
import projspec.utils
68

79
here = os.path.dirname(__file__)
@@ -17,6 +19,11 @@ def test_basic():
1719
proj._repr_html_()
1820

1921

22+
def test_errors():
23+
with pytest.raises(ValueError):
24+
projspec.Project.from_dict({})
25+
26+
2027
def test_contains():
2128
from projspec.artifact.installable import Wheel
2229

0 commit comments

Comments
 (0)