Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4 error at creating a dataset from url #7

Merged
merged 5 commits into from
Apr 20, 2023
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
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">
<img src="https://github.com/gdcc/easyDataverse/blob/main/static/logo.png" width=300 alt="EasyDataverse"></br>
<img src="https://img.shields.io/badge/EasyDataverse-0.3.9-blue" alt="v0.3.6">
<img src="https://img.shields.io/badge/EasyDataverse-0.3.10-blue" alt="v0.3.6">
<img src="https://github.com/gdcc/easyDataverse/actions/workflows/build.yaml/badge.svg" alt="Build Badge">
</a>
</h1>
Expand Down
2 changes: 1 addition & 1 deletion easyDataverse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from easyDataverse.core import Dataset
from easyDataverse.tools import ProgrammingLanguage

__version__ = "0.3.9"
__version__ = "0.3.10"
5 changes: 1 addition & 4 deletions easyDataverse/tools/codegen/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ def camel_to_snake(name):


def spaced_to_snake(name) -> str:

# Clean the title
name = re.sub(r"-|\?", "", name)
name = re.sub(r"-|\?", "_", name)
name = name.replace(r"/", " ")

return "_".join([word.lower() for word in name.replace("-", " ").split(" ")])
Expand Down Expand Up @@ -67,9 +66,7 @@ def generate_JSON_schema(
parents = set(fields.parent)

for parent in parents:

if str(parent) == "nan":

# Process any primitive field to JSON
primitives = fields[
(fields["parent"].isna()) & (fields["fieldType"] != "none")
Expand Down
12 changes: 9 additions & 3 deletions easyDataverse/tools/downloader/nolibutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _create_compound_class(field, lookup):
cls.__name__ = cls_name

# Create a new type from this
return name, description, cls
return _clean_name(name), description, cls


def _parse_compound_fields(data: List, lookup):
Expand All @@ -200,11 +200,18 @@ def _parse_compound_fields(data: List, lookup):
for member in data:
for primitive in member.values():
name, field = _parse_primitive(primitive, lookup)

parsed_fields[name] = field

return parsed_fields


def _clean_name(name):
"""Removes anything that is not a valid variable name"""

return re.sub(r"\-|\?|\(|\)|\[|\]|\.\\|\/", "_", name)


def _parse_primitive(data: Dict, lookup: Dict):
"""Parses a primitive field. Returns name and field definition"""

Expand All @@ -218,7 +225,7 @@ def _parse_primitive(data: Dict, lookup: Dict):

data["description"] = lookup[data["typeName"]]["description"]

return name, _create_primitive_field(lookup=lookup, **data)
return (_clean_name(name), _create_primitive_field(lookup=lookup, **data))


def _create_primitive_field(lookup: Dict, **kwargs):
Expand Down Expand Up @@ -288,7 +295,6 @@ def populate_block_values(block_cls: DataverseBase, block_json: Dict):
attr_name = _find_attribute(block_cls, field["typeName"])

if field_type == "compound":

for entry in field["value"]:
sub_class = _get_sub_class(block_cls, attr_name)
kwargs = {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import setuptools
from setuptools import setup

__VERSION__ = "0.3.9"
__VERSION__ = "0.3.10"

setup(
name="easyDataverse",
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/blocks/testblock.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ b ToyDataset Toy Dataset
#datasetField name title description watermark fieldType displayOrder displayFormat advancedSearchField allowControlledVocabulary allowmultiples facetable displayoncreate required parent metadatablock_id termURI
fooField foo Some primitive field text 0 #VALUE TRUE FALSE FALSE TRUE TRUE FALSE ToyDataset
fooCompound compound Some compound field none 1 #VALUE TRUE FALSE FALSE TRUE FALSE FALSE ToyDataset
fooEnum some_enum Some enum field text 2 #VALUE TRUE TRUE FALSE TRUE FALSE FALSE ToyDataset
fooEnum some-enum Some enum field text 2 #VALUE TRUE TRUE FALSE TRUE FALSE FALSE ToyDataset
fooCompoundField bar Another primitive field text 3 #VALUE FALSE FALSE FALSE FALSE FALSE FALSE fooCompound ToyDataset
#controlledVocabulary DatasetField Value identifier displayOrder
fooEnum enum 0 0