Generate JSON during build time.
authorStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 12:57:13 +0000 (14:57 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 13:02:33 +0000 (15:02 +0200)
And install time, if it doesn't exist, for install from git.

.gitignore
README.txt
debian/clean
debian/control
setup.py
tools/__init__.py [new file with mode: 0644]
tools/gen_json.py

index 17e8fd0ccbb0b1cb691e4ff75ddddd986bcbfcf0..f7f4168673fee9ab2d64b1486f95141ac1b005fd 100644 (file)
@@ -11,3 +11,4 @@ build
 py2exe.log
 VE
 ve
+/data/location_decks/*.json
index 22473282e8aaa42ed323cf922c21a073366f7001..86ac8ef0147ba3d64df58037f1b549aa0d6bed2a 100644 (file)
@@ -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
index 45149aa16d69b0be4353ab5cb3cb9ccb809adab0..9c06f82f2bf32eae102e8c797b9f807a3e5c2100 100644 (file)
@@ -1 +1,2 @@
 *.egg-info/*
+data/location_decks/*.json
index c434373d4e210d70d03f8f10eab5647d20257cc5..1fd00432e038ee950400e801fcb1b44c239ac9d8 100644 (file)
@@ -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/
index ed17c8664a7c7a286e0f713d236170f4c8b8355b..f39ff02542efe5d89ebfbb3b2f7eccc7c9a0940e 100644 (file)
--- 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 (file)
index 0000000..e69de29
index 6ae4b514c3302f29d4dddedc728153b355954193..bec7ffc2b1228627e02912ad8b00cdb3cb153ee2 100755 (executable)
@@ -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: