Skip to content

Commit

Permalink
added VENV_STATE to Makefile for forcing venv rebuilds
Browse files Browse the repository at this point in the history
  • Loading branch information
efroemling committed Apr 25, 2024
1 parent 2b12bf2 commit e7d3ea9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
27 changes: 17 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion config/projectconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"astroid",
"pylint.lint",
"pytest",
"pytz",
"yaml",
"requests",
"typing_extensions",
Expand Down
3 changes: 0 additions & 3 deletions config/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ansiwrap==0.8.4
cpplint==1.6.1
dmgbuild==1.6.1
filelock==3.13.4
Expand All @@ -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
17 changes: 2 additions & 15 deletions tools/efro/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
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.
Expand Down Expand Up @@ -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'
)


Expand Down

0 comments on commit e7d3ea9

Please sign in to comment.