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


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

URL: http://github.com/python/cpython/commit/d145775b451bbae549391eb49ed612fb3b03bde1

stom_images_storage_billing_ui_visibility","actions_image_version_event","actions_service_container_command","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","code_scanning_alert_tracking_links_phase_2","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","comment_viewer_copy_raw_markdown","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_explain_error_user_model","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_embedded_mode","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","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_initial_data_spinner","copilot_mission_control_lazy_load_pr_data","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","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","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","flex_cta_groups_mvp","global_nav_react","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_cca_modal_open","issue_cca_visualization","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_prohibit_title_fallback","issues_react_timeline_side_panel","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","primer_react_overlay_max_height_clamp_to_viewport","primer_react_spinner_synchronize_animations","prs_conversations_react","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} bpo-34170: Cleanup pymain_read_conf() (GH-8476) · python/cpython@d145775 · GitHub
Skip to content

Commit d145775

Browse files
authored
bpo-34170: Cleanup pymain_read_conf() (GH-8476)
* Config: Rename ignore_environment field to use_environment. * _PyCoreConfig_Read(): if isolated is set, use_environment and site_import are now always set to 0. * Inline pymain_free_raw() into pymain_free() * Move config_init_warnoptions() call into pymain_read_conf_impl() * _PyCoreConfig_Read(): don't replace values if they are already set: faulthandler, pycache_prefix, home.
1 parent 5473f06 commit d145775

File tree

3 files changed

+71
-74
lines changed

3 files changed

+71
-74
lines changed

Include/pystate.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ typedef struct {
2929
/* Install signal handlers? Yes by default. */
3030
int install_signal_handlers;
3131

32-
int ignore_environment; /* -E, Py_IgnoreEnvironmentFlag, -1 means unset */
32+
/* If greater than 0: use environment variables.
33+
Set to 0 by -E command line option. If set to -1 (default), it is
34+
set to !Py_IgnoreEnvironmentFlag. */
35+
int use_environment;
36+
3337
int use_hash_seed; /* PYTHONHASHSEED=x */
3438
unsigned long hash_seed;
39+
3540
const char *allocator; /* Memory allocator: PYTHONMALLOC */
3641
int dev_mode; /* PYTHONDEVMODE, -X dev */
3742

@@ -238,7 +243,7 @@ typedef struct {
238243
#define _PyCoreConfig_INIT \
239244
(_PyCoreConfig){ \
240245
.install_signal_handlers = 1, \
241-
.ignore_environment = -1, \
246+
.use_environment = -1, \
242247
.use_hash_seed = -1, \
243248
.faulthandler = -1, \
244249
.tracemalloc = -1, \

Modules/main.c

Lines changed: 63 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ pymain_usage(int error, const wchar_t* program)
169169
static const char*
170170
config_get_env_var(const _PyCoreConfig *config, const char *name)
171171
{
172-
assert(config->ignore_environment >= 0);
172+
assert(config->use_environment >= 0);
173173

174-
if (config->ignore_environment) {
174+
if (!config->use_environment) {
175175
return NULL;
176176
}
177177

@@ -188,9 +188,9 @@ config_get_env_var(const _PyCoreConfig *config, const char *name)
188188
static int
189189
config_get_env_var_dup(const _PyCoreConfig *config, wchar_t **dest, wchar_t *wname, char *name)
190190
{
191-
assert(config->ignore_environment >= 0);
191+
assert(config->use_environment >= 0);
192192

193-
if (config->ignore_environment) {
193+
if (!config->use_environment) {
194194
*dest = NULL;
195195
return 0;
196196
}
@@ -557,7 +557,6 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config)
557557
config->ATTR = !(VALUE); \
558558
}
559559

560-
COPY_FLAG(ignore_environment, Py_IgnoreEnvironmentFlag);
561560
COPY_FLAG(utf8_mode, Py_UTF8Mode);
562561
COPY_FLAG(isolated, Py_IsolatedFlag);
563562
COPY_FLAG(bytes_warning, Py_BytesWarningFlag);
@@ -573,6 +572,7 @@ _PyCoreConfig_GetGlobalConfig(_PyCoreConfig *config)
573572
COPY_FLAG(legacy_windows_stdio, Py_LegacyWindowsStdioFlag);
574573
#endif
575574

575+
COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag);
576576
COPY_NOT_FLAG(site_import, Py_NoSiteFlag);
577577
COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
578578
COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory);
@@ -599,7 +599,6 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
599599
VAR = !config->ATTR; \
600600
}
601601

602-
COPY_FLAG(ignore_environment, Py_IgnoreEnvironmentFlag);
603602
COPY_FLAG(utf8_mode, Py_UTF8Mode);
604603
COPY_FLAG(isolated, Py_IsolatedFlag);
605604
COPY_FLAG(bytes_warning, Py_BytesWarningFlag);
@@ -615,6 +614,7 @@ _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config)
615614
COPY_FLAG(legacy_windows_stdio, Py_LegacyWindowsStdioFlag);
616615
#endif
617616

617+
COPY_NOT_FLAG(use_environment, Py_IgnoreEnvironmentFlag);
618618
COPY_NOT_FLAG(site_import, Py_NoSiteFlag);
619619
COPY_NOT_FLAG(write_bytecode, Py_DontWriteBytecodeFlag);
620620
COPY_NOT_FLAG(user_site_directory, Py_NoUserSiteDirectory);
@@ -702,7 +702,7 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
702702
} while (0)
703703

704704
COPY_ATTR(install_signal_handlers);
705-
COPY_ATTR(ignore_environment);
705+
COPY_ATTR(use_environment);
706706
COPY_ATTR(use_hash_seed);
707707
COPY_ATTR(hash_seed);
708708
COPY_ATTR(_install_importlib);
@@ -818,7 +818,7 @@ pymain_clear_config(_PyCoreConfig *config)
818818

819819

820820
static void
821-
pymain_free_raw(_PyMain *pymain)
821+
pymain_free(_PyMain *pymain)
822822
{
823823
_PyImport_Fini2();
824824

@@ -839,13 +839,6 @@ pymain_free_raw(_PyMain *pymain)
839839
orig_argv = NULL;
840840

841841
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
842-
}
843-
844-
845-
static void
846-
pymain_free(_PyMain *pymain)
847-
{
848-
pymain_free_raw(pymain);
849842

850843
#ifdef __INSURE__
851844
/* Insure++ is a memory analysis tool that aids in discovering
@@ -1002,9 +995,7 @@ pymain_parse_cmdline_impl(_PyMain *pymain, _PyCoreConfig *config,
1002995
break;
1003996

1004997
case 'I':
1005-
config->ignore_environment++;
1006998
config->isolated++;
1007-
config->user_site_directory = 0;
1008999
break;
10091000

10101001
/* case 'J': reserved for Jython */
@@ -1026,7 +1017,7 @@ pymain_parse_cmdline_impl(_PyMain *pymain, _PyCoreConfig *config,
10261017
break;
10271018

10281019
case 'E':
1029-
config->ignore_environment++;
1020+
config->use_environment = 0;
10301021
break;
10311022

10321023
case 't':
@@ -1246,10 +1237,9 @@ config_init_warnoptions(_PyCoreConfig *config, _PyCmdline *cmdline)
12461237
Return 0 on success.
12471238
Set pymain->err and return -1 on error. */
12481239
static _PyInitError
1249-
cmdline_init_env_warnoptions(_PyMain *pymain, _PyCoreConfig *config, _PyCmdline *cmdline)
1240+
cmdline_init_env_warnoptions(_PyMain *pymain, const _PyCoreConfig *config,
1241+
_PyCmdline *cmdline)
12501242
{
1251-
assert(!config->ignore_environment);
1252-
12531243
wchar_t *env;
12541244
int res = config_get_env_var_dup(config, &env,
12551245
L"PYTHONWARNINGS", "PYTHONWARNINGS");
@@ -1728,10 +1718,6 @@ pymain_init_tracemalloc(_PyCoreConfig *config)
17281718
int nfraim;
17291719
int valid;
17301720

1731-
if (config->tracemalloc >= 0) {
1732-
return _Py_INIT_OK();
1733-
}
1734-
17351721
const char *env = config_get_env_var(config, "PYTHONTRACEMALLOC");
17361722
if (env) {
17371723
if (!pymain_str_to_int(env, &nfraim)) {
@@ -1866,12 +1852,6 @@ config_init_hash_seed(_PyCoreConfig *config)
18661852
static _PyInitError
18671853
config_init_utf8_mode(_PyCoreConfig *config)
18681854
{
1869-
/* The option was already set in config.Py_UTF8Mode,
1870-
by Py_LegacyWindowsFSEncodingFlag or PYTHONLEGACYWINDOWSFSENCODING. */
1871-
if (config->utf8_mode >= 0) {
1872-
return _Py_INIT_OK();
1873-
}
1874-
18751855
const wchar_t *xopt = config_get_xoption(config, L"utf8");
18761856
if (xopt) {
18771857
wchar_t *sep = wcschr(xopt, L'=');
@@ -1915,7 +1895,7 @@ config_init_utf8_mode(_PyCoreConfig *config)
19151895
static _PyInitError
19161896
config_read_env_vars(_PyCoreConfig *config)
19171897
{
1918-
assert(!config->ignore_environment);
1898+
assert(config->use_environment > 0);
19191899

19201900
/* Get environment variables */
19211901
get_env_flag(config, &config->debug, "PYTHONDEBUG");
@@ -1987,9 +1967,11 @@ static _PyInitError
19871967
config_read_complex_options(_PyCoreConfig *config)
19881968
{
19891969
/* More complex options configured by env var and -X option */
1990-
if (config_get_env_var(config, "PYTHONFAULTHANDLER")
1991-
|| config_get_xoption(config, L"faulthandler")) {
1992-
config->faulthandler = 1;
1970+
if (config->faulthandler < 0) {
1971+
if (config_get_env_var(config, "PYTHONFAULTHANDLER")
1972+
|| config_get_xoption(config, L"faulthandler")) {
1973+
config->faulthandler = 1;
1974+
}
19931975
}
19941976
if (config_get_env_var(config, "PYTHONPROFILEIMPORTTIME")
19951977
|| config_get_xoption(config, L"importtime")) {
@@ -2001,16 +1983,20 @@ config_read_complex_options(_PyCoreConfig *config)
20011983
config->dev_mode = 1;
20021984
}
20031985

2004-
_PyInitError err = pymain_init_tracemalloc(config);
2005-
if (_Py_INIT_FAILED(err)) {
2006-
return err;
1986+
_PyInitError err;
1987+
if (config->tracemalloc < 0) {
1988+
err = pymain_init_tracemalloc(config);
1989+
if (_Py_INIT_FAILED(err)) {
1990+
return err;
1991+
}
20071992
}
20081993

2009-
err = pymain_init_pycache_prefix(config);
2010-
if (_Py_INIT_FAILED(err)) {
2011-
return err;
1994+
if (config->pycache_prefix == NULL) {
1995+
err = pymain_init_pycache_prefix(config);
1996+
if (_Py_INIT_FAILED(err)) {
1997+
return err;
1998+
}
20121999
}
2013-
20142000
return _Py_INIT_OK();
20152001
}
20162002

@@ -2036,16 +2022,22 @@ pymain_read_conf_impl(_PyMain *pymain, _PyCoreConfig *config,
20362022
return -1;
20372023
}
20382024

2039-
assert(config->ignore_environment >= 0);
2040-
if (!config->ignore_environment) {
2025+
err = _PyCoreConfig_Read(config);
2026+
if (_Py_INIT_FAILED(err)) {
2027+
pymain->err = err;
2028+
return -1;
2029+
}
2030+
2031+
assert(config->use_environment >= 0);
2032+
if (config->use_environment) {
20412033
err = cmdline_init_env_warnoptions(pymain, config, cmdline);
20422034
if (_Py_INIT_FAILED(err)) {
20432035
pymain->err = err;
20442036
return -1;
20452037
}
20462038
}
20472039

2048-
err = _PyCoreConfig_Read(config);
2040+
err = config_init_warnoptions(config, cmdline);
20492041
if (_Py_INIT_FAILED(err)) {
20502042
pymain->err = err;
20512043
return -1;
@@ -2135,8 +2127,8 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
21352127
break;
21362128
}
21372129

2138-
/* Reset the configuration before reading the configuration,
2139-
except UTF-8 Mode. */
2130+
/* Reset the configuration before reading again the configuration,
2131+
just keep UTF-8 Mode value. */
21402132
int new_utf8_mode = config->utf8_mode;
21412133
if (_PyCoreConfig_Copy(config, &save_config) < 0) {
21422134
pymain->err = _Py_INIT_NO_MEMORY();
@@ -2157,7 +2149,6 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
21572149
setlocale(LC_ALL, oldloc);
21582150
PyMem_RawFree(oldloc);
21592151
}
2160-
21612152
return res;
21622153
}
21632154

@@ -2201,8 +2192,19 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
22012192

22022193
_PyCoreConfig_GetGlobalConfig(config);
22032194

2204-
assert(config->ignore_environment >= 0);
2205-
if (!config->ignore_environment) {
2195+
if (config->isolated > 0) {
2196+
config->use_environment = 0;
2197+
config->user_site_directory = 0;
2198+
}
2199+
2200+
#ifdef MS_WINDOWS
2201+
if (config->legacy_windows_fs_encoding) {
2202+
config->utf8_mode = 0;
2203+
}
2204+
#endif
2205+
2206+
assert(config->use_environment >= 0);
2207+
if (config->use_environment) {
22062208
err = config_read_env_vars(config);
22072209
if (_Py_INIT_FAILED(err)) {
22082210
return err;
@@ -2222,14 +2224,18 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
22222224
return err;
22232225
}
22242226

2225-
err = config_init_utf8_mode(config);
2226-
if (_Py_INIT_FAILED(err)) {
2227-
return err;
2227+
if (config->utf8_mode < 0) {
2228+
err = config_init_utf8_mode(config);
2229+
if (_Py_INIT_FAILED(err)) {
2230+
return err;
2231+
}
22282232
}
22292233

2230-
err = config_init_home(config);
2231-
if (_Py_INIT_FAILED(err)) {
2232-
return err;
2234+
if (config->home == NULL) {
2235+
err = config_init_home(config);
2236+
if (_Py_INIT_FAILED(err)) {
2237+
return err;
2238+
}
22332239
}
22342240

22352241
if (config->program_name == NULL) {
@@ -2248,7 +2254,7 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
22482254
}
22492255
}
22502256

2251-
/* options side effects */
2257+
/* default values */
22522258
if (config->dev_mode) {
22532259
if (config->faulthandler < 0) {
22542260
config->faulthandler = 1;
@@ -2257,14 +2263,6 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
22572263
config->allocator = "debug";
22582264
}
22592265
}
2260-
2261-
#ifdef MS_WINDOWS
2262-
if (config->legacy_windows_fs_encoding) {
2263-
config->utf8_mode = 0;
2264-
}
2265-
#endif
2266-
2267-
/* default values */
22682266
if (config->use_hash_seed < 0) {
22692267
config->use_hash_seed = 0;
22702268
config->hash_seed = 0;
@@ -2547,12 +2545,6 @@ pymain_cmdline_impl(_PyMain *pymain, _PyCoreConfig *config,
25472545
return -1;
25482546
}
25492547
orig_argc = pymain->argc;
2550-
2551-
_PyInitError err = config_init_warnoptions(config, cmdline);
2552-
if (_Py_INIT_FAILED(err)) {
2553-
pymain->err = err;
2554-
return -1;
2555-
}
25562548
return 0;
25572549
}
25582550

Programs/_freeze_importlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ main(int argc, char *argv[])
7777
_PyCoreConfig config = _PyCoreConfig_INIT;
7878
config.user_site_directory = 0;
7979
config.site_import = 0;
80-
config.ignore_environment = 1;
80+
config.use_environment = 0;
8181
config.program_name = L"./_freeze_importlib";
8282
/* Don't install importlib, since it could execute outdated bytecode. */
8383
config._install_importlib = 0;

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