8000 gh-133644: remove deprecated global configuration variables by picnixz · Pull Request #133654 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-133644: remove deprecated global configuration variables #133654

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

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
12f494a
remove `Py_BytesWarningFlag`
picnixz May 8, 2025
a6467f8
remove `Py_DebugFlag`
picnixz May 8, 2025
df48806
remove `Py_VerboseFlag`
picnixz May 8, 2025
cfabb22
remove `Py_QuietFlag`
picnixz May 8, 2025
71bca31
remove `Py_InspectFlag`
picnixz May 8, 2025
7ebf7bd
remove `Py_OptimizeFlag`
picnixz May 8, 2025
2d05afe
remove `Py_NoSiteFlag`
picnixz May 8, 2025
2a8e546
remove `Py_FrozenFlag`
picnixz May 8, 2025
93eee09
remove `Py_IgnoreEnvironmentFlag`
picnixz May 8, 2025
311f95c
remove `Py_DontWriteBytecodeFlag`
picnixz May 8, 2025
f5b39db
remove `Py_NoUserSiteDirectory`
picnixz May 8, 2025
c66edb3
remove `Py_UnbufferedStdioFlag`
picnixz May 8, 2025
9116a65
remove `Py_HashRandomizationFlag`
picnixz May 8, 2025
fb2a247
remove `Py_IsolatedFlag`
picnixz May 8, 2025
86c0c87
remove `Py_LegacyWindowsFSEncodingFlag`
picnixz May 8, 2025
eab9e01
remove `Py_LegacyWindowsStdioFlag`
picnixz May 8, 2025
54ff2aa
remove `Py_FileSystemDefaultEncoding` and `Py_HasFileSystemDefaultEnc…
picnixz May 8, 2025
9a322fe
remove `Py_FileSystemDefaultEncodeErrors`
picnixz May 8, 2025
d4ff0f7
fix test_embed
picnixz May 8, 2025
5d59540
blurb
picnixz May 8, 2025
eef039e
update What's New entries
picnixz May 8, 2025
1248cea
update docs
picnixz May 8, 2025
583bafb
update docutils refs
picnixz May 8, 2025
daa1e2d
fixup
picnixz May 8, 2025
6c7baa2
revert `putenv` statements
picnixz May 8, 2025
d9f4def
restore file
picnixz May 8, 2025
279ac00
update stable ABI symbols
picnixz May 8, 2025
cddebbe
revert runtime changes for now
picnixz May 8, 2025
b8afe23
Merge remote-tracking branch 'upstream/main' into cleanup/315/depreca…
picnixz May 9, 2025
8a2173f
Merge remote-tracking branch 'upstream/main' into cleanup/315/depreca…
picnixz Jun 2, 2025
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
Prev Previous commit
Next Next commit
revert runtime changes for now
  • Loading branch information
picnixz committed May 8, 2025
commit cddebbeee651a6e4aa3e02a46f0761094a7907ce
3 changes: 3 additions & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Include/cpython/initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ typedef struct PyPreConfig {
/* If greater than 0, enable isolated mode: sys.path contains
neither the script's directory nor the user's site-packages directory.

Set to 1 by the -I command 8000 line option. */
Set to 1 by the -I command line option. If set to -1 (default), inherit
Py_IsolatedFlag value. */
int isolated;

/* If greater than 0: use environment variables.
Set to 0 by -E command line option. */
Set to 0 by -E command line option. If set to -1 (default), it is
set to !Py_IgnoreEnvironmentFlag. */
int use_environment;

/* Set the LC_CTYPE locale to the user preferred locale? If equals to 0,
Expand Down Expand Up @@ -91,7 +93,8 @@ typedef struct PyPreConfig {
encoding for the filesystem encoding.

Set to 1 if the PYTHONLEGACYWINDOWSFSENCODING environment variable is
set to a non-empty string.
set to a non-empty string. If set to -1 (default), inherit
Py_LegacyWindowsFSEncodingFlag value.

See PEP 529 for more details. */
int legacy_windows_fs_encoding;
Expand Down
21 changes: 20 additions & 1 deletion Include/cpython/pydebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,29 @@
extern "C" {
#endif

Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_DebugFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_VerboseFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_QuietFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_InteractiveFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_InspectFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_OptimizeFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_NoSiteFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_BytesWarningFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_FrozenFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_DontWriteBytecodeFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_NoUserSiteDirectory;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_UnbufferedStdioFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_HashRandomizationFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_IsolatedFlag;

#ifdef MS_WINDOWS
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_LegacyWindowsFSEncodingFlag;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_LegacyWindowsStdioFlag;
#endif

/* this is a wrapper around getenv() that pays attention to
PyConfig.use_environment. It should be used for getting variables like
Py_IgnoreEnvironmentFlag. It should be used for getting variables like
PYTHONPATH and PYTHONHOME from the environment */
PyAPI_FUNC(char*) Py_GETENV(const char *name);

Expand Down
9 changes: 9 additions & 0 deletions Include/fileobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);

/* The default encoding used by the platform file system APIs
If non-NULL, this is different than the default encoding for strings
*/
Py_DEPRECATED(3.12) PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
Py_DEPRECATED(3.12) PyAPI_DATA(const char *) Py_FileSystemDefaultEncodeErrors;
#endif
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_HasFileSystemDefaultEncoding;

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_UTF8Mode;
#endif
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_fileutils.h
A373
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ extern int _Py_open_osfhandle(void *handle, int flags);
? _PyStatus_ERR("cannot decode " NAME) \
: _PyStatus_NO_MEMORY()

extern int _Py_HasFileSystemDefaultEncodeErrors;

extern int _Py_DecodeUTF8Ex(
const char *arg,
Py_ssize_t arglen,
Expand Down
4 changes: 4 additions & 0 deletions Include/internal/pycore_pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ extern "C" {
/* Forward declarations */
struct _PyArgv;

extern int _Py_SetFileSystemEncoding(
const char *encoding,
const char *errors);
extern void _Py_ClearFileSystemEncoding(void);
extern PyStatus _PyUnicode_InitEncodings(PyThreadState *tstate);
#ifdef MS_WINDOWS
extern int _PyUnicode_EnableLegacyWindowsFSEncoding(void);
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_ctypes/test_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def test_undefined(self):
class PythonValuesTestCase(unittest.TestCase):
"""This test only works when python itself is a dll/shared library"""

def test_optimizeflag(self):
# This test accesses the Py_OptimizeFlag integer, which is
# exported by the Python dll and should match the sys.flags value

opt = c_int.in_dll(pythonapi, "Py_OptimizeFlag").value
self.assertEqual(opt, sys.flags.optimize)

@thread_unsafe('overrides frozen modules')
def test_frozentable(self):
# Python exports a PyImport_FrozenModules symbol. This is a
Expand Down
43 changes: 41 additions & 2 deletions Lib/test/test_embed.py
10000
Original file line number Diff line number Diff line change
Expand Up @@ -689,14 +689,41 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
CONFIG_ISOLATED['legacy_windows_stdio'] = False

# global config
DEFAULT_GLOBAL_CONFIG = {
'Py_HasFileSystemDefaultEncoding': 0,
'Py_HashRandomizationFlag': 1,
'_Py_HasFileSystemDefaultEncodeErrors': 0,
}
COPY_GLOBAL_PRE_CONFIG = [
('Py_UTF8Mode', 'utf8_mode'),
]
COPY_GLOBAL_CONFIG = [
# Copy core config to global config for expected values
# True means that the core config value is inverted (0 => 1 and 1 => 0)
('Py_BytesWarningFlag', 'bytes_warning'),
('Py_DebugFlag', 'parser_debug'),
('Py_DontWriteBytecodeFlag', 'write_bytecode', True),
('Py_FileSystemDefaultEncodeErrors', 'filesystem_errors'),
('Py_FileSystemDefaultEncoding', 'filesystem_encoding'),
('Py_FrozenFlag', 'pathconfig_warnings', True),
('Py_IgnoreEnvironmentFlag', 'use_environment', True),
('Py_InspectFlag', 'inspect'),
('Py_InteractiveFlag', 'interactive'),
('Py_IsolatedFlag', 'isolated'),
('Py_NoSiteFlag', 'site_import', True),
('Py_NoUserSiteDirectory', 'user_site_directory', True),
('Py_OptimizeFlag', 'optimization_level'),
('Py_QuietFlag', 'quiet'),
('Py_UnbufferedStdioFlag', 'buffered_stdio', True),
('Py_VerboseFlag', 'verbose'),
]
if MS_WINDOWS:
COPY_GLOBAL_PRE_CONFIG.extend((
('Py_LegacyWindowsFSEncodingFlag', 'legacy_windows_fs_encoding'),
))
COPY_GLOBAL_CONFIG.extend((
('Py_LegacyWindowsStdioFlag', 'legacy_windows_stdio'),
))

EXPECTED_CONFIG = None

Expand Down Expand Up @@ -831,7 +858,7 @@ def check_pre_config(self, configs, expected):
if value is self.IGNORE_CONFIG:
pre_config.pop(key, None)
del expected[key]
self.assertDictEqual(pre_config, expected)
self.assertEqual(pre_config, expected)

def check_config(self, configs, expected):
config = dict(configs['config'])
Expand All @@ -855,7 +882,7 @@ def check_global_config(self, configs):
pre_config = configs['pre_config']
config = configs['config']

expected = {}
expected = dict(self.DEFAULT_GLOBAL_CONFIG)
for item in self.COPY_GLOBAL_CONFIG:
if len(item) == 3:
global_key, core_key, opposite = item
Expand Down Expand Up @@ -943,7 +970,19 @@ def test_init_global_config(self):
}
config = {
'program_name': './globalvar',
'site_import': False,
'bytes_warning': True,
'warnoptions': ['default::BytesWarning'],
'inspect': True,
'interactive': True,
'optimization_level': 2,
'write_bytecode': False,
'verbose': True,
'quiet': True,
'buffered_stdio': False,
'remote_debug': True,
'user_site_directory': False,
'pathconfig_warnings': False,
}
self.check_all_configs("test_init_global_config", config, preconfig,
api=API_COMPAT)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_utf8_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def check(utf8_opt, expected, **kw):
check('utf8=0', [c_arg], LC_ALL=loc)

def test_optim_level(self):
# CPython: check that Py_Main() doesn't increment PyConfig.optimize
# CPython: check that Py_Main() doesn't increment Py_OptimizeFlag
# twice when -X utf8 requires to parse the configuration twice (when
# the encoding changes after reading the configuration, the
# configuration is read again with the new encoding).
Expand Down
3 changes: 0 additions & 3 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,6 @@
added = '3.2'
[data.Py_FileSystemDefaultEncoding]
added = '3.2'
abi_only = true
[function.Py_Finalize]
added = '3.2'
[function.Py_GetBuildInfo]
Expand Down Expand Up @@ -1651,7 +1650,6 @@
added = '3.2'
[data.Py_HasFileSystemDefaultEncoding]
added = '3.2'
abi_only = true
[function.Py_IncRef]
added = '3.2'
[function.Py_Initialize]
Expand Down Expand Up @@ -2207,7 +2205,6 @@
added = '3.10'
[data.Py_FileSystemDefaultEncodeErrors]
added = '3.10'
abi_only = true
[function.PyCodec_Unregister]
added = '3.10'
[function.PyErr_SetInterruptEx]
Expand Down
4 changes: 4 additions & 0 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ static void
pymain_set_inspect(PyConfig *config, int inspect)
{
config->inspect = inspect;
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
Py_InspectFlag = inspect;
_Py_COMP_DIAG_POP
}


Expand Down
11 changes: 11 additions & 0 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -16516,6 +16516,17 @@ init_fs_codec(PyInterpreterState *interp)
/* At this point, PyUnicode_EncodeFSDefault() and
PyUnicode_DecodeFSDefault() can now use the Python codec rather than
the C implementation of the filesystem encoding. */

/* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors
global configuration variables. */
if (_Py_IsMainInterpreter(interp)) {

if (_Py_SetFileSystemEncoding(fs_codec->encoding,
fs_codec->errors) < 0) {
PyErr_NoMemory();
return -1;
}
}
return 0;
}

Expand Down
Loading
Loading
0