Skip to content

Commit

Permalink
Add --with-tzpath to autoconf
Browse files Browse the repository at this point in the history
This is configurable only on POSIX systems at the moment and TZPATH is
initialized to an empty string on Windows.
  • Loading branch information
pganssle committed May 14, 2020
1 parent 93452b2 commit 1ce93da
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 10 deletions.
1 change: 1 addition & 0 deletions Lib/sysconfig.py
Expand Up @@ -546,6 +546,7 @@ def get_config_vars(*args):

if os.name == 'nt':
_init_non_posix(_CONFIG_VARS)
_CONFIG_VARS['TZPATH'] = ''
if os.name == 'posix':
_init_posix(_CONFIG_VARS)
# For backward compatibility, see issue19555
Expand Down
14 changes: 4 additions & 10 deletions Lib/zoneinfo/_tzpath.py
@@ -1,5 +1,6 @@
import os
import sys
import sysconfig


def reset_tzpath(to=None):
Expand All @@ -19,17 +20,10 @@ def reset_tzpath(to=None):
env_var = os.environ.get("PYTHONTZPATH", None)
if env_var is not None:
base_tzpath = _parse_python_tzpath(env_var)
elif sys.platform != "win32":
base_tzpath = [
"/usr/share/zoneinfo",
"/usr/lib/zoneinfo",
"/usr/share/lib/zoneinfo",
"/etc/zoneinfo",
]

base_tzpath.sort(key=lambda x: not os.path.exists(x))
else:
base_tzpath = ()
base_tzpath = _parse_python_tzpath(
sysconfig.get_config_var("TZPATH")
)

TZPATH = tuple(base_tzpath)

Expand Down
3 changes: 3 additions & 0 deletions Makefile.pre.in
Expand Up @@ -197,6 +197,9 @@ OPENSSL_INCLUDES=@OPENSSL_INCLUDES@
OPENSSL_LIBS=@OPENSSL_LIBS@
OPENSSL_LDFLAGS=@OPENSSL_LDFLAGS@

# Default zoneinfo.TZPATH. Added here to expose it in sysconfig.get_config_var
TZPATH=@TZPATH@

# Modes for directories, executables and data files created by the
# install process. Default to user-only-writable for all file types.
DIRMODE= 755
Expand Down
46 changes: 46 additions & 0 deletions configure
Expand Up @@ -658,6 +658,7 @@ LIBFFI_INCLUDEDIR
PKG_CONFIG_LIBDIR
PKG_CONFIG_PATH
PKG_CONFIG
TZPATH
SHLIBS
CFLAGSFORSHARED
LINKFORSHARED
Expand Down Expand Up @@ -819,6 +820,7 @@ with_assertions
enable_optimizations
with_lto
with_hash_algorithm
with_tzpath
with_address_sanitizer
with_memory_sanitizer
with_undefined_behavior_sanitizer
Expand Down Expand Up @@ -1524,6 +1526,9 @@ Optional Packages:
--with-hash-algorithm=[fnv|siphash24]
select hash algorithm for use in Python/pyhash.c
(default is SipHash24)
--with-tzpath=<list of absolute paths separated by pathsep>
Select the default time zone search path for zoneinfo.TZPATH
--with-address-sanitizer
enable AddressSanitizer memory error detector,
'asan' (default is no)
Expand Down Expand Up @@ -10150,6 +10155,47 @@ $as_echo "default" >&6; }
fi


validate_tzpath() {
# Checks that each element of hte path is an absolute path
if test -z "$1"; then
# Empty string is allowed: it indicates no system TZPATH
return 0
fi

# Bad paths are those that don't start with /
if ( echo $1 | grep -qE '(^|:)([^/]|$)' ); then
as_fn_error $? "--with-tzpath must contain only absolute paths, not $1" "$LINENO" 5
return 1;
fi
}

TZPATH="/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-tzpath" >&5
$as_echo_n "checking for --with-tzpath... " >&6; }

# Check whether --with-tzpath was given.
if test "${with_tzpath+set}" = set; then :
withval=$with_tzpath;
case "$withval" in
yes)
as_fn_error $? "--with-tzpath requires a value" "$LINENO" 5
;;
*)
validate_tzpath "$withval"
TZPATH="$withval"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: \"$withval\"" >&5
$as_echo "\"$withval\"" >&6; }
;;
esac

else
validate_tzpath "$TZPATH"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: \"$TZPATH\"" >&5
$as_echo "\"$TZPATH\"" >&6; }
fi



{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-address-sanitizer" >&5
$as_echo_n "checking for --with-address-sanitizer... " >&6; }

Expand Down
36 changes: 36 additions & 0 deletions configure.ac
Expand Up @@ -2946,6 +2946,42 @@ esac
],
[AC_MSG_RESULT(default)])

validate_tzpath() {
# Checks that each element of hte path is an absolute path
if test -z "$1"; then
# Empty string is allowed: it indicates no system TZPATH
return 0
fi

# Bad paths are those that don't start with /
dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
if ( echo $1 | grep -qE '(^|:)(@<:@^/@:>@|$)' ); then
AC_MSG_ERROR([--with-tzpath must contain only absolute paths, not $1])
return 1;
fi
}

TZPATH="/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo"
AC_MSG_CHECKING(for --with-tzpath)
AC_ARG_WITH(tzpath,
AS_HELP_STRING([--with-tzpath=<list of absolute paths separated by pathsep>]
[Select the default time zone search path for zoneinfo.TZPATH]),
[
case "$withval" in
yes)
AC_MSG_ERROR([--with-tzpath requires a value])
;;
*)
validate_tzpath "$withval"
TZPATH="$withval"
AC_MSG_RESULT("$withval")
;;
esac
],
[validate_tzpath "$TZPATH"
AC_MSG_RESULT("$TZPATH")])
AC_SUBST(TZPATH)

AC_MSG_CHECKING(for --with-address-sanitizer)
AC_ARG_WITH(address_sanitizer,
AS_HELP_STRING([--with-address-sanitizer],
Expand Down
12 changes: 12 additions & 0 deletions setup.py
Expand Up @@ -304,6 +304,17 @@ def find_library_file(compiler, libname, std_dirs, paths):
else:
assert False, "Internal error: Path not found in std_dirs or paths"

def validate_tzpath():
base_tzpath = sysconfig.get_config_var('TZPATH')
if not base_tzpath:
return

tzpaths = base_tzpath.split(os.pathsep)
bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
if bad_paths:
raise ValueError('TZPATH must contain only absolute paths, '
+ f'found:\n{tzpaths!r}\nwith invalid paths:\n'
+ f'{bad_paths!r}')

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

sys.modules['concurrent.futures.process'] = DummyProcess
validate_tzpath()

# turn off warnings when deprecated modules are imported
import warnings
Expand Down

0 comments on commit 1ce93da

Please sign in to comment.