I had some newbie distutils I wanted to humbly ask if you don't mind. I read distutils docs on python.org but still had some basic questions... 1. What goes into __init__.py files??? I know what setup.py contents are but I don't recall seeing advice on what to put in __init__.py. 2. I have a ton of data files to list in setup(...) with the data_files switch. Can I avoid listing EVERY file somehow??? Can I use a wildcard in the filename???? 3. Will bdist_rpm install JUST pyc files (bytecode)??? Will sdist install JUST py (source) files??? What about installing source and bytecode?? (py and pyc)?? How do that and is THAT a good idea??? 4. If I tell setup(...) I have a package somewhere with packages = ["..."] does that mean it will get ALL files in that directory without me having to specify them individually?? What if I want to OMIT a file like the CVS directory?!?! Thanks! Chris -- _______________________________________ Christian Seberino, Ph.D. SPAWAR Systems Center San Diego Code 2872 49258 Mills Street, Room 158 San Diego, CA 92152-5385 U.S.A. Phone: (619) 553-9973 Fax : (619) 553-6521 Email: seberino@spawar.navy.mil _______________________________________
On Tue, 2003-09-30 at 19:50, seberino@spawar.navy.mil wrote:
1. What goes into __init__.py files??? I know what setup.py contents are but I don't recall seeing advice on what to put in __init__.py.
You don't need to put anything into __init__.py files. They are necessary to make Python recognize a directory as a package, but they can be empty. If you put code in __init__.py, it is executed when the package is imported, including the first time a submodule of a package is imported. It is sometimes useful to execute code here, but that's up to you.
2. I have a ton of data files to list in setup(...) with the data_files switch. Can I avoid listing EVERY file somehow??? Can I use a wildcard in the filename????
It can be tedious to list all the data files. The setup.py script is a regular Python script, though, so you can compute the full list from the wildcard. The glob module might do what you want or you can search for files using os.path.walk.
3. Will bdist_rpm install JUST pyc files (bytecode)??? Will sdist install JUST py (source) files??? What about installing source and bytecode?? (py and pyc)?? How do that and is THAT a good idea???
The bdist and sdist commands do not install anything. They generate distributions that can be used to install software. You probably know that, but I want to make sure we're on the same page. An sdist distribution contains only .py files. The source distribution could work with many versions of Python, but .pyc files are tied to a particular version. The source distribution generates .pyc files when a user unpacks it and runs "python setup.py install". I believe a bdist command will have the same effect. I'm not sure about bdist_rpm, but bdist_wininst only puts source files in the distribution.
4. If I tell setup(...) I have a package somewhere with packages = ["..."] does that mean it will get ALL files in that directory without me having to specify them individually??
It means all .py files. It will ignore any other file in the directory. Note that you have to explicitly include subpackages in the list.
What if I want to OMIT a file like the CVS directory?!?!
It gets skipped, because it isn't listed as a package. If you tried to list it as a package, it still wouldn't contain any .py files. Note that it is a little tedious to get non-Python files installed with a package. If you want a data file to be included next to the .py file, you've got to go to a lot of trouble. Jeremy
Jeremy Thanks. I needed that. CS On Tue, Sep 30, 2003 at 10:49:30PM -0400, Jeremy Hylton wrote:
On Tue, 2003-09-30 at 19:50, seberino@spawar.navy.mil wrote:
1. What goes into __init__.py files??? I know what setup.py contents are but I don't recall seeing advice on what to put in __init__.py.
You don't need to put anything into __init__.py files. They are necessary to make Python recognize a directory as a package, but they can be empty.
If you put code in __init__.py, it is executed when the package is imported, including the first time a submodule of a package is imported. It is sometimes useful to execute code here, but that's up to you.
2. I have a ton of data files to list in setup(...) with the data_files switch. Can I avoid listing EVERY file somehow??? Can I use a wildcard in the filename????
It can be tedious to list all the data files. The setup.py script is a regular Python script, though, so you can compute the full list from the wildcard. The glob module might do what you want or you can search for files using os.path.walk.
3. Will bdist_rpm install JUST pyc files (bytecode)??? Will sdist install JUST py (source) files??? What about installing source and bytecode?? (py and pyc)?? How do that and is THAT a good idea???
The bdist and sdist commands do not install anything. They generate distributions that can be used to install software. You probably know that, but I want to make sure we're on the same page.
An sdist distribution contains only .py files. The source distribution could work with many versions of Python, but .pyc files are tied to a particular version. The source distribution generates .pyc files when a user unpacks it and runs "python setup.py install".
I believe a bdist command will have the same effect. I'm not sure about bdist_rpm, but bdist_wininst only puts source files in the distribution.
4. If I tell setup(...) I have a package somewhere with packages = ["..."] does that mean it will get ALL files in that directory without me having to specify them individually??
It means all .py files. It will ignore any other file in the directory. Note that you have to explicitly include subpackages in the list.
What if I want to OMIT a file like the CVS directory?!?!
It gets skipped, because it isn't listed as a package. If you tried to list it as a package, it still wouldn't contain any .py files.
Note that it is a little tedious to get non-Python files installed with a package. If you want a data file to be included next to the .py file, you've got to go to a lot of trouble.
Jeremy
-- _______________________________________ Christian Seberino, Ph.D. SPAWAR Systems Center San Diego Code 2872 49258 Mills Street, Room 158 San Diego, CA 92152-5385 U.S.A. Phone: (619) 553-9973 Fax : (619) 553-6521 Email: seberino@spawar.navy.mil _______________________________________
On Tue, Sep 30, 2003 at 04:50:25PM -0700, seberino@spawar.navy.mil wrote:
3. Will bdist_rpm install JUST pyc files (bytecode)??? Will sdist install JUST py (source) files??? What about installing source and bytecode?? (py and pyc)?? How do that and is THAT a good idea???
Binary distributions (bdist) means that C extensions are compiled and the user installing them doesn't need a C compiler. .py files are also installed, and may or may not be compiled into .pyc files, depending on the bdist format. Source distributions require users to run "setup.py install" to install them, and if the package contains C extensions and the user doesn't have a C compiler, they'll be unable to install the package. For packages consisting of only Python code, there's only a slight difference between source and binary distributions from the end user's point of view. C extensions make the difference greater; in particular, few Windows users will have a compiler. --amk
Thanks! This is all great and useful info. sdist = py files bdist* = py or pyc files *Which* bdist_* switches have py files and which have pyc files?? Especially what do bdist_rpm and bdist have? Chris On Wed, Oct 01, 2003 at 10:05:08AM -0400, amk@amk.ca wrote:
On Tue, Sep 30, 2003 at 04:50:25PM -0700, seberino@spawar.navy.mil wrote:
3. Will bdist_rpm install JUST pyc files (bytecode)??? Will sdist install JUST py (source) files??? What about installing source and bytecode?? (py and pyc)?? How do that and is THAT a good idea???
Binary distributions (bdist) means that C extensions are compiled and the user installing them doesn't need a C compiler. .py files are also installed, and may or may not be compiled into .pyc files, depending on the bdist format.
Source distributions require users to run "setup.py install" to install them, and if the package contains C extensions and the user doesn't have a C compiler, they'll be unable to install the package.
For packages consisting of only Python code, there's only a slight difference between source and binary distributions from the end user's point of view. C extensions make the difference greater; in particular, few Windows users will have a compiler.
--amk
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig
-- _______________________________________ Christian Seberino, Ph.D. SPAWAR Systems Center San Diego Code 2872 49258 Mills Street, Room 158 San Diego, CA 92152-5385 U.S.A. Phone: (619) 553-9973 Fax : (619) 553-6521 Email: seberino@spawar.navy.mil _______________________________________
participants (3)
-
amk@amk.ca
-
Jeremy Hylton
-
seberino@spawar.navy.mil