Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 438984 - dev-python/python-exec: C-wrapper prohibits 'pythonX.Y foo' invocation
Summary: dev-python/python-exec: C-wrapper prohibits 'pythonX.Y foo' invocation
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Michał Górny
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-19 20:27 UTC by Michał Górny
Modified: 2012-11-23 22:18 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2012-10-19 20:27:47 UTC
The C wrapper installed by python-exec and symlinked in place of Python scripts by distutils-r1 makes it impossible to invoke those scripts (without implementation suffix) through 'pythonX.Y', e.g.:

$ python2.7 /usr/bin/flaggie
  File "/usr/bin/flaggie", line 1
    ELF
    ^
SyntaxError: invalid syntax

This is somehow a regression, you can tell, although running 'pythonX.Y /usr/bin/foo' wouldn't respect the given Python version AFAIK.

Anyway, there are two questions:

1. Do we want to support such use? As in, do we really expect people doing 'pythonX.Y /usr/bin/foo' when they can just call /usr/bin/foo-pythonX.Y instead?

2. If we do, how can we solve that?
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2012-11-04 00:11:26 UTC
Since this seems to be a very big deal for some people and Brian has tested a fairly good solution already, here's how I see we could fix it:

1. rename python-exec -> some-other-name,

2. install python-exec as a python script setting EPYTHON and doing re-exec with shebang running some-other-name directly.


Unless I'm missing something, this should fix it sanely:

1. foo -symlink-> python-exec -shebang-> some-other-name,

[no python involved in running]

2. python foo -symlink-> python python-exec -os.exec()-> some-other-name.


@floppym, idella4: any comments? I'll try to implement it in a branch today afternoon.
Comment 2 Mike Gilbert gentoo-dev 2012-11-04 00:40:08 UTC
(In reply to comment #1)

I'm not actually sure what you're proposing here, but I'm happy to review whatever you come up with.
Comment 3 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2012-11-04 14:22:42 UTC
(In reply to comment #2)
> (In reply to comment #1)
> 
> I'm not actually sure what you're proposing here, but I'm happy to review
> whatever you come up with.

And it's ready on 'python-wrapper' branch!

  layman -a mgorny
  flaggie python-exec +**
  EGIT_BRANCH=python-wrapper emerge -1 python-exec
  python3.2 /usr/bin/flaggie

(!)

Or just:

https://bitbucket.org/mgorny/python-exec/compare/python-wrapper..
Comment 4 Mike Gilbert gentoo-dev 2012-11-04 18:35:49 UTC
Seems to work pretty well.

One interesting behavior: If you invoke it using a python version for which there is no script-$EPYTHON, it falls back to the eselected version and/or iterating through all of them.
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2012-11-04 20:04:34 UTC
(In reply to comment #4)
> Seems to work pretty well.
> 
> One interesting behavior: If you invoke it using a python version for which
> there is no script-$EPYTHON, it falls back to the eselected version and/or
> iterating through all of them.

Yes, that was intended.

I'm however wondering about two things:

1) using sys.executable...

...which is dumb path to the interpreter and contain just anything. I'm thinking about replacing that with something smart and simple -- like installing a custom Python module with EPYTHON written for import.

2) calling the wrapper directly instead of the wrapped script...

...which is somehow better but doesn't exactly follow the semantics of 'pythonX.Y /usr/bin/foo'. For example, it respects the interpreter options in shebang while the latter wouldn't. And your point also falls into this category.

We might make it instead just choose foo-pythonX.Y, and execute that script using the current Python interpreter whatever it is.
Comment 6 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2012-11-23 22:18:17 UTC
Fixed in 0.2.