Skip to content
This repository was archived by the owner on Oct 9, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 11 additions & 68 deletions doc/sphinx/source/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
<https://github.com/bastienleonard/pysfml-cython/downloads>`_, 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 *);
Expand Down Expand Up @@ -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
Expand All @@ -209,40 +179,13 @@ 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
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.
31 changes: 0 additions & 31 deletions patch.py

This file was deleted.

110 changes: 41 additions & 69 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,89 +27,61 @@
# 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)]
if sys.version_info.major > 2:
cflags = ["-D", "DL_IMPORT(RTYPE)=RTYPE"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DL_IMPORT(RTYPE)=RTYPE in at least Python 2.7 and up, though it's probably better to find the version where it was removed completely and only override from there up.

else:
ext_modules = [Extension('sfml', [src('sfml.cpp'), src('hacks.cpp')],
libraries=libs)]

cflags = []

ext_modules = [Extension(
'sfml',
[src('sfml.pyx'), src('hacks.cpp')],
language='c++',
libraries=['sfml-graphics', 'sfml-window', 'sfml-audio', 'sfml-system'],
extra_compile_args=cflags
)]

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='[email protected]',
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)
setup(
name='pySFML',
ext_modules=ext_modules,
version='0.2.1',
description='A Python binding for SFML 2',
long_description=long_description,
author='Bastien Leonard',
author_email='[email protected]',
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'
],
cmdclass={
'build_ext': Cython.Distutils.build_ext
}
)
114 changes: 0 additions & 114 deletions setup3k.py

This file was deleted.