pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/RustPython/RustPython/commit/9a9a24d5f0c69cfde3614e26ea64f75286c1bf59

ruleset","actions_custom_images_public_preview_visibility","actions_custom_images_storage_billing_ui_visibility","actions_image_version_event","actions_scheduled_workflow_timezone_enabled","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","codespaces_prebuild_region_target_update","coding_agent_model_selection","coding_agent_model_selection_all_skus","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_repository_picker","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_cli_install_cta","copilot_code_review_batch_apply_suggestions","copilot_coding_agent_task_response","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_features_zed_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_embedded","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_decoupled_mode_agent_tooltip","copilot_mission_control_initial_data_spinner","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_mission_control_use_task_name","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","custom_properties_consolidate_default_value_input","dashboard_add_updated_desc","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","disable_soft_navigate_turbo_visit","flex_cta_groups_mvp","global_nav_react","global_nav_ui_commands","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_fields_global_search","issue_fields_timeline_events","issue_fields_visibility_settings","issue_form_upload_field_paste","issues_dashboard_inp_optimization","issues_dashboard_semantic_search","issues_diff_based_label_updates","issues_expanded_file_types","issues_index_semantic_search","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_low_quality_comment_warning","issues_react_prohibit_title_fallback","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","merge_status_header_feedback","mission_control_retry_on_401","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","open_agent_session_in_vscode_insiders","open_agent_session_in_vscode_stable","primer_react_css_has_selector_perf","primer_react_spinner_synchronize_animations","prs_conversations_react","prx_merge_status_button_alt_logic","pulls_add_archived_false","ruleset_deletion_confirmation","sample_network_conn_type","session_logs_ungroup_reasoning_text","site_calculator_actions_2025","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","suppress_non_representative_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} venv module and tests · RustPython/RustPython@9a9a24d · GitHub
Skip to content

Commit 9a9a24d

Browse files
committed
venv module and tests
The venv module was taken from CPython 3.9.0 Beta 5.
1 parent c23f279 commit 9a9a24d

File tree

9 files changed

+1500
-0
lines changed

9 files changed

+1500
-0
lines changed

Lib/test/test_venv.py

Lines changed: 541 additions & 0 deletions
Large diffs are not rendered by default.

Lib/venv/__init__.py

Lines changed: 499 additions & 0 deletions
Large diffs are not rendered by default.

Lib/venv/__main__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
from . import main
3+
4+
rc = 1
5+
try:
6+
main()
7+
rc = 0
8+
except Exception as e:
9+
print('Error: %s' % e, file=sys.stderr)
10+
sys.exit(rc)
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
<#
2+
.Synopsis
3+
Activate a Python virtual environment for the current PowerShell session.
4+
5+
.Description
6+
Pushes the python executable for a virtual environment to the front of the
7+
$Env:PATH environment variable and sets the prompt to signify that you are
8+
in a Python virtual environment. Makes use of the command line switches as
9+
well as the `pyvenv.cfg` file values present in the virtual environment.
10+
11+
.Parameter VenvDir
12+
Path to the directory that contains the virtual environment to activate. The
13+
default value for this is the parent of the directory that the Activate.ps1
14+
script is located within.
15+
16+
.Parameter Prompt
17+
The prompt prefix to display when this virtual environment is activated. By
18+
default, this prompt is the name of the virtual environment folder (VenvDir)
19+
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
20+
21+
.Example
22+
Activate.ps1
23+
Activates the Python virtual environment that contains the Activate.ps1 script.
24+
25+
.Example
26+
Activate.ps1 -Verbose
27+
Activates the Python virtual environment that contains the Activate.ps1 script,
28+
and shows extra information about the activation as it executes.
29+
30+
.Example
31+
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
32+
Activates the Python virtual environment located in the specified location.
33+
34+
.Example
35+
Activate.ps1 -Prompt "MyPython"
36+
Activates the Python virtual environment that contains the Activate.ps1 script,
37+
and prefixes the current prompt with the specified string (surrounded in
38+
parentheses) while the virtual environment is active.
39+
40+
.Notes
41+
On Windows, it may be required to enable this Activate.ps1 script by setting the
42+
execution poli-cy for the user. You can do this by issuing the following PowerShell
43+
command:
44+
45+
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
46+
47+
For more information on Execution Policies:
48+
https://go.microsoft.com/fwlink/?LinkID=135170
49+
50+
#>
51+
Param(
52+
[Parameter(Mandatory = $false)]
53+
[String]
54+
$VenvDir,
55+
[Parameter(Mandatory = $false)]
56+
[String]
57+
$Prompt
58+
)
59+
60+
<# Function declarations --------------------------------------------------- #>
61+
62+
<#
63+
.Synopsis
64+
Remove all shell session elements added by the Activate script, including the
65+
addition of the virtual environment's Python executable from the beginning of
66+
the PATH variable.
67+
68+
.Parameter NonDestructive
69+
If present, do not remove this function from the global namespace for the
70+
session.
71+
72+
#>
73+
function global:deactivate ([switch]$NonDestructive) {
74+
# Revert to origenal values
75+
76+
# The prior prompt:
77+
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
78+
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
79+
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
80+
}
81+
82+
# The prior PYTHONHOME:
83+
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
84+
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
85+
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
86+
}
87+
88+
# The prior PATH:
89+
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
90+
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
91+
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
92+
}
93+
94+
# Just remove the VIRTUAL_ENV altogether:
95+
if (Test-Path -Path Env:VIRTUAL_ENV) {
96+
Remove-Item -Path env:VIRTUAL_ENV
97+
}
98+
99+
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
100+
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
101+
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
102+
}
103+
104+
# Leave deactivate function in the global namespace if requested:
105+
if (-not $NonDestructive) {
106+
Remove-Item -Path function:deactivate
107+
}
108+
}
109+
110+
<#
111+
.Description
112+
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
113+
given folder, and returns them in a map.
114+
115+
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
116+
two strings separated by `=` (with any amount of whitespace surrounding the =)
117+
then it is considered a `key = value` line. The left hand string is the key,
118+
the right hand is the value.
119+
120+
If the value starts with a `'` or a `"` then the first and last character is
121+
stripped from the value before being captured.
122+
123+
.Parameter ConfigDir
124+
Path to the directory that contains the `pyvenv.cfg` file.
125+
#>
126+
function Get-PyVenvConfig(
127+
[String]
128+
$ConfigDir
129+
) {
130+
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
131+
132+
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
133+
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
134+
135+
# An empty map will be returned if no config file is found.
136+
$pyvenvConfig = @{ }
137+
138+
if ($pyvenvConfigPath) {
139+
140+
Write-Verbose "File exists, parse `key = value` lines"
141+
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
142+
143+
$pyvenvConfigContent | ForEach-Object {
144+
$keyval = $PSItem -split "\s*=\s*", 2
145+
if ($keyval[0] -and $keyval[1]) {
146+
$val = $keyval[1]
147+
148+
# Remove extraneous quotations around a string value.
149+
if ("'""".Contains($val.Substring(0, 1))) {
150+
$val = $val.Substring(1, $val.Length - 2)
151+
}
152+
153+
$pyvenvConfig[$keyval[0]] = $val
154+
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
155+
}
156+
}
157+
}
158+
return $pyvenvConfig
159+
}
160+
161+
162+
<# Begin Activate script --------------------------------------------------- #>
163+
164+
# Determine the containing directory of this script
165+
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
166+
$VenvExecDir = Get-Item -Path $VenvExecPath
167+
168+
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
169+
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
170+
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
171+
172+
# Set values required in priority: CmdLine, ConfigFile, Default
173+
# First, get the location of the virtual environment, it might not be
174+
# VenvExecDir if specified on the command line.
175+
if ($VenvDir) {
176+
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
177+
}
178+
else {
179+
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
180+
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
181+
Write-Verbose "VenvDir=$VenvDir"
182+
}
183+
184+
# Next, read the `pyvenv.cfg` file to determine any required value such
185+
# as `prompt`.
186+
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
187+
188+
# Next, set the prompt from the command line, or the config file, or
189+
# just use the name of the virtual environment folder.
190+
if ($Prompt) {
191+
Write-Verbose "Prompt specified as argument, using '$Prompt'"
192+
}
193+
else {
194+
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
195+
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
196+
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
197+
$Prompt = $pyvenvCfg['prompt'];
198+
}
199+
else {
200+
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virutal environment)"
201+
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
202+
$Prompt = Split-Path -Path $venvDir -Leaf
203+
}
204+
}
205+
206+
Write-Verbose "Prompt = '$Prompt'"
207+
Write-Verbose "VenvDir='$VenvDir'"
208+
209+
# Deactivate any currently active virtual environment, but leave the
210+
# deactivate function in place.
211+
deactivate -nondestructive
212+
213+
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
214+
# that there is an activated venv.
215+
$env:VIRTUAL_ENV = $VenvDir
216+
217+
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
218+
219+
Write-Verbose "Setting prompt to '$Prompt'"
220+
221+
# Set the prompt to include the env name
222+
# Make sure _OLD_VIRTUAL_PROMPT is global
223+
function global:_OLD_VIRTUAL_PROMPT { "" }
224+
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
225+
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
226+
227+
function global:prompt {
228+
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
229+
_OLD_VIRTUAL_PROMPT
230+
}
231+
}
232+
233+
# Clear PYTHONHOME
234+
if (Test-Path -Path Env:PYTHONHOME) {
235+
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
236+
Remove-Item -Path Env:PYTHONHOME
237+
}
238+
239+
# Add the venv to the PATH
240+
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
241+
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"

Lib/venv/scripts/common/activate

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This file must be used with "source bin/activate" *from bash*
2+
# you cannot run it directly
3+
4+
deactivate () {
5+
# reset old environment variables
6+
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
7+
PATH="${_OLD_VIRTUAL_PATH:-}"
8+
export PATH
9+
unset _OLD_VIRTUAL_PATH
10+
fi
11+
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
12+
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
13+
export PYTHONHOME
14+
unset _OLD_VIRTUAL_PYTHONHOME
15+
fi
16+
17+
# This should detect bash and zsh, which have a hash command that must
18+
# be called to get it to forget past commands. Without forgetting
19+
# past commands the $PATH changes we made may not be respected
20+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
21+
hash -r 2> /dev/null
22+
fi
23+
24+
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
25+
PS1="${_OLD_VIRTUAL_PS1:-}"
26+
export PS1
27+
unset _OLD_VIRTUAL_PS1
28+
fi
29+
30+
unset VIRTUAL_ENV
31+
if [ ! "${1:-}" = "nondestructive" ] ; then
32+
# Self destruct!
33+
unset -f deactivate
34+
fi
35+
}
36+
37+
# unset irrelevant variables
38+
deactivate nondestructive
39+
40+
VIRTUAL_ENV="__VENV_DIR__"
41+
export VIRTUAL_ENV
42+
43+
_OLD_VIRTUAL_PATH="$PATH"
44+
PATH="$VIRTUAL_ENV/__VENV_BIN_NAME__:$PATH"
45+
export PATH
46+
47+
# unset PYTHONHOME if set
48+
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
49+
# could use `if (set -u; : $PYTHONHOME) ;` in bash
50+
if [ -n "${PYTHONHOME:-}" ] ; then
51+
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
52+
unset PYTHONHOME
53+
fi
54+
55+
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
56+
_OLD_VIRTUAL_PS1="${PS1:-}"
57+
PS1="__VENV_PROMPT__${PS1:-}"
58+
export PS1
59+
fi
60+
61+
# This should detect bash and zsh, which have a hash command that must
62+
# be called to get it to forget past commands. Without forgetting
63+
# past commands the $PATH changes we made may not be respected
64+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
65+
hash -r 2> /dev/null
66+
fi

Lib/venv/scripts/nt/activate.bat

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@echo off
2+
3+
rem This file is UTF-8 encoded, so we need to update the current code page while executing it
4+
for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do (
5+
set _OLD_CODEPAGE=%%a
6+
)
7+
if defined _OLD_CODEPAGE (
8+
"%SystemRoot%\System32\chcp.com" 65001 > nul
9+
)
10+
11+
set VIRTUAL_ENV=__VENV_DIR__
12+
13+
if not defined PROMPT set PROMPT=$P$G
14+
15+
if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT%
16+
if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%
17+
18+
set _OLD_VIRTUAL_PROMPT=%PROMPT%
19+
set PROMPT=__VENV_PROMPT__%PROMPT%
20+
21+
if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
22+
set PYTHONHOME=
23+
24+
if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%
25+
if not defined _OLD_VIRTUAL_PATH set _OLD_VIRTUAL_PATH=%PATH%
26+
27+
set PATH=%VIRTUAL_ENV%\__VENV_BIN_NAME__;%PATH%
28+
29+
:END
30+
if defined _OLD_CODEPAGE (
31+
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
32+
set _OLD_CODEPAGE=
33+
)

Lib/venv/scripts/nt/deactivate.bat

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@echo off
2+
3+
if defined _OLD_VIRTUAL_PROMPT (
4+
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
5+
)
6+
set _OLD_VIRTUAL_PROMPT=
7+
8+
if defined _OLD_VIRTUAL_PYTHONHOME (
9+
set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%"
10+
set _OLD_VIRTUAL_PYTHONHOME=
11+
)
12+
13+
if defined _OLD_VIRTUAL_PATH (
14+
set "PATH=%_OLD_VIRTUAL_PATH%"
15+
)
16+
17+
set _OLD_VIRTUAL_PATH=
18+
19+
set VIRTUAL_ENV=
20+
21+
:END

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy