-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-40503: Add compile-time configuration to PEP 615 #20034
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
Conversation
configure.ac
Outdated
validate_tzpath() { | ||
# Check that each element of the tzpath is an absolute path | ||
all_paths=$1 | ||
while test "${all_paths#*:}" != "$1"; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comparison to "$1" confuses me. $all_paths starts out as $1, and you're only removing things, so surely this loop would never end? It also feels like you could do this with grep instead:
if ( echo
AC_MSG_ERROR(...);
return 1;
fi
(There are already other uses of grep -E in configure.ac, so I think it's safe to rely on.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, though it was annoyingly tricky to pull off. It took me forever to realize that autoconf
was stripping out the []
characters from the grep string.
configure.ac
Outdated
;; | ||
esac | ||
], | ||
[AC_MSG_RESULT(default)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add $TZPATH in the message here, so you can see what that default is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I originally had it this way, but then I played around with the possibility of using something closer to the previous logic, where if TZPATH
is not explicitly set, at runtime the module will order the path based on a hard-coded string where the order is determined by which directories exist at import time. In that case, "default" made more sense than any hard-coded string.
I abandoned that approach as YAGNI — if we want to do something like that, we should probably just do it at build time anyway.
91cb1dd
to
e3a52c6
Compare
The import machinery can be somewhat fragile, and the "seamlessly falls back to pure Python" nature of this module makes it so that a problem building the C extension or a failure to import the pure Python version might easily go unnoticed. This adds some "smoke tests" that rely on implementation details of each module to ensure that we're building the ones we think we are.
This should improve support on Windows, including actually building the C extension.
This reverts commit 874dca0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG for the configure changes (for UNIX; not sure if more should be done for Windows).
configure.ac
Outdated
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 relative paths separated by pathsep>] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute paths, yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, oops! Good catch.
Suggestion by Petr Viktorin.
e3a52c6
to
cb54267
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows build changes look fine, thanks for getting the installer!
- name: Install test dependencies | ||
run: | | ||
.\python.bat -m ensurepip --user | ||
.\python.bat -m pip install --user -r Misc/requirements-test.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed, I don't like relying on pip to install into the source tree before we've run the test suite.
In general, system-wide dependencies are installed using the system package manager, or downloaded using specialised scripts and an existing Python installation (see PCbuild/get-externals.py
). This would be a new network dependency, and I'd rather keep us to things that are checked in or directly grabbed from GitHub.
@@ -48,6 +48,7 @@ jobs: | |||
./python -m venv .venv | |||
source ./.venv/bin/activate | |||
python -m pip install -U coverage | |||
python -m pip install -r Misc/requirements-test.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also as discussed, coverage is the one exception, but it's also not a core part of the PR workflow. We already switch CI providers for PRs every time Victor gets annoyed at network instability, so let's try and keep PR clean. We can leave it in the post-merge workflow if you really want.
@@ -546,6 +546,7 @@ def get_config_vars(*args): | |||
|
|||
if os.name == 'nt': | |||
_init_non_posix(_CONFIG_VARS) | |||
_CONFIG_VARS['TZPATH'] = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we just .get()
it rather than assuming it'll be set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be guaranteeing that it's set, and it should be an error condition otherwise. The "reasonable default" varies by platform, and can be configured at build time.
On Windows, the reasonable default is actually an empty string (no tzdata), but also I'd like to add it as a flag at build time.
TZPATH_TEST_LOCK = threading.Lock() | ||
|
||
|
||
def call_once(f): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from ._common import ZoneInfoNotFoundError | ||
|
||
try: | ||
from _czoneinfo import ZoneInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We normally just use the underscore prefix to indicate an accelerator module. The c
prefix hasn't really been used since 3.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a slightly more complicated situation, because _czoneinfo
is actually parallel to zoneinfo._zoneinfo
. In the reference implementation, the two are zoneinfo._zoneinfo
and zoneinfo._czoneinfo
, but the limitations of our current build system prevent me from doing that here.
+ day | ||
) | ||
|
||
# TODO: These are not actually epoch dates as they are expressed in local time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this TODO need to be fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point, but this is a method on a private class and the only issue is that the name is slightly misleading, so it's not in the critical path to an MVP.
This is configurable only on POSIX systems at the moment and TZPATH is initialized to an empty string on Windows.
cb54267
to
ddb8244
Compare
This is the implementation for PEP 615's support for compile-time configuration of the time zone search path.
The main implementation is in #19909 — at the moment it's not merged so unfortunately the commits are also present in this PR until that one gets merged. I couldn't come up with a good way to both have a neat diff and run the CI, so I went with running the CI.
The relevant changes are the ones starting with the commit "
Add --with-tzpath to autoconf
"https://bugs.python.org/issue40503