From 03bf5e618fbcd2fb200379b4af65c8f7bde15722 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Mon, 31 Aug 2015 02:12:07 +0000 Subject: [PATCH] Properly handle extra source files --- pirate/data.py | 10 ++++++++-- {data => pirate/data}/categories.json | 0 {data => pirate/data}/sorts.json | 0 setup.py | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) rename {data => pirate/data}/categories.json (100%) rename {data => pirate/data}/sorts.json (100%) diff --git a/pirate/data.py b/pirate/data.py index 27ca62d..73869d1 100644 --- a/pirate/data.py +++ b/pirate/data.py @@ -1,7 +1,13 @@ import json +import pkgutil -categories = json.load(open('data/categories.json')) -sorts = json.load(open('data/sorts.json')) + +def get_resource(filename): + return pkgutil.get_data(__package__, 'data/' + filename) + + +categories = json.loads(get_resource('categories.json').decode()) +sorts = json.loads(get_resource('sorts.json').decode()) default_headers = {'User-Agent': 'pirate get'} default_timeout = 10 diff --git a/data/categories.json b/pirate/data/categories.json similarity index 100% rename from data/categories.json rename to pirate/data/categories.json diff --git a/data/sorts.json b/pirate/data/sorts.json similarity index 100% rename from data/sorts.json rename to pirate/data/sorts.json diff --git a/setup.py b/setup.py index 83fbcab..fcbd94b 100755 --- a/setup.py +++ b/setup.py @@ -9,6 +9,7 @@ setup(name='pirate-get', author_email='me@viktorstanchev.com', license='GPL', packages=find_packages(), + package_data={'': ["data/*.json"]}, entry_points={ 'console_scripts': ['pirate-get = pirate.pirate:main'] },