diff --git a/.gitignore b/.gitignore index d8428bd..4ef70c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ build/ -sfml.so -sfml.cpython-32mu.so -sfml.cpython-64mu.so +dist/ +MANIFEST src/sfml.cpp src/sfml.h *~ diff --git a/MANIFEST.in b/MANIFEST.in index 1b02f7d..94df4f8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include setup.py setup3k.py patch.py README.md CHANGELOG.txt LICENSE.txt +include setup.py README.md *.txt recursive-include src *.py *.pyx *.pxd *.cpp *.hpp *.c *.h recursive-include tests *.py recursive-include examples *.py *.txt *.png *.jpg *.bmp *.sfx *.wav *.ttf diff --git a/doc/sphinx/source/building.rst b/doc/sphinx/source/building.rst index 8e1eccd..07f6a82 100644 --- a/doc/sphinx/source/building.rst +++ b/doc/sphinx/source/building.rst @@ -108,9 +108,9 @@ because it links to another C or C++ runtime. Common build options -------------------- -You can build the module with the ``setup.py`` script (or -``setup3k.py`` for Python 3). This section discusses some common -options that you may need or find useful. +You can build the module with the ``setup.py`` script. +This section discusses some common options that you may need or +find useful. ``--inplace`` means that the module will be dropped in the current directory. I find this more practical, as it makes it easier to test @@ -128,44 +128,18 @@ In the end, the command will look something like this:: python setup.py build_ext --inplace --compiler=mingw32 -.. _building_without_cython: +.. _building: -Building without Cython ------------------------ - -.. warning:: - - Github has removed the downloads feature, so I don't plan to - package source releases anymore. Windows users can use the - installers, and it should be easier for other users to build the - module now that recent versions of Cython correctly build the - module out of the box. - -If you download a source release at the `download page -`_, you -don't need to install Cython, since the release already contains the -files that Cython would generate. - -Make sure that ``USE_CYTHON`` is set to ``False`` in setup.py (or -setup3k.py, if you're building for Python 3). You can then build the -module by typing this command:: - - python setup.py build_ext - - -.. _building_with_cython: - -Building with Cython installed +Building ------------------------------ .. warning:: With older versions of Cython, the binding won't work correctly when built straight from the Git repo. If you want to build from - the source, you're encouraged to use the latest source release. See - :ref:`building_without_cython`. If you really want to build from - Git, you need to modify the generated sfml.cpp file. You need all - these declarations:: + the source, you're encouraged to use the latest source release. + If you really want to build from Git, you need to modify the + generated sfml.cpp file. You need all these declarations:: __PYX_EXTERN_C DL_EXPORT(PyObject) *wrap_time_instance(sf::Time *); __PYX_EXTERN_C DL_EXPORT(PyObject) *wrap_render_target_instance(sf::RenderTarget *); @@ -197,10 +171,6 @@ When you've done so, you can build the module by typing this command:: python setup.py build_ext -If you get an error related with ``DL_IMPORT``, refer to the end of -the :ref:`python3` section. - - .. _python3: Building a Python 3 module @@ -209,29 +179,7 @@ Building a Python 3 module It's possible to build a Python 3 module, but you may encounter a few minor problems. -First of all, on my machine, the Cython class used in ``setup3k.py`` to -automate Cython invocation is only installed for Python 2. It's -probably possible to install it for Python 3, but it's not complicated -to invoke Cython manually:: - - cython --cplus sfml.pyx - -The next step is to invoke the ``setup3k.py`` script to build the -module. Since we called Cython already, make sure that ``USE_CYTHON`` -is set to ``False`` in ``setup3k.py``, then invoke this command:: - - python3 setup3k.py build_ext - -(Note that you may have to type ``python`` instead of ``python3``; -typically, GNU/Linux systems provide this as a way to call a specific -version of the interpreter, but I'm not sure that's the case for all -of them as well as Windows.) - -(Also note that on GNU/Linux, the generated file won't be called -``sfml.so`` but something like ``sfml.cpython-32mu.so``. Apparently, -on Windows it's still ``sfml.pyd``.) - -The second problem used to be that you had to use bytes instead of +The main problem used to be that you had to use bytes instead of Unicode e.g. when passing a filename or window title to SFML. This is now gone, except possibly in methods that I forgot to fix; make sure to report the issue if you encounter such a case. When you pass a @@ -239,10 +187,5 @@ Unicode object to these methods, they now encode it in UTF-8 before passing them to SFML. You can change the encoding by setting the :attr:`default_encoding` variable at any time. -Finally, compilation may fail because the ``src/sfml.h`` file -generated by Cython uses the deprecated ``DL_IMPORT()`` macro. At the -root of the project, there is a ``patch.py`` script that will remove -the offending macros for you. The trick is that ``src/sfml.h`` will -not exist at first; the setup script will create it, then try to -compile it and fail. That's when you need to use ``patch.py``, and -build the module again. +There were also some building issues, but they are now (hopefully) +resolved. diff --git a/patch.py b/patch.py deleted file mode 100755 index f418ae8..0000000 --- a/patch.py +++ /dev/null @@ -1,31 +0,0 @@ -#! /usr/bin/env python2 -# -*- coding: utf-8 -*- - -"""This script modifies some Cython-generated files. - - Currently, it's only needed to call it when building for Python 3.""" - - -import os.path -import re - - -def patch_sf_h(): - """Remove the DL_IMPORT macros in src/sfml.h.""" - - filename = os.path.join('src', 'sfml.h') - - with open(filename, 'r') as f: - source = f.read() - - source = re.sub(r'DL_IMPORT\(([\w\s:]+)\)', r'\1', source) - - with open(filename, 'w') as f: - f.write(source) - -def main(): - patch_sf_h() - - -if __name__ == '__main__': - main() diff --git a/setup.py b/setup.py index e85fb2c..16c6120 100644 --- a/setup.py +++ b/setup.py @@ -27,89 +27,77 @@ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. - # When creating a Windows installer, drop the SFML and dependent DLLs # in the current folder and they will be included in the installer. - -# Set to False if you don't have Cython installed. The script will -# then build the extension module from the sf.cpp file, like a regular -# extension. -USE_CYTHON = True - - import glob import os.path import sys from distutils.core import setup from distutils.extension import Extension -from distutils.command.build_ext import build_ext - -if USE_CYTHON: - import Cython.Distutils +import Cython.Distutils def src(path): return os.path.join('src', path) - -print >> sys.stderr, ("\nIf the build fails, run patch.py and try again\n" - "----------------------------------------------\n") - -libs = ['sfml-graphics', 'sfml-window', 'sfml-audio', 'sfml-system'] - -if USE_CYTHON: - ext_modules = [Extension('sfml', [src('sfml.pyx'), src('hacks.cpp')], - language='c++', - libraries=libs)] -else: - ext_modules = [Extension('sfml', [src('sfml.cpp'), src('hacks.cpp')], - libraries=libs)] - -with open('README.md', 'r') as f: - long_description = f.read() - -kwargs = dict(name='pySFML', - ext_modules=ext_modules, - version='0.2.1', - description='A Python binding for SFML 2', - long_description=long_description, - author=u'Bastien Léonard', - author_email='bastien.leonard@gmail.com', - url='https://github.com/bastienleonard/pysfml-cython', - license='BSD', - data_files=[ - ('', glob.glob('*.dll')), - (os.path.join('lib', 'site-packages', 'pysfml-cython'), - ['LICENSE.txt', 'SFML-LICENSE.txt'])], - classifiers=[ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Cython', - 'Topic :: Games/Entertainment', - 'Topic :: Multimedia', - 'Topic :: Software Development :: Libraries :: Python Modules' - ]) - - -if USE_CYTHON: - kwargs.update(cmdclass={'build_ext': Cython.Distutils.build_ext}) +if sys.version_info.major > 2: + author = 'Bastien Léonard' + cflags = ["-D", "DL_IMPORT(RTYPE)=RTYPE"] else: - class CustomBuildExt(build_ext): - """This class is used to build the Windows binary releases.""" - - def build_extensions(self): - cc = self.compiler.compiler_type - - if cc == 'mingw32': - for e in self.extensions: - # e.extra_compile_args = [] - e.extra_link_args = ['-static-libgcc', '-static-libstdc++'] - - build_ext.build_extensions(self) - - kwargs.update(cmdclass={'build_ext': CustomBuildExt}) - -setup(**kwargs) + author = 'Bastien Léonard'.decode('utf-8') + cflags = [] + +setup( + name='pySFML', + version='0.2.1', + description='A Python binding for SFML 2', + long_description=open('README.md').read(), + + author=author, + author_email='bastien.leonard@gmail.com', + url='https://github.com/bastienleonard/pysfml-cython', + license='LICENSE.txt', + + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Cython', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', + 'Topic :: Games/Entertainment', + 'Topic :: Multimedia', + 'Topic :: Software Development :: Libraries :: Python Modules' + ], + + data_files=[ + ('', glob.glob('*.dll')), + (os.path.join('lib', 'site-packages', 'pysfml-cython'), + ['LICENSE.txt', 'SFML-LICENSE.txt'] + ) + ], + + ext_modules=[ + Extension( + 'sfml', + [ + src('sfml.pyx'), + src('hacks.cpp') + ], + language='c++', + libraries=[ + 'sfml-audio', + 'sfml-graphics', + 'sfml-system', + 'sfml-window' + ], + extra_compile_args=cflags + ) + ], + + cmdclass={ + 'build_ext': Cython.Distutils.build_ext + } +) diff --git a/setup3k.py b/setup3k.py deleted file mode 100644 index fc59136..0000000 --- a/setup3k.py +++ /dev/null @@ -1,114 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright 2010, 2011, 2012 Bastien Léonard. All rights reserved. - -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: - -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. - -# 2. Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. - -# THIS SOFTWARE IS PROVIDED BY BASTIEN LÉONARD ``AS IS'' AND ANY -# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BASTIEN LÉONARD OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. - - -# When creating a Windows installer, drop the SFML and dependent DLLs -# in the current folder and they will be included in the installer. - - -# Set to False if you don't have Cython installed. The script will -# then build the extension module from the sf.cpp file, like a regular -# extension. -USE_CYTHON = True - - -import glob -import os.path -import sys -from distutils.core import setup -from distutils.extension import Extension -from distutils.command.build_ext import build_ext - -if USE_CYTHON: - import Cython.Distutils - - -def src(path): - return os.path.join('src', path) - - -print("\nIf the build fails, run patch.py and try again\n" - "----------------------------------------------\n", file=sys.stderr) - -libs = ['sfml-graphics', 'sfml-window', 'sfml-audio', 'sfml-system'] - -if USE_CYTHON: - ext_modules = [Extension('sfml', [src('sfml.pyx'), src('hacks.cpp')], - language='c++', - libraries=libs)] -else: - ext_modules = [Extension('sfml', [src('sfml.cpp'), src('hacks.cpp')], - libraries=libs)] - -with open('README.md', 'r') as f: - long_description = f.read() - -kwargs = dict(name='pySFML', - ext_modules=ext_modules, - version='0.2.1', - description='A Python binding for SFML 2', - long_description=long_description, - author='Bastien Léonard', - author_email='bastien.leonard@gmail.com', - url='https://github.com/bastienleonard/pysfml-cython', - license='BSD', - data_files=[ - ('', glob.glob('*.dll')), - (os.path.join('lib', 'site-packages', 'pysfml-cython'), - ['LICENSE.txt', 'SFML-LICENSE.txt'])], - classifiers=[ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Cython', - 'Topic :: Games/Entertainment', - 'Topic :: Multimedia', - 'Topic :: Software Development :: Libraries :: Python Modules' - ]) - -if USE_CYTHON: - kwargs.update(cmdclass={'build_ext': Cython.Distutils.build_ext}) -else: - class CustomBuildExt(build_ext): - """This class is used to build the Windows binary releases.""" - - def build_extensions(self): - cc = self.compiler.compiler_type - - if cc == 'mingw32': - for e in self.extensions: - # e.extra_compile_args = [] - e.extra_link_args = ['-static-libgcc', '-static-libstdc++'] - - build_ext.build_extensions(self) - - kwargs.update(cmdclass={'build_ext': CustomBuildExt}) - -setup(**kwargs)