Skip to content

Commit

Permalink
release/0.7.2: Add separated loading of package information
Browse files Browse the repository at this point in the history
  • Loading branch information
nok committed Jan 20, 2019
1 parent a6d5e20 commit 7afa694
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7afa694

Please sign in to comment.