[PATCH] win32 installer for bzr 0.9: rev.2
Alexander Belchenko
bialix at ukr.net
Tue Aug 1 00:18:42 BST 2006
John Arbash Meinel пишет:
>
>>> I also feel like it would be better to use
>>> sys.executable, rather than joining prefix + 'python.exe'.
>> No. Your feelings is wrong. This script (bzr-win32-bdist-postinstall.py)
>> launched during installation phase when user runs bzr-0.9.win32.exe
>> installer. And for this script sys.executable equals to full path to
>> installer. Not to python interpreter. So "prefix + 'python.exe'" is right.
>>
> I think you are saying you spawn 'python
> bzr-win32-bdist-postinstall.py', or the equivalent.
>
> sys.executable == a python executable, *not* the script that is running
> (that is sys.argv[0])
>
> If sys.executable == 'bzr-0.9.win32.exe', how do you know that it is
> sitting in the same directory as 'python.exe'?
>
> I think I understand that bzr-0.9.win32.exe is just the installer, not a
> python interpreter. Which would mean that you still should use
> 'sys.executable'.
I try to clarify a bit. Script bzr-win32-bdist-postinstall.py designed
exclusively to use with python-based installer. This script designed in
accordance with python documentation 'Distributing Python Modules'
section '5.3 Creating Windows Installers', subsection 'The
Postinstallation scripts'.
http://docs.python.org/dist/postinstallation-script.html#SECTION005310000000000000000
This document in particular says:
--------------------------------------------------------------------------
This script will be run at installation time on the target system after
all the files have been copied, with argv[1] set to -install, and again
at uninstallation time before the files are removed with argv[1] set to
-remove.
The installation script runs embedded in the windows installer, every
output (sys.stdout, sys.stderr) is redirected into a buffer and will be
displayed in the GUI after the script has finished.
-------------------------------------------------------------------------
I create simple testing postinstall script to inspect values of
different path variables. Content of this script:
-------------------------------------------------
import os
import sys
if "-install" in sys.argv[1:]:
print 'sys.argv:', sys.argv
print 'sys.executable:', sys.executable
print 'sys.prefix:', sys.prefix
print 'sys.exec_prefix:', sys.exec_prefix
print 'os.getcwd():', os.getcwd()
-------------------------------------------------
This script launched automatically by python-based installer as last
step of installation (after all source files is copied). Output of this
script is sown at the last screen of installation wizard. Here
copy-pasted text. Also see attached screenshot.
-------------------------------------------------
sys.argv: ['C:\\Python24\\Scripts\\bzr-win32-bdist-postinstall.py',
'-install']
sys.executable:
E:\Bazaar-NG\devel\python-installer\dist\bzr-0.9.0dev0.win32.exe
sys.prefix: C:\Python24
sys.exec_prefix: C:\Python24
os.getcwd(): E:\Bazaar-NG\devel\python-installer\dist
-------------------------------------------------
Documentation of sys module says:
-------------------------------------------------------------------------
exec_prefix
A string giving the site-specific directory prefix where the
platform-dependent Python files are installed; by default, this is also
'/usr/local'. This can be set at build time with the --exec-prefix
argument to the configure script. Specifically, all configuration files
(e.g. the pyconfig.h header file) are installed in the directory
exec_prefix + '/lib/pythonversion/config', and shared library modules
are installed in exec_prefix + '/lib/pythonversion/lib-dynload', where
version is equal to version[:3].
executable
A string giving the name of the executable binary for the Python
interpreter, on systems where this makes sense.
prefix
A string giving the site-specific directory prefix where the platform
independent Python files are installed; by default, this is the string
'/usr/local'. This can be set at build time with the --prefix argument
to the configure script. The main collection of Python library modules
is installed in the directory prefix + '/lib/pythonversion' while the
platform independent header files (all except pyconfig.h) are stored in
prefix + '/include/pythonversion', where version is equal to version[:3].
--------------------------------------------------------------------------
But built-in help for module sys very brief here:
--------------------------------------------------------------------------
executable -- pathname of this Python interpreter
prefix -- prefix used to find the Python library
exec_prefix -- prefix used to find the machine-specific Python library
--------------------------------------------------------------------------
As you can see postinstall script running by installer itself (I suppose
that installer use Python C/API to load and execute this script, with
function like Py_Main or something similar). Both sys.prefix and
sys.exec_prefix is very similar to each other, and I don't see
difference between them on Windows. Although, C:\Python24\Scripts seems
to be platform-dependent location (AFAIK, on Linux executable scripts
installed directly to /usr/bin or /usr/sbin). Probably I need to use
sys.exec_prefix as directory where python.exe is located.
If we want to be *really* paranoid, we can do additional check that
python.exe actually exists at os.path.join(sys.exec_prefix,
'python.exe') or try to build path to python.exe from sys.argv[0]
because python.exe on windows usually in directory one level up relative
to Scripts, or we can try to search python installation directory by
looking at windows registry (latter can't works if user don't install
python as usual but instead build it from sources or simply copying from
archive or another machine).
I think sys.exec_prefix is what we need. And we don't need to be paranoid.
>>> ...Why is this failing? Because the standalone doesn't have a 'doc/api'
>>> directory?
>> It's failing because in standalone bzr.exe bzrlib itself packed inside
>> library.zip archive. So it simply cannot be os-listdir-able. When I work
>> on installer in early may I ask about this. You can search trough
>> maillist archive. Someone point me that doctest could be improved to use
>> zipimport module to actually obtain list of packed *.txt files with
>> doctests. But I looks too complex for this minor issue.
>>
> Yeah, you mentioned this briefly already, I'm okay with what you are doing.
Before I forget some important details so I think it's OK to explain
things more clear.
>> +Making installers for OS Windows
>> +================================
>> +To build a win32 installer, see the instructions at wiki page:
>> +http://bazaar-vcs.org/BzrWin32Installer
>> +
>> +
>> :: vim: ft=rst tw=74 ai
>
> 'see the instructions on the wiki page:'
Ah, sorry. Thanks for fix.
I think I should to looking for english training courses.
>> # win32 installer for bzr.exe
>> installer: exe copy_docs
>> - @echo Make windows installer
>> - cog.py -d -o tools\win32\bzr.iss tools\win32\bzr.iss.cog
>> - "C:\Program Files\Inno Setup 5\iscc" /Q tools\win32\bzr.iss
>> + @echo *** Make windows installer
>> + cog.py -d -o tools/win32/bzr.iss tools/win32/bzr.iss.cog
>> + iscc /Q tools/win32/bzr.iss
>
> Shouldn't this be 'python cog.py' to be consistent with your other changes.
It's very thin here.
No, it shouldn't be 'python cog.py' because in this case we need to
specify full path to cog.py and this path potentially could be something
like 'C:\Python24\Scripts\cog.py' but if user install Python to
different (not default) directory this path will be wrong. In my
instruction about installer I say that user should add both
'C:\Python24' and 'C:\Python24\Scripts' to $PATH environment variable,
so running cog.py simply by name should work on both Windows and Linux.
In other cases I use form 'python path/to/script.py' to avoid difference
between Windows and Linux (on Linux I have to use something like
'./path/to/script.py' or simply './script.py').
> v--- It seems like it would be better to do:
> META_INFO.update({'version':get_bzr_version()})
> Earlier, rather than having to do it twice. Especially since you've
> already updated ARGS, which would set version = '<unknown>'
> Is there a code path that doesn't need version to be set?
Actually -- yes, py2exe's path don't use this version info. But at other
side it absolutely harmless to set it up in one place for all
installers. I'll change this.
> I think it is just about ready for merging. If you can do the last few
> bits, we'll get it merged this week.
OK.
--
Alexander
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python-installer-postinstall-paths.png
Type: image/png
Size: 20929 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060801/5bd661b2/attachment.png
More information about the bazaar
mailing list