From: Stefano Rivera Date: Sat, 17 May 2014 12:57:13 +0000 (+0200) Subject: Generate JSON during build time. X-Git-Tag: 0.1~107 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=0b5abec00215c76d64da1dfe86b4e333899ebbaa;p=naja.git Generate JSON during build time. And install time, if it doesn't exist, for install from git. --- diff --git a/.gitignore b/.gitignore index 17e8fd0..f7f4168 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ build py2exe.log VE ve +/data/location_decks/*.json diff --git a/README.txt b/README.txt index 2247328..86ac8ef 100644 --- a/README.txt +++ b/README.txt @@ -75,10 +75,6 @@ points, you win the game, and there is much rejoicing. Development notes ----------------- -Ensure the JSON is generated from the YAML, for people with out pyyaml:: - - ./tools/gen_json.py - Creating a source distribution with:: python setup.py sdist diff --git a/debian/clean b/debian/clean index 45149aa..9c06f82 100644 --- a/debian/clean +++ b/debian/clean @@ -1 +1,2 @@ *.egg-info/* +data/location_decks/*.json diff --git a/debian/control b/debian/control index c434373..1fd0043 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,8 @@ Build-Depends: debhelper (>= 7.0.50~), dh-python, python, - python-setuptools (>= 0.6b3) + python-setuptools (>= 0.6b3), + python-yaml Standards-Version: 3.9.5 X-Python-Version: >= 2.6 Homepage: http://www.robolock-ii.org/ diff --git a/setup.py b/setup.py index ed17c86..f39ff02 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,10 @@ """Setuptools setup.py file for Robolock II.""" from setuptools import setup, find_packages +from setuptools.command.sdist import sdist +from setuptools.command.install import install + +from tools import gen_json try: import py2exe @@ -15,6 +19,19 @@ except ImportError: # This should probably be pulled from constants.py VERSION_STR = "0.1" + +class NajaSdist(sdist): + def run(self): + gen_json.main() + sdist.run(self) + + +class NajaInstall(install): + def run(self): + gen_json.main(update=False) + install.run(self) + + setup( name="robolock-II", version=VERSION_STR, @@ -65,12 +82,21 @@ setup( 'pygame', ], + setup_requires=[ + 'PyYAML', + ], + # Files packages=find_packages(), scripts=[ 'scripts/naja', ], + cmdclass={ + 'sdist': NajaSdist, + 'install': NajaInstall, + }, + # py2exe windows=[{ 'script': 'scripts/naja', diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/gen_json.py b/tools/gen_json.py index 6ae4b51..bec7ffc 100755 --- a/tools/gen_json.py +++ b/tools/gen_json.py @@ -3,10 +3,8 @@ import json import os -import yaml - -def main(): +def main(update=True): data = os.path.join(os.path.dirname(__file__), '..', 'data') deck_dir = os.path.join(data, 'location_decks') @@ -19,6 +17,10 @@ def main(): yaml_path = os.path.join(deck_dir, yaml_fn) json_path = os.path.join(deck_dir, json_fn) + if not update and os.path.exists(json_path): + continue + + import yaml with open(yaml_path) as yaml_f: obj = yaml.safe_load(yaml_f) with open(json_path, 'w') as json_f: