Skip to content

Commit 1ce93da

Browse files
committed
Add --with-tzpath to autoconf
This is configurable only on POSIX systems at the moment and TZPATH is initialized to an empty string on Windows.
1 parent 93452b2 commit 1ce93da

File tree

6 files changed

+102
-10
lines changed

6 files changed

+102
-10
lines changed

Lib/sysconfig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ def get_config_vars(*args):
546546

547547
if os.name == 'nt':
548548
_init_non_posix(_CONFIG_VARS)
549+
_CONFIG_VARS['TZPATH'] = ''
549550
if os.name == 'posix':
550551
_init_posix(_CONFIG_VARS)
551552
# For backward compatibility, see issue19555

Lib/zoneinfo/_tzpath.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
import sysconfig
34

45

56
def reset_tzpath(to=None):
@@ -19,17 +20,10 @@ def reset_tzpath(to=None):
1920
env_var = os.environ.get("PYTHONTZPATH", None)
2021
if env_var is not None:
2122
base_tzpath = _parse_python_tzpath(env_var)
22-
elif sys.platform != "win32":
23-
base_tzpath = [
24-
"/usr/share/zoneinfo",
25-
"/usr/lib/zoneinfo",
26-
"/usr/share/lib/zoneinfo",
27-
"/etc/zoneinfo",
28-
]
29-
30-
base_tzpath.sort(key=lambda x: not os.path.exists(x))
3123
else:
32-
base_tzpath = ()
24+
base_tzpath = _parse_python_tzpath(
25+
sysconfig.get_config_var("TZPATH")
26+
)
3327

3428
TZPATH = tuple(base_tzpath)
3529

Makefile.pre.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ OPENSSL_INCLUDES=@OPENSSL_INCLUDES@
197197
OPENSSL_LIBS=@OPENSSL_LIBS@
198198
OPENSSL_LDFLAGS=@OPENSSL_LDFLAGS@
199199

200+
# Default zoneinfo.TZPATH. Added here to expose it in sysconfig.get_config_var
201+
TZPATH=@TZPATH@
202+
200203
# Modes for directories, executables and data files created by the
201204
# install process. Default to user-only-writable for all file types.
202205
DIRMODE= 755

configure

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ LIBFFI_INCLUDEDIR
658658
PKG_CONFIG_LIBDIR
659659
PKG_CONFIG_PATH
660660
PKG_CONFIG
661+
TZPATH
661662
SHLIBS
662663
CFLAGSFORSHARED
663664
LINKFORSHARED
@@ -819,6 +820,7 @@ with_assertions
819820
enable_optimizations
820821
with_lto
821822
with_hash_algorithm
823+
with_tzpath
822824
with_address_sanitizer
823825
with_memory_sanitizer
824826
with_undefined_behavior_sanitizer
@@ -1524,6 +1526,9 @@ Optional Packages:
15241526
--with-hash-algorithm=[fnv|siphash24]
15251527
select hash algorithm for use in Python/pyhash.c
15261528
(default is SipHash24)
1529+
--with-tzpath=<list of absolute paths separated by pathsep>
1530+
Select the default time zone search path for zoneinfo.TZPATH
1531+
15271532
--with-address-sanitizer
15281533
enable AddressSanitizer memory error detector,
15291534
'asan' (default is no)
@@ -10150,6 +10155,47 @@ $as_echo "default" >&6; }
1015010155
fi
1015110156

1015210157

10158+
validate_tzpath() {
10159+
# Checks that each element of hte path is an absolute path
10160+
if test -z "$1"; then
10161+
# Empty string is allowed: it indicates no system TZPATH
10162+
return 0
10163+
fi
10164+
10165+
# Bad paths are those that don't start with /
10166+
if ( echo $1 | grep -qE '(^|:)([^/]|$)' ); then
10167+
as_fn_error $? "--with-tzpath must contain only absolute paths, not $1" "$LINENO" 5
10168+
return 1;
10169+
fi
10170+
}
10171+
10172+
TZPATH="/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo"
10173+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-tzpath" >&5
10174+
$as_echo_n "checking for --with-tzpath... " >&6; }
10175+
10176+
# Check whether --with-tzpath was given.
10177+
if test "${with_tzpath+set}" = set; then :
10178+
withval=$with_tzpath;
10179+
case "$withval" in
10180+
yes)
10181+
as_fn_error $? "--with-tzpath requires a value" "$LINENO" 5
10182+
;;
10183+
*)
10184+
validate_tzpath "$withval"
10185+
TZPATH="$withval"
10186+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: \"$withval\"" >&5
10187+
$as_echo "\"$withval\"" >&6; }
10188+
;;
10189+
esac
10190+
10191+
else
10192+
validate_tzpath "$TZPATH"
10193+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: \"$TZPATH\"" >&5
10194+
$as_echo "\"$TZPATH\"" >&6; }
10195+
fi
10196+
10197+
10198+
1015310199
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-address-sanitizer" >&5
1015410200
$as_echo_n "checking for --with-address-sanitizer... " >&6; }
1015510201

configure.ac

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,6 +2946,42 @@ esac
29462946
],
29472947
[AC_MSG_RESULT(default)])
29482948

2949+
validate_tzpath() {
2950+
# Checks that each element of hte path is an absolute path
2951+
if test -z "$1"; then
2952+
# Empty string is allowed: it indicates no system TZPATH
2953+
return 0
2954+
fi
2955+
2956+
# Bad paths are those that don't start with /
2957+
dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
2958+
if ( echo $1 | grep -qE '(^|:)(@<:@^/@:>@|$)' ); then
2959+
AC_MSG_ERROR([--with-tzpath must contain only absolute paths, not $1])
2960+
return 1;
2961+
fi
2962+
}
2963+
2964+
TZPATH="/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo"
2965+
AC_MSG_CHECKING(for --with-tzpath)
2966+
AC_ARG_WITH(tzpath,
2967+
AS_HELP_STRING([--with-tzpath=<list of absolute paths separated by pathsep>]
2968+
[Select the default time zone search path for zoneinfo.TZPATH]),
2969+
[
2970+
case "$withval" in
2971+
yes)
2972+
AC_MSG_ERROR([--with-tzpath requires a value])
2973+
;;
2974+
*)
2975+
validate_tzpath "$withval"
2976+
TZPATH="$withval"
2977+
AC_MSG_RESULT("$withval")
2978+
;;
2979+
esac
2980+
],
2981+
[validate_tzpath "$TZPATH"
2982+
AC_MSG_RESULT("$TZPATH")])
2983+
AC_SUBST(TZPATH)
2984+
29492985
AC_MSG_CHECKING(for --with-address-sanitizer)
29502986
AC_ARG_WITH(address_sanitizer,
29512987
AS_HELP_STRING([--with-address-sanitizer],

setup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ def find_library_file(compiler, libname, std_dirs, paths):
304304
else:
305305
assert False, "Internal error: Path not found in std_dirs or paths"
306306

307+
def validate_tzpath():
308+
base_tzpath = sysconfig.get_config_var('TZPATH')
309+
if not base_tzpath:
310+
return
311+
312+
tzpaths = base_tzpath.split(os.pathsep)
313+
bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
314+
if bad_paths:
315+
raise ValueError('TZPATH must contain only absolute paths, '
316+
+ f'found:\n{tzpaths!r}\nwith invalid paths:\n'
317+
+ f'{bad_paths!r}')
307318

308319
def find_module_file(module, dirlist):
309320
"""Find a module in a set of possible folders. If it is not found
@@ -2451,6 +2462,7 @@ class DummyProcess:
24512462
ProcessPoolExecutor = None
24522463

24532464
sys.modules['concurrent.futures.process'] = DummyProcess
2465+
validate_tzpath()
24542466

24552467
# turn off warnings when deprecated modules are imported
24562468
import warnings

0 commit comments

Comments
 (0)