Skip to content

Commit

Permalink
Add a command for generating dataverse data file
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarthisius committed Sep 13, 2019
1 parent 8edafd0 commit 063fd4d
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from distutils.cmd import Command
from setuptools import setup, find_packages
import sys
import versioneer
Expand All @@ -8,6 +9,35 @@
with open("README.md", encoding="utf8") as f:
readme = f.read()


class GenerateDataverseInstallationsFileCommand(Command):
description = "Generate Dataverse installations data map"
user_options = []

def initialize_options(self):
self.url = (
"https://services.dataverse.harvard.edu/miniverse/map/installations-json"
)

def finalize_options(self):
pass

def run(self):
from urllib.request import urlopen
import json

resp = urlopen(self.url, timeout=5)
resp_body = resp.read()
data = json.loads(resp_body.decode("utf-8"))
if "installations" not in data:
raise ValueError("Malformed installation map.")
with open("repo2docker/contentproviders/dataverse.json", "wb") as fp:
fp.write(resp_body)


__cmdclass = versioneer.get_cmdclass()
__cmdclass["generate_dataverse_file"] = GenerateDataverseInstallationsFileCommand

setup(
name="jupyter-repo2docker",
version=versioneer.get_version(),
Expand Down Expand Up @@ -48,7 +78,7 @@
],
packages=find_packages(),
include_package_data=True,
cmdclass=versioneer.get_cmdclass(),
cmdclass=__cmdclass,
entry_points={
"console_scripts": [
"jupyter-repo2docker = repo2docker.__main__:main",
Expand Down

0 comments on commit 063fd4d

Please sign in to comment.