bpo-45582: Port getpath[p].c to getpath.py · python/cpython@a63f5d8 · GitHub
Skip to content

Commit a63f5d8

Browse files
committed
bpo-45582: Port getpath[p].c to getpath.py
1 parent ec382fa commit a63f5d8

42 files changed

Lines changed: 3488 additions & 3674 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/c-api/init_config.rst

Lines changed: 28 additions & 13 deletions

Include/cpython/fileutils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ PyAPI_FUNC(wchar_t*) _Py_wrealpath(
135135
size_t resolved_path_len);
136136
#endif
137137

138-
#ifndef MS_WINDOWS
139138
PyAPI_FUNC(int) _Py_isabs(const wchar_t *path);
140-
#endif
141139

142140
PyAPI_FUNC(int) _Py_abspath(const wchar_t *path, wchar_t **abspath_p);
143141

Include/cpython/initconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ typedef struct PyConfig {
210210
// If non-zero, disallow threads, subprocesses, and fork.
211211
// Default: 0.
212212
int _isolated_interpreter;
213+
214+
// If non-zero, we believe we're running from a source tree.
215+
int _development_env;
213216
} PyConfig;
214217

215218
PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config);

Include/internal/pycore_fileutils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ extern int _Py_EncodeNonUnicodeWchar_InPlace(
7474
Py_ssize_t size);
7575
#endif
7676

77+
extern PyAPI_FUNC(int) _Py_isabs(const wchar_t *path);
78+
extern PyAPI_FUNC(int) _Py_abspath(const wchar_t *path, wchar_t **abspath_p);
7779
extern wchar_t * _Py_join_relfile(const wchar_t *dirname,
7880
const wchar_t *relfile);
7981
extern int _Py_add_relfile(wchar_t *dirname,
8082
const wchar_t *relfile,
8183
size_t bufsize);
8284
extern size_t _Py_find_basename(const wchar_t *filename);
83-
PyAPI_FUNC(int) _Py_normalize_path(const wchar_t *path,
84-
wchar_t *buf, const size_t buf_len);
85+
PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size);
8586

8687

8788
// Macros to protect CRT calls against instant termination when passed an

Include/internal/pycore_initconfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
152152
extern PyStatus _PyConfig_Copy(
153153
PyConfig *config,
154154
const PyConfig *config2);
155-
extern PyStatus _PyConfig_InitPathConfig(
155+
PyAPI_FUNC(PyStatus) _PyConfig_InitPathConfig(
156156
PyConfig *config,
157157
int compute_path_config);
158158
extern PyStatus _PyConfig_InitImportConfig(PyConfig *config);
@@ -166,6 +166,8 @@ extern PyStatus _PyConfig_SetPyArgv(
166166
PyAPI_FUNC(PyObject*) _PyConfig_AsDict(const PyConfig *config);
167167
PyAPI_FUNC(int) _PyConfig_FromDict(PyConfig *config, PyObject *dict);
168168

169+
extern void _Py_DumpPathConfig(PyThreadState *tstate);
170+
169171

170172
/* --- Function used for testing ---------------------------------- */
171173

Include/internal/pycore_pathconfig.h

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,15 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
typedef struct _PyPathConfig {
12-
/* Full path to the Python program */
13-
wchar_t *program_full_path;
14-
wchar_t *prefix;
15-
wchar_t *exec_prefix;
16-
wchar_t *stdlib_dir;
17-
/* Set by Py_SetPath(), or computed by _PyConfig_InitPathConfig() */
18-
wchar_t *module_search_path;
19-
/* Python program name */
20-
wchar_t *program_name;
21-
/* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
22-
wchar_t *home;
23-
#ifdef MS_WINDOWS
24-
/* isolated and site_import are used to set Py_IsolatedFlag and
25-
Py_NoSiteFlag flags on Windows in read_pth_file(). These fields
26-
are ignored when their value are equal to -1 (unset). */
27-
int isolated;
28-
int site_import;
29-
/* Set when a venv is detected */
30-
wchar_t *base_executable;
31-
#endif
32-
} _PyPathConfig;
33-
34-
#ifdef MS_WINDOWS
35-
# define _PyPathConfig_INIT \
36-
{.module_search_path = NULL, \
37-
.isolated = -1, \
38-
.site_import = -1}
39-
#else
40-
# define _PyPathConfig_INIT \
41-
{.module_search_path = NULL}
42-
#endif
43-
/* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
44-
45-
PyAPI_DATA(_PyPathConfig) _Py_path_config;
46-
#ifdef MS_WINDOWS
47-
PyAPI_DATA(wchar_t*) _Py_dll_path;
48-
#endif
49-
5011
extern void _PyPathConfig_ClearGlobal(void);
12+
extern PyStatus _PyPathConfig_ReadGlobal(PyConfig *config);
13+
extern PyStatus _PyPathConfig_UpdateGlobal(const PyConfig *config);
14+
extern const wchar_t * _PyPathConfig_GetGlobalModuleSearchPath(void);
5115

52-
extern PyStatus _PyPathConfig_Calculate(
53-
_PyPathConfig *pathconfig,
54-
const PyConfig *config);
5516
extern int _PyPathConfig_ComputeSysPath0(
5617
const PyWideStringList *argv,
5718
PyObject **path0);
58-
extern PyStatus _Py_FindEnvConfigValue(
59-
FILE *env_file,
60-
const wchar_t *key,
61-
wchar_t **value_p);
62-
63-
#ifdef MS_WINDOWS
64-
extern wchar_t* _Py_GetDLLPath(void);
65-
#endif
6619

67-
extern PyStatus _PyConfig_WritePathConfig(const PyConfig *config);
68-
extern void _Py_DumpPathConfig(PyThreadState *tstate);
69-
extern PyObject* _PyPathConfig_AsDict(void);
7020

7121
#ifdef __cplusplus
7222
}

Lib/ntpath.py

Lines changed: 63 additions & 49 deletions

0 commit comments

Comments
 (0)