473,545 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Distutils

Hi!

I just started playing around with Distutils and there is one thing I
could use some help with. I'm wondering if there is some convenient way
to access the directories where the data_files was installed?

--
Johan Svedberg, jo***@svedberg. pp.se, http://johan.svedberg.pp.se/
Jul 18 '05 #1
8 1728
On Qui 13 Mai 2004 13:14, Johan Svedberg wrote:
I just started playing around with Distutils and there is one thing I
could use some help with. I'm wondering if there is some convenient way
to access the directories where the data_files was installed?


Could you explain when and why you are trying to do that?

--
Godoy. <go***@ieee.org >
Jul 18 '05 #2
* Jorge Godoy <go***@ieee.org >:
On Qui 13 Mai 2004 13:14, Johan Svedberg wrote:
I just started playing around with Distutils and there is one thing I
could use some help with. I'm wondering if there is some convenient
way to access the directories where the data_files was installed?


Could you explain when and why you are trying to do that?


Well, the reason is that I've told setup.py to install a bunch of
templates in <prefix>/share/myapp/templates/ and I want to make sure
that myapp can find these no matter what <prefix> is.

--
Johan Svedberg, jo***@svedberg. pp.se, http://johan.svedberg.pp.se/
Jul 18 '05 #3
At some point, Johan Svedberg <jo***@svedberg .pp.se> wrote:
Hi!

I just started playing around with Distutils and there is one thing I
could use some help with. I'm wondering if there is some convenient way
to access the directories where the data_files was installed?


If you're using the data_files argument to setup(), it's behaviour is
described in the manual. Basically, if the specified directory is
absolute, the files go there. Otherwise, the directory is relative to
sys.prefix (or sys.exec_prefix if extension modules are installed).

For example (from the documentation):

### setup.py
setup(...
py_modules = ['mod'],
data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
('config', ['cfg/data.cfg']),
('/etc/init.d', ['init-script'])]
)
###

I'll assume sys.prefix is '/usr'.

b1.gif and b2.gif will installed by default /usr/bitmaps',
and data.cfg in /usr/config. init-script will be installed in /etc/init.d.

Now, there's a difficulty. If I run the setup.py script like this:

$ python setup.py install --prefix=/usr/local

then b1.gif, for instance, gets installed in /usr/local/bitmaps. So
you can't hard-code /usr/bitmaps as the path to look at in your
application. One thing you can do is use the __file__ variable that's
defined in a module to find out where that module is installed, and
work your way up.

With the above call to setup.py, the module 'mod.py' would be
installed in /usr/local/lib/python2.3/site-packages, and within
mod.py, __file__ would be
'/usr/local/lib/python2.3/site-packages/mod.pyc', so you could walk
the tree up.

However, there's more problems. I install somethings in my home
directory like this:

$ python setup.py install --home=~/usr

Now mod.__file__ is '/home/cookedm/usr/lib/python/mod.pyc'. Things can
get more complicated if the --install-lib option is used.

Ugh.

One solution that I've seen used several times is to install data
files in the package directory:

### setup.py
from distutils.core import setup
from distutils.comma nd.install_data import install_data

class my_install_data (install_data):
def finalize_option s(self):
self.set_undefi ned_options('in stall',
('install_lib', 'install_dir'))
install_data.fi nalize_options( self)

setup(...
packages = ['mypackage', 'mypackage.data '],
data_files=[('mypackage/data', ['bm/b1.gif', 'bm/b2.gif'])],
cmdclass = { 'install_data' : my_install_data }
)
###

b1.gif and b2.gif will now be installed in the same directory as the
modules in mypackage.data. A file mypackage.data. __init.py can look
like this:

### mypackage.data. __init__
import os.path
def data_dir():
mod_loc = os.path.dirname (__file__)
return os.path.abspath (mod_loc)
###

Then in your main code,

### mypackage.do_st uff_module
import mypackage.data
....
data_dir = mypackage.data. data_dir()
b1gif = open(os.path.jo in(data_dir, 'b1.gif'))
###

Hope this helps.

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)phy sics(dot)mcmast er(dot)ca
Jul 18 '05 #4
* David M. Cooke <co**********@p hysics.mcmaster .ca>:

[...]
Hope this helps.


It does! This was the exact problems I thought of myself! A huuuge
thanks for taking the time to break this down for me!

Regards,

--
Johan Svedberg, jo***@svedberg. pp.se, http://johan.svedberg.pp.se/
Jul 18 '05 #5
On Qui 13 Mai 2004 15:39, Johan Svedberg wrote:
Well, the reason is that I've told setup.py to install a bunch of
templates in <prefix>/share/myapp/templates/ and I want to make sure
that myapp can find these no matter what <prefix> is.


I see somebody suggested that you use __file__, from the module.

Another option --- I'm using it --- is to have a config file and have
distutils to call a postinstall script (requires Python 2.3+) to update the
directory in such a config file.

You can parse it with ConfigParser in your application. It also adds an
interesting way of putting things in different places and still having them
to work as expected :-)

--
Godoy. <go***@ieee.org >
Jul 18 '05 #6
At some point, Jorge Godoy <go***@ieee.org > wrote:
On Qui 13 Mai 2004 15:39, Johan Svedberg wrote:
Well, the reason is that I've told setup.py to install a bunch of
templates in <prefix>/share/myapp/templates/ and I want to make sure
that myapp can find these no matter what <prefix> is.


I see somebody suggested that you use __file__, from the module.

Another option --- I'm using it --- is to have a config file and have
distutils to call a postinstall script (requires Python 2.3+) to update the
directory in such a config file.


Of course, you have to able to find the config file, but that's a
smaller kettle of fish. I suppose you could put the config file in
your modules directory (like I suggested), and have your other data
files sitting outside (in /usr/share/whatever).

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)phy sics(dot)mcmast er(dot)ca
Jul 18 '05 #7
On Qui 13 Mai 2004 17:51, David M. Cooke wrote:
Of course, you have to able to find the config file, but that's a
smaller kettle of fish. I suppose you could put the config file in
your modules directory (like I suggested), and have your other data
files sitting outside (in /usr/share/whatever).


If all your concerns are with unix machines, taht would be great. I don't
know if his software should also run on other platforms and OSs. Anyway,
you have basically two points, for Unix and Windows: /etc/something/config
and c:\Windows\some thing\config. You can check the OS and go to the correct
directory... It makes it harder to find only one file: the config file. The
other way you'd have to check all the other files...

--
Godoy. <go***@ieee.org >
Jul 18 '05 #8
* Johan Svedberg <jo***@svedberg .pp.se>:
* Jorge Godoy <go***@ieee.org >:
On Qui 13 Mai 2004 13:14, Johan Svedberg wrote:
I just started playing around with Distutils and there is one thing
I could use some help with. I'm wondering if there is some
convenient way to access the directories where the data_files was
installed?


Could you explain when and why you are trying to do that?


Well, the reason is that I've told setup.py to install a bunch of
templates in <prefix>/share/myapp/templates/ and I want to make sure
that myapp can find these no matter what <prefix> is.


When I think more about it, the cleanest way would probably be if I
could in some way patch the relevant files so that they point to the
right location. This would ofcourse have to be done after the user has
decided where he wants to install things. Very much like the way
configure and make works together.

I'm going to look around more to see if I can find any good solution by
looking at other peoples projects. I find it really strange that there
isn't some generic way of doing this since application installment is a
pretty central part.

--
Johan Svedberg, jo***@svedberg. pp.se, http://johan.svedberg.pp.se/
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1953
by: Isaac Jones | last post by:
Hello Python Community. I bring greetings from the Haskell community (http://www.haskell.org) ;) There has been a lot of discussion of late about creating a grand-unified build & distribution system for "3rd party" Haskell libraries (those not distributed with the compilers). Python's Distutils has come up a few times. The Haskell...
0
1321
by: Jorge Godoy | last post by:
Hi! For the following setup.py, I get this error: byte-compiling /var/tmp/bhsys-buildroot/usr/lib/python2.3/site-packages/bhsys/Impressao.py to Impressao.pyc byte-compiling /var/tmp/bhsys-buildroot/usr/lib/python2.3/site-packages/bhsys/bhsys.py to bhsys.pyc running install_scripts
1
2642
by: Mathieu Malaterre | last post by:
Hello, I thought this would be easy but I guess I didn't get the distutil feeling. I am trying to write a setup for install my package but I don't understand how to do that. organisation: setup.py /bin/
15
4100
by: Colin J. Williams | last post by:
The distutils download page has: -------------------------------------------------------- Current stable release The current stable release is Distutils 1.0.2; you can download it as: * Distutils-1.0.2.tar.gz (source distribution) (233k) * Distutils-1.0.2.zip (source distribution) (274k) * Distutils-1.0.2.win32.exe (Windows installer)...
1
1704
by: Terry Hancock | last post by:
Some time ago, I got the idea that I wanted to build image resources from vector graphic originals, instead of marshalling hundreds of tiny little icon images by hand. I wrote "BuildImage" to do this for me, and so far, it works very well, so I'm trying to make it easier to use and available to more developers. There is a brief (and...
7
1777
by: Scott | last post by:
I've installed Python 2.4 under WinXP and am attempting to create an extension module using the steps outlined here: http://python.org/doc/2.4/ext/win-cookbook.html I'm specifically trying to perform step 6. Creating a brand new project using VC6. The trouble I have is that there are no PC or PCbuild subdirectories in C:\Python24. Where...
0
1854
by: Maarten Sneep | last post by:
I'm trying to build PyBison on Mac OS X, and I'm running into some problems with the distutils. Just for starters: PyBison requires Pyrex. This is not a problem, and Pyrex seems to work without problems, at least the primes sample module shows a nice 25 to 30 fold speed increase over the pure python version. I used the distutils to...
6
2336
by: ajikoe | last post by:
Hello I tried to combine c++ and python together. So I follow from this website: http://kortis.to/radix/python_ext/ I have this code: # prmodule.c static PyObject *pr_isprime(PyObject *self, PyObject *args){ int n, input; if (!PyArg_ParseTuple(args, "i", &input))
3
1718
by: Rick Muller | last post by:
I need some distutils help. I currently run a python library (PyQuante) that, until recently, had all of its modules in a single directory, called "PyQuante". The setup command in my setup.py module had a single "packages" line: packages = , I moved some of the routines into Basis and IO subdirectories of PyQuante, and amended the...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7752
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.