File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ ...
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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 ""
Original file line number Diff line number Diff line change 22import os .path
33import pickle
44
5+ import pytest
6+
57import projspec .utils
68
79here = 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+
2027def test_contains ():
2128 from projspec .artifact .installable import Wheel
2229
You can’t perform that action at this time.
0 commit comments