Skip to content

Commit 10086fa

Browse files
committed
More strictly dropping TIND date and better setup.py
1 parent a278cb9 commit 10086fa

File tree

3 files changed

+64
-30
lines changed

3 files changed

+64
-30
lines changed

caltechdata_api/decustomize_schema.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,30 @@ def decustomize_schema(json_record,pass_emails=False,pass_media=False):
129129
datetypes.add(d['dateType'])
130130
json_record['dates']=json_record.pop('relevantDates')
131131

132-
#set publicationYear
132+
#Set publicationYear and save publicationDate
133133
if 'publicationDate' in json_record:
134-
if isinstance(json_record['publicationDate'],str):
135-
year = json_record['publicationDate'].split('-')[0]
136-
json_record['publicationYear'] = year
137-
else:
138-
#Junk validation filler
139-
json_record['publicationYear'] = '0000'
140-
141-
#If "Submitted' date type was not manually set in metadata
142-
#Or 'Issued was not manually set
143-
#We want to save the entire publicationDate
144-
if 'Submitted' or 'Issued' not in datetypes:
134+
#If "Submitted' or 'Issued' date type was not manually set in metadata
135+
#the system created publicationDate is correct
136+
if 'Issued' not in datetypes and 'Submitted' not in datetypes:
145137
if 'dates' in json_record:
146138
json_record['dates'].append({"date":json_record['publicationDate'],\
147139
"dateType": "Submitted"})
148140
else:
149141
json_record['dates']=[{"date":json_record['publicationDate'],\
150142
"dateType": "Submitted"}]
143+
year = json_record['publicationDate'].split('-')[0]
144+
json_record['publicationYear'] = year
145+
#Otherwise pick 'Submitted' then 'Issued' date for publicationYear
146+
else:
147+
if 'Submitted' in datetypes:
148+
selection = 'Submitted'
149+
else:
150+
selection = 'Issued'
151+
for d in json_record['dates']:
152+
if d['dateType'] == selection:
153+
year = d['date'].split('-')[0]
154+
json_record['publicationYear'] = year
155+
151156
del json_record['publicationDate']
152157

153158
else:

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"codeRepository": "https://github.com/caltechlibrary/caltechdata_api",
77
"issueTracker": "https://github.com/caltechlibrary/caltechdata_api/issues",
88
"license": "https://data.caltech.edu/license",
9-
"version": "0.1.0",
9+
"version": "0.1.1",
1010
"author": [
1111
{
1212
"@type": "Person",

setup.py

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,50 @@
44
# Note: To use the 'upload' functionality of this file, you must:
55
# $ pip install twine
66

7-
import io
7+
import io,json
88
import os
99
import sys
1010
from shutil import rmtree
1111

1212
from setuptools import find_packages, setup, Command
1313

14-
# Package meta-data.
15-
NAME = 'caltechdata_api'
16-
DESCRIPTION = "Python wrapper for the CaltechDATA API."
17-
URL = 'https://github.com/caltechlibrary/caltechdata_api'
18-
19-
AUTHOR = 'Tom Morrell'
14+
def read(fname):
15+
with open(fname, mode = "r", encoding = "utf-8") as f:
16+
src = f.read()
17+
return src
18+
19+
codemeta_json = "codemeta.json"
20+
21+
# Let's pickup as much metadata as we need from codemeta.json
22+
with open(codemeta_json, mode = "r", encoding = "utf-8") as f:
23+
src = f.read()
24+
meta = json.loads(src)
25+
26+
# Let's make our symvar string
27+
version = meta["version"]
28+
29+
# Now we need to pull and format our author, author_email strings.
30+
author = ""
31+
author_email = ""
32+
for obj in meta["author"]:
33+
given = obj["givenName"]
34+
family = obj["familyName"]
35+
email = obj["email"]
36+
if len(author) == 0:
37+
author = given + " " + family
38+
else:
39+
author = author + ", " + given + " " + family
40+
if len(author_email) == 0:
41+
author_email = email
42+
else:
43+
author_email = author_email + ", " + email
44+
description = meta['description']
45+
url = meta['codeRepository']
46+
download = meta['downloadUrl']
47+
license = meta['license']
48+
name = meta['name']
49+
2050
REQUIRES_PYTHON = '>=3.7.0'
21-
VERSION = '0.1.0'
2251

2352
# What packages are required for this module to be executed?
2453
REQUIRED = [
@@ -43,15 +72,15 @@
4372
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
4473
long_description = '\n' + f.read()
4574
except FileNotFoundError:
46-
long_description = DESCRIPTION
75+
long_description = description
4776

4877
# Load the package's __version__.py module as a dictionary.
4978
about = {}
50-
if not VERSION:
79+
if not version:
5180
with open(os.path.join(here, NAME, '__version__.py')) as f:
5281
exec(f.read(), about)
5382
else:
54-
about['__version__'] = VERSION
83+
about['__version__'] = version
5584

5685

5786
class UploadCommand(Command):
@@ -89,15 +118,15 @@ def run(self):
89118

90119
# Where the magic happens:
91120
setup(
92-
name=NAME,
121+
name=name,
93122
version=about['__version__'],
94-
description=DESCRIPTION,
123+
description=description,
95124
long_description=long_description,
96125
long_description_content_type='text/markdown',
97-
author=AUTHOR,
98-
author_email=EMAIL,
126+
author=author,
127+
author_email=author_email,
99128
python_requires=REQUIRES_PYTHON,
100-
url=URL,
129+
url=url,
101130
packages=find_packages(exclude=('tests',)),
102131
# If your package is a single module, use this instead of 'packages':
103132
# py_modules=['mypackage'],
@@ -108,7 +137,7 @@ def run(self):
108137
install_requires=REQUIRED,
109138
extras_require=EXTRAS,
110139
include_package_data=True,
111-
license='BSD',
140+
license=license,
112141
classifiers=[
113142
# Trove classifiers
114143
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)