Repository navigation
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
Description
| BPO | 12394 |
|---|---|
| Nosy | @mhammond, @freddrake, @vsajip, @tjguk, @tarekziade, @merwok |
| Files |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/merwok'
closed_at = <Date 2014-03-13.03:02:17.570>
created_at = <Date 2011-06-24.09:14:23.730>
labels = ['type-feature', 'library']
title = 'packaging: generate scripts from callable (dotted paths)'
updated_at = <Date 2014-03-13.03:02:17.569>
user = 'https://github.com/vsajip'bugs.python.org fields:
activity = <Date 2014-03-13.03:02:17.569>
actor = 'eric.araujo'
assignee = 'eric.araujo'
closed = True
closed_date = <Date 2014-03-13.03:02:17.570>
closer = 'eric.araujo'
components = ['Library (Lib)', 'Distutils2']
creation = <Date 2011-06-24.09:14:23.730>
creator = 'vinay.sajip'
dependencies = []
files = ['22711', '22727', '22922', '24659']
hgrepos = ['42']
issue_num = 12394
keywords = ['patch']
message_count = 58.0
messages = ['138896', '138897', '138899', '138900', '138902', '138906', '138909', '138911', '138915', '138918', '138922', '138938', '138943', '138944', '138945', '138983', '139021', '139022', '139115', '139122', '140815', '140841', '140847', '140882', '140883', '140888', '140925', '140951', '140956', '140978', '140979', '140983', '141047', '141048', '141059', '141152', '142282', '142302', '142303', '142322', '142323', '142342', '142349', '142377', '142378', '142400', '146218', '146296', '146298', '146306', '146311', '146378', '146382', '146383', '150463', '150502', '154467', '154468']
nosy_count = 10.0
nosy_names = ['mhammond', 'fdrake', 'vinay.sajip', 'ceder', 'tim.golden', 'tarek', 'eric.araujo', 'alexis', 'higery', 'guyrozendorn']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue12394'
versions = ['3rd party', 'Python 3.3']Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
Activity
vsajip commentedon Jun 24, 2011
At present, packaging support for scripts on Windows is the same as for any other system. This is sub-optimal, for the following reasons:
Setuptools (and therefore Distribute) support these requirements by installing a script "demo", on Windows, as "demo.exe" and "demo-script.py" (or "demo-script.pyw"), where demo.exe is a stock Windows executable (either console or GUI) which invokes the appropriate Python executable on the "demo-script.py[w]" file.
Packaging should provide a similar mechanism, which can be implemented very simply by changing the build_scripts command appropriately. It should work like this:
The stock executables can be the same as Distribute uses (setuptools/cli.exe and setuptools/gui.exe), if there is no licensing (or other) issue with having them in Python. If there is such an issue, they can be written from scratch to do the same job (it's just one C file).
I have this working in the pythonv branch, and if this feature request is accepted then I can work up a patch with test and doc changes. (The build_scripts changes are quite straightforward.)
tjguk commentedon Jun 24, 2011
Are you aware of PEP-397?
http://www.python.org/dev/peps/pep-0397/
vsajip commentedon Jun 24, 2011
@tim: It had gone under my radar, thanks for the link!
I don't know if/when it will be accepted (i.e. whether before 3.3), so my suggestion could be considered as a fallback alternative which works now. If the PEP-397 launcher is available, then of course we should use that.
Of course PEP-397 does not support 'pythonw' in shebang lines, but the "pythonw" I am suggesting here will not appear in the final output script anyway. It's more of a hint to build_scripts indicating the launcher to use. It seems this choice is still required, since from a quick reading of PEP-397, I couldn't see how the user could just type "demo" for an eponymous script in a virtualenv and get the correct launcher (console or GUI).
tjguk commentedon Jun 24, 2011
Adding Mark H as the author of PEP-397
merwok commentedon Jun 24, 2011
My GSoC student will work on integrating the scripts generation from setuptools into packaging.
vsajip commentedon Jun 24, 2011
Éric, what will be the scope of that integration? Please bear in mind, I have a working solution, so there's no need to cover this part again unless you think there's a problem with my implementation.
The changes were straightforward, see
https://bitbucket.org/vinay.sajip/pythonv/changeset/d2453f281baf
merwok commentedon Jun 24, 2011
In the setup.cfg files, scripts will now be a mapping of names to callables, like the setuptools scripts and gui_scripts entry points:
On UNIX, a Python script named sphinx-build will be created, on Windows, a binary sphinx-build.exe will be created.
vsajip commentedon Jun 24, 2011
Does that mean that you can't just put an arbitrary Python script in your application? You have to structure it as a callable?
Of course, I see the applicability of it for the entry_points functionality of setuptools.
merwok commentedon Jun 24, 2011
Arbitrary script files are supported via the resources feature (when the bug you reported is fixed :) The generation of scripts from callables is a widely-used setuptools feature that will solve a number of problems (Python not on PATH on Windows, unnecessary .py extension on UNIX, such things).
vsajip commentedon Jun 24, 2011
Then for Unix at least, how will the installer know which resources need the execute permission turned on? Just by the destination?
merwok commentedon Jun 24, 2011
The copy function used will preserve rights. IOW, the +x will be needed in the source.
[-]Packaging should provide better support for executable scripts on Windows[/-][+]packaging: generate scripts from callable (dotted paths)[/+]36 remaining items
vsajip commentedon Aug 18, 2011
Just to clarify: I'm -1 on heuristics too; it's better to have some way of explicitly declaring the intention. I've no problem with e.g. the [scripts] section being used just for generated scripts, as long as there is a clear way of designating arbitrary .py/.pyw files as scripts in the [resources] section, which would have the shebang line transmutation applied during installation.
Re. the unwanted attachments - sorry, I don't normally use HTML email - I need to change the settings I was using.
merwok commentedon Oct 23, 2011
FTR, distribute recently committed two fixes for the exe wrappers: https://bitbucket.org/tarek/distribute/issue/238 and https://bitbucket.org/tarek/distribute/issue/207
vsajip commentedon Oct 24, 2011
FYI: In pythonv, the build_scripts functionality provides identical support for dotted callables to what Éric proposed, while preserving existing functionality for ordinary script files. Thus:
copies demo1 (adjusting its shebang) and creates demo2 and demo3 from the dotted callables (using the appropriate shebang).
While working on this, I came up against a problem with build_scripts in virtual environments: if I install a project into virtual env 1, then scripts are built with shebangs pointing to that env. If I then install the same project into virtual env 2, then the scripts are not re-created, so they would be installed into virtual env 2 with shebangs referencing virtual env 1. One solution is to set the force flag for virtual environments, but then if you later install into the system Python, then files with wrong shebangs could be installed there. I think the force flag should default to True for build_scripts; the extra script build time would be negligible except in pathological cases. Do you agree?
vsajip commentedon Oct 24, 2011
Re. the launcher changes, those improvements by Guy Rozendorn are welcome. I noticed some differences from the approach taken by Mark Hammond and Curt Hagenlocher in the PEP-397 implementation, which I ported to C:
The Ctrl-C is ignored by the PEP-397 launcher. AFAICT it's passed to the child process anyway by Windows. The ignoring prevents the default behaviour (premature termination of the launcher).
The PEP-397 launcher also duplicates the standard handles before creating the child process.
The PEP-397 launcher also associates the launcher and the child together using the Job API.
merwok commentedon Oct 24, 2011
My current preference is to use only new-style generated scripts for the scripts field in the files section, and to let people use the data-files/resources system for old-style file scripts.
We’ll have to think about the shebang munging and decide if we keep it. I think recommending that people use “/usr/bin/env python” (or python3) and not doing anything to the shebang may be the best thing.
vsajip commentedon Oct 24, 2011
What about Windows support? Of course there is PEP-397 which brings shebang-line functionality to Windows, but that PEP has not yet been finalised. Without the existing shebang functionality, IMO there will be problems for Windows users with the “/usr/bin/env python” approach you suggest.
merwok commentedon Oct 25, 2011
vsajip commentedon Oct 25, 2011
Please spell out for me how you see this working: I don't see it. Note that scripts have to use the correct Python even if they are invoked using an explicit path pointing into a virtual environment.
vsajip commentedon Oct 25, 2011
To expand on what I said about not seeing how things will work under Windows: are we going to place .exe launchers adjacent to the script, like setuptools does? If the script just has a shebang of "#!/usr/bin/env python", how is the launcher supposed to determine the exact Python to use from that, in a venv scenario where multiple Pythons will be installed? Scripts in virtual envs are supposed to run if invoked, even if the env is not on the PATH.
merwok commentedon Jan 2, 2012
I’ll get back to this issue later, but now I just wanted to add a link about building the binary exe files: http://mail.python.org/pipermail/python-dev/2006-April/063846.html (it comes from the time where setuptools was supposed to be added to the stdlib)
vsajip commentedon Jan 3, 2012
@Éric: you may also be interested in a standalone launcher which I wrote for the pythonv branch:
https://bitbucket.org/vinay.sajip/simple_launcher/
This is built using Visual Studio and is not based on setuptools code, but uses the same Windows API for child process creation and synchronisation as the PEP-397 launcher (rather than execv/spawnv as the setuptools launcher does). It also links with the runtime statically rather than linking with msvcrt.dll.
merwok commentedon Feb 27, 2012
I merged default yesterday and produced this patch. I’ll use the review site to make comments.
merwok commentedon Feb 27, 2012
Or I won’t, as even a dumb no-git-style diff does not create a review link, maybe because of the binary file change. *Sigh* Trying again.