diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..6b7f694 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,7 @@ +include MANIFEST.in +include LICENSE +include README.md +include punyverse/world.json +graft punyverse/assets +include punyverse/*.c +exclude punyverse/*.pyx diff --git a/README.md b/README.md index 7fa80ae..5517035 100644 --- a/README.md +++ b/README.md @@ -3,36 +3,19 @@ punyverse Python simulator of a puny universe. (How many words can I stick into one?) -![Punyverse Preview](https://quantum2.xyz/wp-content/uploads/2017/07/punyverse.png) +![Punyverse Preview](https://guanzhong.ca/assets/projects/punyverse-c91f1cb1415c2922c5dcdf9773bc8d86e52e86e1c1b01d33a0969af7b669b8c4.png) Installation ------------ -To install, simply clone this repository, or download a copy [here](https://github.com/quantum5/punyverse/archive/master.zip). +Currently, only Python 2 on Windows is supported. -After that, download the [launcher](https://github.com/quantum5/punyverse/releases/download/launcher0.4/launcher.exe), -put it into the repository directory and let it unpack in your repository (or copy). +To install, run `pip install punyverse`. -You may start playing any time by running `punyverse.exe`, or `punyverse_debug.exe` if you desire a console. +Then, run `punyverse` to launch the simulator, or `punyversew` to launch without the console. ### A Note on Textures If your graphics card doesn't support the massive texture sizes this module comes with, you can shrink them. -You can run `small_images.exe` (or `small_images.py`, if you have python) to generate smaller versions of -shipped textures, which requires either `PIL` or `pgmagick` to process the images. - -### Advanced Install - -If you wish to use your own python installation, to run `punyverse`, you can clone the code. -Here are the things you need: - -* Python 2.7, I have no Python 2.6 install to test this. -* a C compiler to compile `_model.c` and `_glgeom.c` - * requires OpenGL headers and libraries. - * not really necessary, but it runs way faster with these. -* install `pyglet` - -After getting the dependencies done, you can now run the `punyverse` module using `python -mpunyverse`. - -See above if you run into texture issues. +To do this, run `punyverse_small_images`. diff --git a/bootloader.py b/bootloader.py deleted file mode 100644 index 7a309cd..0000000 --- a/bootloader.py +++ /dev/null @@ -1,40 +0,0 @@ -import pyglet -import json -import os -import sys -import uuid -import imp -import argparse - -def load_dll(dir, module): - name = 'punyverse.' + module - path = os.path.join(dir, 'punyverse', module + '.pyd') - if not os.path.exists(path): - path = os.path.join(dir, 'punyverse.%s.pyd' % module) - if not os.path.exists(path): - raise ImportError('No module named %s' % module) - return imp.load_dynamic(name, path) - -if __name__ == '__main__': - try: - dir = os.path.dirname(sys.executable) - if sys.frozen == 'windows_exe': - sys.stderr = open(os.path.join(dir, 'punyverse.log'), 'a') - except AttributeError: - sys.exit('This is only meant to be ran frozen.') - - sys.path.insert(0, dir) - try: - import punyverse - except ImportError: - pass - - # Model indirectly depends on _glgeom to handle textures - load_dll(dir, '_glgeom') - - # Model path needs special handling - _model = load_dll(dir, '_model') - _model.model_base = os.path.join(dir, 'punyverse', 'assets', 'models') - - with open('punyverse\__main__.py', 'r') as code: - exec(code) diff --git a/launcher.py b/launcher.py deleted file mode 100644 index 6c23e40..0000000 --- a/launcher.py +++ /dev/null @@ -1,29 +0,0 @@ -from distutils.core import setup -import py2exe -from glob import glob -import sys -import os -import shutil - -if len(sys.argv) < 2: - sys.argv.append('py2exe') - -parent = os.path.dirname(__file__) -join = os.path.join - -setup( - console=[{'dest_base': 'punyverse_debug', 'script': 'bootloader.py'}, 'small_images.py'], - windows=[{'dest_base': 'punyverse', 'script': 'bootloader.py'}], - options={'py2exe': { - 'unbuffered': True, 'optimize': 2, - 'excludes': [ - '_ssl', 'unittest', 'doctest', 'PIL', 'email', 'distutils', - 'pyglet.window.carbon', 'pyglet.window.xlib', - 'pyglet.media.drivers.alsa', - 'win32wnet', 'netbios', 'pgmagick' - ], - 'includes': ['punyverse._model', 'punyverse._glgeom'], - 'dll_excludes': ['MPR.dll', 'w9xpopen.exe'], - } - } -) diff --git a/small_images.py b/punyverse/small_images.py similarity index 88% rename from small_images.py rename to punyverse/small_images.py index ed00433..1f839ca 100644 --- a/small_images.py +++ b/punyverse/small_images.py @@ -39,20 +39,20 @@ try: def save(image, file): image.write(file) except ImportError: - import Image - + from PIL import Image + def get_image(image): return Image.open(image) - + def get_size(image): return image.size - + def scale(image, width, height): original_width, original_height = image.size if width * 3 < original_width and height * 3 < original_height: image = image.resize((width * 2, height * 2)) return image.resize((width, height), Image.ANTIALIAS) - + def save(image, file): image.save(file) @@ -97,19 +97,8 @@ textures = [ 'moons/mimas.jpg', ] -def frozen(): - import imp - return (hasattr(sys, 'frozen') or # new py2exe - hasattr(sys, 'importers') # old py2exe - or imp.is_frozen('__main__')) # tools/freeze - -def get_main_dir(): - if frozen(): - return os.path.dirname(sys.executable) - return os.path.dirname(__file__) - def main(): - punyverse = os.path.join(get_main_dir(), 'punyverse') + punyverse = os.path.dirname(__file__) try: with open(os.path.join(punyverse, 'assets', 'textures.txt')) as f: files = [i.strip() for i in f if not i.startswith('#') and i.strip()] diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..abc728a --- /dev/null +++ b/setup.py @@ -0,0 +1,83 @@ +from __future__ import print_function +import sys +import os + +from setuptools import setup, Extension + +has_pyx = os.path.exists(os.path.join(os.path.dirname(__file__), 'punyverse', '_glgeom.pyx')) + +try: + from Cython.Build import cythonize +except ImportError: + if has_pyx: + print('You need to install cython first before installing punyverse.', file=sys.stderr) + print('Run: pip install cython', file=sys.stderr) + print('Or if you do not have pip: easy_install cython', file=sys.stderr) + sys.exit(1) + cythonize = lambda x: x + + +if has_pyx: + pyx_path = lambda x: x +else: + pyx_path = lambda x: x.replace('.pyx', '.c') + + +with open(os.path.join(os.path.dirname(__file__), 'README.md')) as f: + long_description = f.read() + +setup( + name='punyverse', + version='0.1', + packages=['punyverse'], + package_data={ + 'punyverse': [ + 'world.json', + 'assets/textures.txt', + 'assets/textures/*.jpg', + 'assets/textures/*.png', + 'assets/textures/moons/*', + 'assets/models/asteroids/*', + 'assets/models/satellites/*.mtl', + 'assets/models/satellites/*.obj', + 'assets/models/satellites/*.jpg', + 'assets/models/satellites/*.png', + 'assets/models/satellites/cassini/*', + ], + }, + ext_modules=cythonize([ + Extension('punyverse._glgeom', sources=[pyx_path('punyverse/_glgeom.pyx')], libraries=['opengl32']), + Extension('punyverse._model', sources=[pyx_path('punyverse/_model.pyx')], libraries=['opengl32']), + ]), + + entry_points={ + 'console_scripts': [ + 'punyverse = punyverse.__main__:main', + 'punyverse_small_images = punyverse.small_images:main', + ], + 'gui_scripts': [ + 'punyversew = punyverse.__main__:main' + ] + + }, + install_requires=['pyglet', 'Pillow'], + + author='quantum', + author_email='quantum2048@gmail.com', + url='https://github.com/quantum5/punyverse', + description='Python simulator of a puny universe.', + long_description=long_description, + long_description_content_type='text/markdown', + keywords='universe simulator', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Win32 (MS Windows)', + 'Intended Audience :: End Users/Desktop', + 'License :: OSI Approved :: GNU General Public License v2 (GPLv2)', + 'Operating System :: Microsoft :: Windows', + 'Programming Language :: Python', + 'Topic :: Games/Entertainment :: Simulation', + 'Topic :: Multimedia :: Graphics :: 3D Rendering', + 'Topic :: Scientific/Engineering :: Visualization', + ], +)