distutils

Finding a file in a Python module distribution

六月ゝ 毕业季﹏ 提交于 2019-12-17 22:57:29
问题 I've written a Python package that includes a bsddb database of pre-computed values for one of the more time-consuming computations. For simplicity, my setup script installs the database file in the same directory as the code which accesses the database (on Unix, something like /usr/lib/python2.5/site-packages/mypackage/). How do I store the final location of the database file so my code can access it? Right now, I'm using a hack based on the __file__ variable in the module which accesses the

Package only binary compiled .so files of a python library compiled with Cython

 ̄綄美尐妖づ 提交于 2019-12-17 22:52:26
问题 I have a package named mypack which inside has a module mymod.py , and the __init__.py . For some reason that is not in debate, I need to package this module compiled (nor .py or .pyc files are allowed). That is, the __init__.py is the only source file allowed in the distributed compressed file. The folder structure is: . │ ├── mypack │ ├── __init__.py │ └── mymod.py ├── setup.py I find that Cython is able to do this, by converting each .py file in a .so library that can be directly imported

Can a Python package depend on a specific version control revision of another Python package?

空扰寡人 提交于 2019-12-17 22:37:04
问题 Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in setup.py e.g requires = 'svn://example.org/useful.package/trunk@1234' ? 回答1: You need to do two things. First, require the exact version you want, e.g.: install_requires = "useful.package==1.9dev-r1234" and then include a dependency_links setting specifying where to find it: dependency_links = ["svn://example.org/useful.package/trunk

Hook to add commands to distutils build?

只谈情不闲聊 提交于 2019-12-17 18:53:33
问题 I've added a custom distutils command to a setup.py script: from distutils.command.build_py import build_py cmdclass = {} cmdclass['build_qt'] = BuildQt cmdclass['build_py'] = build_py setup(..., cmdclass=cmdclass, ...) Is there a way to make it so that when running:: python setup.py build this first calls python setup.py build_qt automatically? 回答1: You can override build : from distutils.command.build import build class my_build(build): def run(self): self.run_command("build_qt") build.run

What is the correct way to share package version with setup.py and the package?

空扰寡人 提交于 2019-12-17 17:24:23
问题 With distutils , setuptools , etc. a package version is specified in setup.py : # file: setup.py ... setup( name='foobar', version='1.0.0', # other attributes ) I would like to be able to access the same version number from within the package: >>> import foobar >>> foobar.__version__ '1.0.0' I could add __version__ = '1.0.0' to my package's __init__.py, but I would also like to include additional imports in my package to create a simplified interface to the package: # file: __init__.py from

How to build a Python C Extension so I can import it from a module

北战南征 提交于 2019-12-17 10:41:32
问题 I have a Python project with many sub-modules that I package up with distutils. I would like to build some Python extensions in C to live in some of these sub-modules but I don't understand how to get the Python extension to live in a submodule. What follows is the simplest example of what I'm looking for: Here is my Python extension c_extension.c : #include <Python.h> static PyObject * get_answer(PyObject *self, PyObject *args) { return Py_BuildValue("i", 42); } static PyMethodDef Methods[]

Don't touch my shebang

空扰寡人 提交于 2019-12-17 09:21:49
问题 One thing I hate about distutils (I guess he is the evil who does this) is that it changes the shebang line. In other words, the more rational and environment-vars decided scripture #!/usr/bin/env python gets magically converted into #!/whatever/absolute/path/is/my/python This is seen also with grok: I used grokproject in a virtualenv to start my project, but now I cannot move the development directory around anymore, because it puts absolute paths in the shebang directive. The reason why I

Don't touch my shebang

被刻印的时光 ゝ 提交于 2019-12-17 09:21:42
问题 One thing I hate about distutils (I guess he is the evil who does this) is that it changes the shebang line. In other words, the more rational and environment-vars decided scripture #!/usr/bin/env python gets magically converted into #!/whatever/absolute/path/is/my/python This is seen also with grok: I used grokproject in a virtualenv to start my project, but now I cannot move the development directory around anymore, because it puts absolute paths in the shebang directive. The reason why I

How to extend distutils with a simple post install script?

北战南征 提交于 2019-12-17 06:33:50
问题 I need to run a simple script after the modules and programs have been installed. I'm having a little trouble finding straight-forward documentation on how to do this. It looks like I need to inherit from distutils.command.install, override some methods and add this object to the setup script. The specifics are a bit hazy though and it seems like a lot of effort for such a simple hook. Does anyone know an easy way to do this? 回答1: I dug through distutils source for a day to learn enough about

Execute a Python script post install using distutils / setuptools

╄→尐↘猪︶ㄣ 提交于 2019-12-17 05:54:49
问题 I'm trying to add a post-install task to Python distutils as described in How to extend distutils with a simple post install script?. The task is supposed to execute a Python script in the installed lib directory . This script generates additional Python modules the installed package requires. My first attempt is as follows: from distutils.core import setup from distutils.command.install import install class post_install(install): def run(self): install.run(self) from subprocess import call