Coder Social home page Coder Social logo

Question about pyenv about gef HOT 6 CLOSED

samas69420 avatar samas69420 commented on August 25, 2024
Question about pyenv

from gef.

Comments (6)

hugsy avatar hugsy commented on August 25, 2024

pyenv is the source of too many unwanted issue and I don't think it's gef's job to check if it's running in a venv or not. In addition, none of the pyenv checks are tested through our CI so it's a bit uncertain to know when bugs hit.

I don't know if this could lead to conflicts, maybe it would be better to just force users to set the global python version to "system" from pyenv and deactivate any virtual environment before running gdb if pyenv is detected

Exactly. As I mentioned in #1048 the correct approach IMO is simply to remove all code related to pyenv detection in gef itself, and instead we can have a standalone script (in scripts/ for instance) that will be here exactly for that purpose; script that must be loaded before gef in the gdbinit. We can easily do that and also provide documentation to assist on setting this up for users.

@samas69420 If you're willing to do this, such PR would be most welcome - simply because I don't think many of the other devs (include myself) use pyenv for gdb.

from gef.

samas69420 avatar samas69420 commented on August 25, 2024

what should the script do besides detecting pyenv?

from gef.

hugsy avatar hugsy commented on August 25, 2024

what should the script do besides detecting pyenv?

Exactly that, but in a separate script:

gef/gef.py

Lines 11396 to 11415 in ece5728

try:
pyenv = which("pyenv")
pyenv_root = gef_pystring(subprocess.check_output([pyenv, "root"]).strip())
pyenv_version = gef_pystring(subprocess.check_output([pyenv, "version-name"]).strip())
site_packages_dir = pathlib.Path(pyenv_root) / f"versions/{pyenv_version}/lib/python{pathlib.Path(pyenv_version).stem}/site-packages"
assert site_packages_dir.is_dir()
site.addsitedir(str(site_packages_dir.absolute()))
except FileNotFoundError:
pass
# When using a Python virtual environment, GDB still loads the system-installed Python
# so GEF doesn't load site-packages dir from environment
# In order to fix it, from the shell with venv activated we run the python binary,
# take and parse its path, add the path to the current python process using sys.path.extend
PYTHONBIN = which("python3")
PREFIX = gef_pystring(subprocess.check_output([PYTHONBIN, '-c', 'import os, sys;print((sys.prefix))'])).strip("\\n")
if PREFIX != sys.base_prefix:
SITE_PACKAGES_DIRS = subprocess.check_output(
[PYTHONBIN, "-c", "import os, sys;print(os.linesep.join(sys.path).strip())"]).decode("utf-8").split()
sys.path.extend(SITE_PACKAGES_DIRS)

from gef.

hugsy avatar hugsy commented on August 25, 2024

And maybe leave an additional global variable or environment variable like RUNNING_IN_PYENV or something in case that's important to detect in the future (I doubt it, but it won't hurt).

from gef.

samas69420 avatar samas69420 commented on August 25, 2024

i can try, but anyway i already made a little edit on the code (still in gef.py tho), now users are forced to explicitly select "system" python version if they're using pyenv and if they don't do it they get a error message, i also moved the gef declaration above so i could use the err function to print the message, if it's ok i can open a PR
https://github.com/samas69420/gef/blob/a1d1a62aa9826526fc985cf8d534beb563be9158/gef.py#L11383-L11444

from gef.

hugsy avatar hugsy commented on August 25, 2024

pyenv support has been removed with #1084

Closing this issue

from gef.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.