-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
107 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.16 | ||
0.0.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
from itertools import islice | ||
from datapackage import Resource | ||
from ..helpers.resource_matcher import ResourceMatcher | ||
from .. import DataStreamProcessor, schema_validator | ||
|
||
|
||
class set_type(DataStreamProcessor): | ||
|
||
def __init__(self, name, **options): | ||
def __init__(self, name, resources=-1, **options): | ||
super(set_type, self).__init__() | ||
self.name = name | ||
self.options = options | ||
self.resource = None | ||
self.resource_count = None | ||
self.resources = resources | ||
|
||
def process_resources(self, resources): | ||
resources = super(set_type, self).process_resources(resources) | ||
yield from islice(resources, self.resource_count - 1) | ||
yield schema_validator(self.resource, next(resources)) | ||
for res in resources: | ||
if self.matcher.match(res.res.name): | ||
yield schema_validator(res.res, res) | ||
else: | ||
yield res | ||
|
||
def process_datapackage(self, dp): | ||
dp = super(set_type, self).process_datapackage(dp) | ||
self.matcher = ResourceMatcher(self.resources, dp) | ||
added = False | ||
for field in dp.descriptor['resources'][-1]['schema']['fields']: | ||
if field['name'] == self.name: | ||
field.update(self.options) | ||
added = True | ||
break | ||
self.resource = Resource(dp.descriptor['resources'][-1]) | ||
self.resource_count = len(dp.descriptor['resources']) | ||
for res in dp.descriptor['resources']: | ||
if self.matcher.match(res['name']): | ||
for field in res['schema']['fields']: | ||
if field['name'] == self.name: | ||
field.update(self.options) | ||
added = True | ||
break | ||
assert added, 'Failed to find field {} in schema'.format(self.name) | ||
return dp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters