Python distutils, how to get a compiler that is going to be used?

This is an expanded version of Luper Rouch’s answer that worked for me to get an openmp extension to compile using both mingw and msvc on windows. After subclassing build_ext you need to pass it to setup.py in the cmdclass arg. By subclassing build_extensions instead of finalize_options you’ll have the actual compiler object to look … Read more

Speeding up build process with distutils

Try building with environment variable CC=”ccache gcc”, that will speed up build significantly when the source has not changed. (strangely, distutils uses CC also for c++ source files). Install the ccache package, of course. Since you have a single extension which is assembled from multiple compiled object files, you can monkey-patch distutils to compile those … Read more

Distribute a Python package with a compiled dynamic shared library

What I ended up doing is: setup( name=”py_my_lib”, version=version, # specified elsewhere packages=[”], package_dir={”: ‘.’}, package_data={”: [‘py_my_lib.so’]}, ) This way I get to import the lib by its name, and don’t have another level of nestedness: import py_my_lib and not from py_my_lib_wrapper import py_my_lib

What is the graft command in Python’s MANIFEST.in file?

You can see such a file in JoshData/pdfminer/MANIFEST.in or openstack/deb-python-falcon/MANIFEST.in for instance. It is a python project which uses the MANIFEST.in template A MANIFEST.in file can be added in a project to define the list of files to include in the distribution built by the sdist command. When sdist is run, it will look for … Read more

How can I run a Makefile in setup.py?

The method I normally use is to override the command in question: from distutils.command.install import install as DistutilsInstall class MyInstall(DistutilsInstall): def run(self): do_pre_install_stuff() DistutilsInstall.run(self) do_post_install_stuff() … setup(…, cmdclass={‘install’: MyInstall}, …) This took me quite a while to figure out from the distutils documentation and source, so I hope it saves you the pain. Note: you … Read more

How do I use data in package_data from source code?

The standard pkgutil module’s get_data() function will calculate the path to your data, relative to your package, and retrieve the data for you via whatever module loader Python used to import the hermes package: import pkgutil data = pkgutil.get_data(‘hermes’, ‘templates/python.tpl’) Of course in certain cases you could just read your data using a path calculated … Read more

How to extend distutils with a simple post install script?

I dug through distutils source for a day to learn enough about it to make a bunch of custom commands. It’s not pretty, but it does work. import distutils.core from distutils.command.install import install … class my_install(install): def run(self): install.run(self) # Custom stuff here # distutils.command.install actually has some nice helper methods # and interfaces. I … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)