From 978bb1d57be243bb4ddec6a4f76990ba49dd1d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kr=C3=BCger?= Date: Sat, 22 Feb 2025 23:05:05 +0100 Subject: [PATCH] Remove the baseline test new-year race condition. Fix #3723. (#3724) * Patch the baseline test new-year race condition. Fix #3723. * Use freezegun to circumvent the new year race condition. --- .gitignore | 3 +++ nikola/__main__.py | 22 +++++++++++----------- scripts/baseline.sh | 6 ++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index dad1f96a1f..e17d71bfd6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,10 @@ tmp/ cache/ output/ +baseline/ +nikola-baseline-build/ /tags +v3.*.zip.* # GitHub token .pypt/gh-token diff --git a/nikola/__main__.py b/nikola/__main__.py index 6baf841447..a17d9e77fd 100644 --- a/nikola/__main__.py +++ b/nikola/__main__.py @@ -116,6 +116,17 @@ def main(args=None): else: needs_config_file = False + invariant = False + + if len(args) > 0 and args[0] == 'build' and '--invariant' in args: + try: + import freezegun + freeze = freezegun.freeze_time("2038-01-01") + freeze.start() + invariant = True + except ImportError: + req_missing(['freezegun'], 'perform invariant builds') + sys.path.insert(0, os.path.dirname(conf_filename)) try: spec = importlib.util.spec_from_file_location("conf", conf_filename) @@ -138,17 +149,6 @@ def main(args=None): if conf_filename_changed: LOGGER.info("Using config file '{0}'".format(conf_filename)) - invariant = False - - if len(args) > 0 and args[0] == 'build' and '--invariant' in args: - try: - import freezegun - freeze = freezegun.freeze_time("2038-01-01") - freeze.start() - invariant = True - except ImportError: - req_missing(['freezegun'], 'perform invariant builds') - if config: if os.path.isdir('plugins') and not os.path.exists('plugins/__init__.py'): with open('plugins/__init__.py', 'w') as fh: diff --git a/scripts/baseline.sh b/scripts/baseline.sh index 8fb13e814e..5b739adbc2 100755 --- a/scripts/baseline.sh +++ b/scripts/baseline.sh @@ -1,4 +1,7 @@ #!/bin/bash + +set -e -o pipefail -x + PYVER=$(scripts/getpyver.py short) if [[ "$1" == "check" ]]; then echo -e "\033[36m>> Downloading baseline for $PYVER...\033[0m" @@ -19,8 +22,7 @@ rm "pages/creating-a-theme.rst" "pages/extending.rst" "pages/internals.rst" "pag LC_ALL='en_US.UTF-8' PYTHONHASHSEED=0 nikola build --invariant if [[ "$1" == "check" ]]; then echo -e "\033[36m>> Testing baseline...\033[0m" - diff -ubwr ../baseline output - if [[ $? == 0 ]]; then + if diff -ubwr ../baseline output; then echo -e "\033[32;1m>> Baseline test successful\033[0m" else CODE=$?