Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature req: auto-hash-lib-py-app #2650

Open
the-moog opened this issue Mar 20, 2023 · 3 comments
Open

Feature req: auto-hash-lib-py-app #2650

the-moog opened this issue Mar 20, 2023 · 3 comments

Comments

@the-moog
Copy link

the-moog commented Mar 20, 2023

AFAIK, Pyenv auto hashing currently only works with 'standard' Python tools or anything installed by pip. It is not aware of exes that link to Python, unless a shim file is manually created.

A user could provide their own shim, but if there are a lot of Python based commands then there would be a lof of maintainance and any user edits of system files is a PITA to support.

auto-hash-lib-py-app, for want of a better name, would do the following:
On a bash chdir hook, or some other hook (how does pyenv know if this is a pyenv, anyway?), or other command, e.g. activate, this would happen:

on the cd hook (or init or activate or whatever)
pyenv-auto-hash-lib-py-app (*name pending) would scan the entire tree for any executables.
looping through that list:
  For each executable it would
    If there is no existing shim for that exe
     use ldd to determine if that app dynlinks to the Python version present in the current pyenv tree,
       If the versions match it auto creates a shim for that app, in pyenv

At app runtime,
As usual, the shim alters the LD_LIBRARY_PATH environemt before running it,

Currently the user must provide 'shims' for each app that diverts it to pyenv as required., diverting all apps would be a bad idea in case one used a different python.  There could be a hook script scans the current pyenv tree for executables and uses ldd to finid if that exe uses the same version as the current pyenv and create shims for them automatically if they don't already exist.

Wondering if there is another way. Somehow hook popen() within the environment or spawn another shell on chdir and exit that shell on chdir ?

Other perhaps useful links:
https://github.com/pmem/syscall_intercept (hot patching libc in user space)
https://github.com/rcaloras/bash-preexec bash preexec/postexec hooks

Prerequisite - Yep done that.

@native-api
Copy link
Member

Could you describe the intended use case?

@native-api
Copy link
Member

native-api commented Apr 7, 2023

IIRC it's for linking your program against Pyenv-provided Python, right?
You need to direct ld to pick a specific libpython?

And it probably needs to be one-time lest it prevents you from calling other stuff that link against the system's Python.

@native-api
Copy link
Member

As usual, the shim alters the LD_LIBRARY_PATH environemt before running it

Altering LD_LIBRARY_PATH would break system scripts that use system Python if it has the same minor version, as per #2698.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants