-
-
Notifications
You must be signed in to change notification settings - Fork 732
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
Add support for virtualenv #1119
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9854,6 +9854,9 @@ def __init__(self) -> None: | |||||||||||||||
plugins_dir = GefSetting("", str, "Autoload additional GEF commands from external directory", hooks={"on_write": [GefSetting.no_spaces, ]}) | ||||||||||||||||
plugins_dir.add_hook("on_changed", [lambda _, new_val: GefSetting.must_exist(new_val), lambda _, new_val: self.load_extra_plugins(new_val), ]) | ||||||||||||||||
gef.config["gef.extra_plugins_dir"] = plugins_dir | ||||||||||||||||
venv_path = GefSetting("", str, "Path to the virtualenv used by GEF", hooks={"on_write": [GefSetting.no_spaces, ]}) | ||||||||||||||||
venv_path.add_hook("on_changed", [lambda _, new_val: GefSetting.must_exist(new_val), lambda _, new_val: self.load_virtualenv(new_val), ]) | ||||||||||||||||
gef.config["gef.virtualenv_path"] = venv_path | ||||||||||||||||
gef.config["gef.disable_color"] = GefSetting(False, bool, "Disable all colors in GEF") | ||||||||||||||||
gef.config["gef.tempdir"] = GefSetting(GEF_TEMP_DIR, pathlib.Path, "Directory to use for temporary/cache content", hooks={"on_write": [GefSetting.no_spaces, GefSetting.create_folder_tree]}) | ||||||||||||||||
gef.config["gef.show_deprecation_warnings"] = GefSetting(True, bool, "Toggle the display of the `deprecated` warnings") | ||||||||||||||||
|
@@ -9943,6 +9946,13 @@ def load_plugins_from_directory(plugin_directory: pathlib.Path): | |||||||||||||||
dbg(f"Loading extra plugins from directory={directory}") | ||||||||||||||||
return load_plugins_from_directory(directory) | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def load_virtualenv(self, new_path: Optional[pathlib.Path] = None): | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this makes sense as a method here |
||||||||||||||||
path = new_path or gef.config["gef.virtualenv_path"] | ||||||||||||||||
if path: | ||||||||||||||||
activate_script_path = pathlib.Path(path)/"bin"/"activate_this.py" | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here
|
||||||||||||||||
exec(open(activate_script_path).read(), {'__file__': activate_script_path}) | ||||||||||||||||
Comment on lines
+9952
to
+9954
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid cascading by returning first on error
Suggested change
Comment on lines
+9952
to
+9954
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also simpler exec(activate_script_path.read_text(), {'__file__': activate_script_path}) |
||||||||||||||||
|
||||||||||||||||
@property | ||||||||||||||||
def loaded_command_names(self) -> Iterable[str]: | ||||||||||||||||
print("obsolete loaded_command_names") | ||||||||||||||||
|
@@ -11717,6 +11727,9 @@ def target_remote_posthook(): | |||||||||||||||
gef.gdb.load() | ||||||||||||||||
gef.gdb.show_banner() | ||||||||||||||||
|
||||||||||||||||
# load venv | ||||||||||||||||
gef.gdb.load_virtualenv() | ||||||||||||||||
|
||||||||||||||||
# load config | ||||||||||||||||
gef.gdb.load_extra_plugins() | ||||||||||||||||
|
||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
virtualenv config test module | ||
""" | ||
|
||
from tests.base import RemoteGefUnitTestGeneric | ||
from os import system | ||
from tempfile import mktemp | ||
|
||
|
||
class VirtualenvConfig(RemoteGefUnitTestGeneric): | ||
"""virtualenv config test module""" | ||
|
||
def setUp(self) -> None: | ||
venv_path = mktemp() | ||
system(f"virtualenv {venv_path}") | ||
system(f"{venv_path}/bin/pip install numpy") | ||
|
||
self.venv_path = venv_path | ||
|
||
return super().setUp() | ||
|
||
def test_conf_venv(self): | ||
gdb = self._gdb | ||
gdb.execute(f"gef config gef.virtualenv_path {self.venv_path}") | ||
|
||
res = gdb.execute("pi __import__('numpy').test()", to_string=True) | ||
assert 'NumPy version' in res | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double quotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we do it above, but you shuld be able to just add
on_changed
as an extra key in thehooks
arg for the constructor.