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

Update activate_this.py documentation to use runpy instead of exec #2716

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/virtualenv/activation/python/activate_this.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
Activate virtualenv for current interpreter:

Use exec(open(this_file).read(), {'__file__': this_file}).
import runpy
runpy.run_path(this_file)

This can be used when you must use an existing Python interpreter, not the virtualenv bin/python.
""" # noqa: D415
Expand All @@ -15,7 +16,7 @@
try:
abs_file = os.path.abspath(__file__)
except NameError as exc:
msg = "You must use exec(open(this_file).read(), {'__file__': this_file})"
msg = "You must use import runpy; runpy.run_path(this_file)"
raise AssertionError(msg) from exc

bin_dir = os.path.dirname(abs_file)
Expand Down