diff --git a/setup.py b/setup.py index 00e46a3e..f6f36e5a 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,52 @@ from setuptools import setup from setuptools import find_packages -from sklearn_porter import meta # see sklearn_porter/package.json +from os.path import abspath +from os.path import dirname +from os.path import exists +from os.path import join +from json import load + + +def _load_meta(path): + """ + Load meta data about this package from file package.json. + :param path: The path to package.json + :return: Dictionary of key value pairs. + """ + with open(path) as f: + meta = load(f, encoding='utf-8') + meta = {k: v.decode('utf-8') if isinstance(v, bytes) else v + for k, v in meta.items()} + + src_dir = abspath(dirname(path)) + + if 'requirements' in meta and \ + str(meta['requirements']).startswith('file://'): + req_path = str(meta['requirements'])[7:] + req_path = join(src_dir, req_path) + if exists(req_path): + reqs = open(req_path, 'r').read().strip().split('\n') + reqs = [req.strip() for req in reqs if 'git+' not in req] + meta['requirements'] = reqs + else: + meta['requirements'] = '' + + if 'long_description' in meta and \ + str(meta['long_description']).startswith('file://'): + readme_path = str(meta['long_description'])[7:] + readme_path = join(src_dir, readme_path) + if exists(readme_path): + readme = open(readme_path, 'r').read().strip() + meta['long_description'] = readme + else: + meta['long_description'] = '' + + return meta + + +package = join(abspath(dirname(__file__)), 'sklearn_porter', 'package.json') +meta = _load_meta(package) setup(