From e7d3ea98ec204a84801109bd7256afb7a869bc7e Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 25 Apr 2024 10:08:54 -0700 Subject: [PATCH] added VENV_STATE to Makefile for forcing venv rebuilds --- Makefile | 27 +++++++++++++++++---------- config/projectconfig.json | 1 - config/requirements.txt | 3 --- tools/efro/util.py | 17 ++--------------- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 0da5f567..f46ba42b 100644 --- a/Makefile +++ b/Makefile @@ -176,7 +176,7 @@ dummymodules-clean: env # Build the project's Python virtual environment. This should happen # automatically as a dependency of the env target. -venv: .venv/efro_venv_complete +venv: .venv/.efro_venv_complete # Update pip requirements to latest versions. venv-upgrade: env @@ -1221,10 +1221,10 @@ TOOL_CFG_INST = $(PCOMMAND) tool_config_install # Anything that affects tool-config generation. TOOL_CFG_SRC = tools/efrotools/toolconfig.py config/projectconfig.json \ - .venv/efro_venv_complete tools/pcommand + .venv/.efro_venv_complete tools/pcommand # Anything that should trigger an environment-check when changed. -ENV_SRC = tools/batools/build.py .venv/efro_venv_complete tools/pcommand +ENV_SRC = tools/batools/build.py .venv/.efro_venv_complete tools/pcommand # Generate a pcommand script hard-coded to use our virtual environment. # This is a prereq dependency so should not itself depend on env. @@ -1273,21 +1273,28 @@ SKIP_ENV_CHECKS ?= 0 VENV_PYTHON ?= python3.12 -# Rebuild our virtual environment whenever reqs or Python version changes. -# This is a prereq dependency so should not itself depend on env. Note that we -# rely on pcommand but can't use it in here until the end when the venv is up. -# Also note that we try to update existing venvs when possible, but when -# Python version changes we blow it away and start over to be safe. -.venv/efro_venv_complete: tools/pcommand config/requirements.txt \ +# Increment this to force all downstream venvs to fully rebuild. Useful after +# removing requirements since upgrading in place will never uninstall stuff. +VENV_STATE = 0 + +# Rebuild our virtual environment whenever reqs, Python version, or explicit +# state number changes. This is a dependency of env so it should not itself +# depend on env. Note that we list pcommand as a requirement but can't use it +# in here until the end when the venv is up. Also note that we try to update +# venvs in place when possible, but when Python version or venv-state changes +# we blow it away and start over to be safe. +.venv/.efro_venv_complete: tools/pcommand config/requirements.txt \ tools/efrotools/pyver.py @[ -f .venv/bin/$(VENV_PYTHON) ] \ + && [ -f .venv/.efro_venv_state_$(VENV_STATE) ] \ && echo Updating existing $(VENV_PYTHON) virtual environment in \'.venv\'... \ || (echo Creating new $(VENV_PYTHON) virtual environment in \'.venv\'... \ && rm -rf .venv) $(VENV_PYTHON) -m venv .venv .venv/bin/pip install --upgrade pip .venv/bin/pip install -r config/requirements.txt - touch .venv/efro_venv_complete # Done last to enforce fully-built venvs. + touch .venv/.efro_venv_state_$(VENV_STATE) \ + .venv/.efro_venv_complete # Done last to enforce fully-built venvs. @$(PCOMMAND) echo \ GRN Project virtual environment for BLD $(VENV_PYTHON) RST GRN \ at BLD .venv RST GRN is ready to use. diff --git a/config/projectconfig.json b/config/projectconfig.json index f8f1237e..1e16e3c3 100644 --- a/config/projectconfig.json +++ b/config/projectconfig.json @@ -31,7 +31,6 @@ "astroid", "pylint.lint", "pytest", - "pytz", "yaml", "requests", "typing_extensions", diff --git a/config/requirements.txt b/config/requirements.txt index 89ad203e..fc66adb0 100644 --- a/config/requirements.txt +++ b/config/requirements.txt @@ -1,4 +1,3 @@ -ansiwrap==0.8.4 cpplint==1.6.1 dmgbuild==1.6.1 filelock==3.13.4 @@ -13,13 +12,11 @@ pytest==8.1.1 python-daemon==3.0.1 python-lsp-black==2.0.0 python-lsp-server==1.11.0 -pytz==2024.1 PyYAML==6.0.1 requests==2.31.0 Sphinx==7.3.7 types-certifi==2021.10.8.3 types-filelock==3.2.7 -types-pytz==2024.1.0.20240417 types-PyYAML==6.0.12.20240311 types-requests==2.31.0.20240406 typing_extensions==4.11.0 diff --git a/tools/efro/util.py b/tools/efro/util.py index 5d1b2f7d..2f55997d 100644 --- a/tools/efro/util.py +++ b/tools/efro/util.py @@ -12,16 +12,6 @@ import functools from enum import Enum from typing import TYPE_CHECKING, cast, TypeVar, Generic -_pytz_utc: Any - -# We don't *require* pytz, but we want to support it for tzinfos if available. -try: - import pytz - - _pytz_utc = pytz.utc -except ModuleNotFoundError: - _pytz_utc = None # pylint: disable=invalid-name - if TYPE_CHECKING: import asyncio from efro.call import Call as Call # 'as Call' so we re-export. @@ -112,12 +102,9 @@ def enum_by_value(cls: type[EnumT], value: Any) -> EnumT: def check_utc(value: datetime.datetime) -> None: """Ensure a datetime value is timezone-aware utc.""" - if value.tzinfo is not datetime.timezone.utc and ( - _pytz_utc is None or value.tzinfo is not _pytz_utc - ): + if value.tzinfo is not datetime.UTC: raise ValueError( - 'datetime value does not have timezone set as' - ' datetime.timezone.utc' + 'datetime value does not have timezone set as datetime.UTC' )