Skip to content

Commit

Permalink
Merge pull request #12 from materials-data-facility/toolbox-dev
Browse files Browse the repository at this point in the history
Toolbox dev
  • Loading branch information
jgaff committed Mar 5, 2018
2 parents 08929f2 + c3f8112 commit 5dee5f7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Untitled*.ipynb

*.cache*
*pytest_cache*

*temp/*

Expand Down
1 change: 1 addition & 0 deletions mdf_toolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .toolbox import *
6 changes: 4 additions & 2 deletions mdf_toolbox/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def format_gmeta(data):
Arguments:
data (dict or list): The data to be formatted.
If data is a dict, it must contain:
data["mdf"]["landing_page"] (str): A URI to a web page for the entry.
data["mdf"]["mdf_id"] (str): A unique identifier.
data["mdf"]["acl"] (list of str): A list of Globus UUIDs that are allowed to view the entry.
If data is a list, it must consist of GMetaEntry documents.
Expand All @@ -541,7 +541,9 @@ def format_gmeta(data):
return {
"@datatype": "GMetaEntry",
"@version": "2016-11-09",
"subject": data["mdf"]["landing_page"],
"subject": ("https://materialsdatafacility.org/data/{}/{}"
.format(data["mdf"].get("parent_id", data["mdf"]["mdf_id"]),
data["mdf"]["mdf_id"])),
"visible_to": data["mdf"].pop("acl"),
"content": data
}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ universal=1
addopts = --ignore=setup.py --cov=mdf_toolbox

[flake8]
exclude = .git,*.egg*
exclude = .git,*.egg*,*__init__.py
max-line-length = 100
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='mdf_toolbox',
version='0.1.5',
version='0.1.6',
packages=['mdf_toolbox'],
description='Materials Data Facility Python utilities',
long_description=("Toolbox is the Materials Data Facility Python package"
Expand Down
16 changes: 8 additions & 8 deletions tests/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_format_gmeta():
md1 = {
"mdf": {
"acl": ["public"],
"landing_page": "https://example.com"
"mdf_id": "123"
}
}
# More complex GMetaEntry
Expand All @@ -158,7 +158,6 @@ def test_format_gmeta():
"acl": ["public"],
"source_name": "source name",
"citation": ["abc"],
"landing_page": "http://www.globus.org",
"data_contact": {
"given_name": "Test",
"family_name": "McTesterson",
Expand All @@ -173,7 +172,8 @@ def test_format_gmeta():
}],
"ingest_date": "Jan 1, 2017",
"metadata_version": "1.1",
"mdf_id": "1",
"mdf_id": "123",
"parent_id": "000",
"resource_type": "dataset"
},
"dc": {},
Expand All @@ -185,26 +185,25 @@ def test_format_gmeta():
assert gme1 == {
"@datatype": "GMetaEntry",
"@version": "2016-11-09",
"subject": "https://example.com",
"subject": "https://materialsdatafacility.org/data/123/123",
"visible_to": ["public"],
"content": {
"mdf": {
"landing_page": "https://example.com"
"mdf_id": "123"
}
}
}
gme2 = toolbox.format_gmeta(md2)
assert gme2 == {
"@datatype": "GMetaEntry",
"@version": "2016-11-09",
"subject": "http://www.globus.org",
"subject": "https://materialsdatafacility.org/data/000/123",
"visible_to": ["public"],
"content": {
"mdf": {
"title": "test",
"source_name": "source name",
"citation": ["abc"],
"landing_page": "http://www.globus.org",
"data_contact": {
"given_name": "Test",
"family_name": "McTesterson",
Expand All @@ -219,7 +218,8 @@ def test_format_gmeta():
}],
"ingest_date": "Jan 1, 2017",
"metadata_version": "1.1",
"mdf_id": "1",
"mdf_id": "123",
"parent_id": "000",
"resource_type": "dataset"
},
"dc": {},
Expand Down

0 comments on commit 5dee5f7

Please sign in to comment.