Skip to content
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

Update to Python 3.12 #32548

Merged
merged 58 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
bb99b4a
3.12
adeebshihadeh May 1, 2024
a4f37c3
pprofile is broken
adeebshihadeh May 1, 2024
a22eb47
use modified metadrivepy3-12
BBBmau May 27, 2024
3d1567f
Merge branch 'master' into pyenv-py3-12
BBBmau May 27, 2024
1c6a1d5
0.3.0 metadrive
BBBmau May 27, 2024
b6f1b20
Merge branch 'pyenv-py3-12' of github.com:BBBmau/openpilot into pyenv…
BBBmau May 27, 2024
7f4ea87
Merge remote-tracking branch 'comma/master' into pyenv-py3-12
BBBmau May 28, 2024
256f992
Merge branch 'pyenv-py3-12' of github.com:BBBmau/openpilot into pyenv…
BBBmau May 28, 2024
8c3f529
add metadrive/commaai git dependency
BBBmau May 28, 2024
8a18bf4
metadrive git set
BBBmau May 28, 2024
aa72380
pin sounddevice 0.4.6
BBBmau May 28, 2024
d42949a
Merge branch 'master' into pyenv-py3-12
maxime-desroches Jun 8, 2024
12cd1bf
datetime.utcnow() deprecation
maxime-desroches Jun 8, 2024
644ec15
poetry lock
maxime-desroches Jun 8, 2024
cee284f
make datetime not aware
maxime-desroches Jun 8, 2024
a25d5c7
poetry lock
maxime-desroches Jun 8, 2024
7eaec60
pin pytools
maxime-desroches Jun 8, 2024
1460853
google_crc32c wheel
maxime-desroches Jun 8, 2024
83ccb95
unpin sounddevice
maxime-desroches Jun 8, 2024
82eec23
Merge branch 'master' into pyenv-py3-12
maxime-desroches Jun 8, 2024
5252953
clean metadrive
maxime-desroches Jun 11, 2024
18e1fa8
merge master
maxime-desroches Jun 11, 2024
106f783
use python crc
maxime-desroches Jun 11, 2024
33738dc
mypy
maxime-desroches Jun 11, 2024
747eda9
3.12.4
maxime-desroches Jun 11, 2024
fbee652
lock
maxime-desroches Jun 11, 2024
8616fd9
allow python3.11
maxime-desroches Jun 11, 2024
84b8479
merge master
maxime-desroches Jun 11, 2024
3a019c5
test
maxime-desroches Jun 11, 2024
0999ab5
no pip
maxime-desroches Jun 11, 2024
0f3f5b5
poetry
maxime-desroches Jun 11, 2024
231f32a
better
maxime-desroches Jun 11, 2024
1baf9c9
better
maxime-desroches Jun 11, 2024
43dc0b5
Merge branch 'master' into pyenv-py3-12
maxime-desroches Jun 11, 2024
4abbc68
merge
maxime-desroches Jun 11, 2024
2024142
remove
maxime-desroches Jun 11, 2024
5364482
try
maxime-desroches Jun 11, 2024
8711e92
test
maxime-desroches Jun 11, 2024
567531b
try this
maxime-desroches Jun 11, 2024
353b6ba
snok
maxime-desroches Jun 11, 2024
e679926
python
maxime-desroches Jun 11, 2024
44910c8
simpler
maxime-desroches Jun 11, 2024
5b55d16
setuptools
maxime-desroches Jun 11, 2024
4c1456a
lower
maxime-desroches Jun 11, 2024
091d3ba
try
maxime-desroches Jun 11, 2024
e0f2fac
try
maxime-desroches Jun 11, 2024
a5c6146
work?
maxime-desroches Jun 11, 2024
e1a0749
ubuntu deps
maxime-desroches Jun 11, 2024
a4faa1a
ubuntu
maxime-desroches Jun 11, 2024
53d53e8
try
maxime-desroches Jun 11, 2024
201e29f
remove
maxime-desroches Jun 11, 2024
01a4045
merge
maxime-desroches Jun 11, 2024
d6480c2
move
maxime-desroches Jun 11, 2024
8b2f644
remove this
maxime-desroches Jun 11, 2024
a261348
names
maxime-desroches Jun 11, 2024
8c552a3
Update .github/workflows/tools_tests.yaml
maxime-desroches Jun 11, 2024
ca2718a
python<4
maxime-desroches Jun 11, 2024
c179f83
<3.13
maxime-desroches Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/tools_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ jobs:
source selfdrive/test/setup_vsound.sh && \
CI=1 pytest tools/sim/tests/test_metadrive_bridge.py"

test_python311:
name: test python3.11 support
runs-on: ubuntu-latest
timeout-minutes: 20
maxime-desroches marked this conversation as resolved.
Show resolved Hide resolved
steps:
- uses: actions/checkout@v4
- name: Installing ubuntu dependencies
run: INSTALL_EXTRA_PACKAGES=no tools/install_ubuntu_dependencies.sh
- name: Installing python
uses: actions/setup-python@v5
with:
python-version: '3.11.4'
- name: Installing pip
run: pip install pip==24.0
- name: Installing poetry
run: pip install poetry==1.7.0
- name: Installing python dependencies
run: poetry install --no-cache --no-root

devcontainer:
name: devcontainer
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11.4
3.12.4
4 changes: 2 additions & 2 deletions Dockerfile.openpilot_base
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER $USER

ENV POETRY_VIRTUALENVS_CREATE=false
ENV PYENV_VERSION=3.11.4
ENV PYENV_VERSION=3.12.4
ENV PYENV_ROOT="/home/$USER/pyenv"
ENV PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"

Expand All @@ -76,7 +76,7 @@ RUN cd /tmp && \
rm -rf /tmp/* && \
rm -rf /home/$USER/.cache && \
find /home/$USER/pyenv -type d -name ".git" | xargs rm -rf && \
rm -rf /home/$USER/pyenv/versions/3.11.4/lib/python3.11/test
rm -rf /home/$USER/pyenv/versions/3.12.4/lib/python3.12/test

USER root
RUN sudo git config --global --add safe.directory /tmp/openpilot
4 changes: 2 additions & 2 deletions common/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import jwt
import os
import requests
from datetime import datetime, timedelta
from datetime import datetime, timedelta, UTC
from openpilot.system.hardware.hw import Paths
from openpilot.system.version import get_version

Expand All @@ -23,7 +23,7 @@ def request(self, method, endpoint, timeout=None, access_token=None, **params):
return api_get(endpoint, method=method, timeout=timeout, access_token=access_token, **params)

def get_token(self, expiry_hours=1):
now = datetime.utcnow()
now = datetime.now(UTC).replace(tzinfo=None)
payload = {
'identity': self.dongle_id,
'nbf': now,
Expand Down
2,732 changes: 1,399 additions & 1,333 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ repository = "https://github.com/commaai/openpilot"
documentation = "https://docs.comma.ai"

[tool.poetry.dependencies]
python = "~3.11"
python = ">=3.11, <3.13"
maxime-desroches marked this conversation as resolved.
Show resolved Hide resolved

# multiple users
sounddevice = "*" # micd + soundd
Expand Down Expand Up @@ -154,15 +154,14 @@ inputs = "*"
Jinja2 = "*"
lru-dict = "*"
matplotlib = "*"
# No release for this fix https://github.com/metadriverse/metadrive/issues/632. Pinned to this commit until next release
metadrive-simulator = {git = "https://github.com/metadriverse/metadrive.git", rev ="233a3a1698be7038ec3dd050ca10b547b4b3324c", markers = "platform_machine != 'aarch64'" } # no linux/aarch64 wheels for certain dependencies
metadrive-simulator = { git = "https://github.com/commaai/metadrive.git", branch = "python3.12", markers = "platform_machine != 'aarch64'" } # no linux/aarch64 wheels for certain dependencies
mpld3 = "*"
mypy = "*"
myst-parser = "*"
natsort = "*"
opencv-python-headless = "*"
parameterized = "^0.8"
pprofile = "*"
#pprofile = "*"
BBBmau marked this conversation as resolved.
Show resolved Hide resolved
polyline = "*"
pre-commit = "*"
pyautogui = "*"
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/test/test_updated.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _check_update_state(self, update_available):
# make sure LastUpdateTime is recent
t = self._read_param("LastUpdateTime")
last_update_time = datetime.datetime.fromisoformat(t)
td = datetime.datetime.utcnow() - last_update_time
td = datetime.datetime.now(datetime.UTC).replace(tzinfo=None) - last_update_time
assert td.total_seconds() < 10
self.params.remove("LastUpdateTime")

Expand Down
4 changes: 2 additions & 2 deletions system/athena/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jwt
from pathlib import Path

from datetime import datetime, timedelta
from datetime import datetime, timedelta, UTC
from openpilot.common.api import api_get
from openpilot.common.params import Params
from openpilot.common.spinner import Spinner
Expand Down Expand Up @@ -66,7 +66,7 @@ def register(show_spinner=False) -> str | None:
start_time = time.monotonic()
while True:
try:
register_token = jwt.encode({'register': True, 'exp': datetime.utcnow() + timedelta(hours=1)}, private_key, algorithm='RS256')
register_token = jwt.encode({'register': True, 'exp': datetime.now(UTC).replace(tzinfo=None) + timedelta(hours=1)}, private_key, algorithm='RS256')
cloudlog.info("getting pilotauth")
resp = api_get("v2/pilotauth/", method='POST', timeout=15,
imei=imei1, imei2=imei2, serial=serial, public_key=public_key, register_token=register_token)
Expand Down
2 changes: 1 addition & 1 deletion system/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def manager_init() -> None:
("LongitudinalPersonality", str(log.LongitudinalPersonality.standard)),
]
if not PC:
default_params.append(("LastUpdateTime", datetime.datetime.utcnow().isoformat().encode('utf8')))
default_params.append(("LastUpdateTime", datetime.datetime.now(datetime.UTC).replace(tzinfo=None).isoformat().encode('utf8')))

if params.get_bool("RecordFrontLock"):
params.put_bool("RecordFront", True)
Expand Down
2 changes: 1 addition & 1 deletion system/qcomgpsd/qcomgpsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def setup_quectel(diag: ModemDiag) -> bool:
os.remove(ASSIST_DATA_FILE)
#at_cmd("AT+QGPSXTRADATA?")
if system_time_valid():
time_str = datetime.datetime.utcnow().strftime("%Y/%m/%d,%H:%M:%S")
time_str = datetime.datetime.now(datetime.UTC).replace(tzinfo=None).strftime("%Y/%m/%d,%H:%M:%S")
at_cmd(f"AT+QGPSXTRATIME=0,\"{time_str}\",1,1,1000")

at_cmd("AT+QGPSCFG=\"outport\",\"usbnmea\"")
Expand Down
2 changes: 1 addition & 1 deletion system/qcomgpsd/tests/test_qcomgpsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def check_assistance(self, should_be_loaded):
if should_be_loaded:
assert valid_duration == "10080" # should be max time
injected_time = datetime.datetime.strptime(injected_time_str.replace("\"", ""), "%Y/%m/%d,%H:%M:%S")
assert abs((datetime.datetime.utcnow() - injected_time).total_seconds()) < 60*60*12
assert abs((datetime.datetime.now(datetime.UTC).replace(tzinfo=None) - injected_time).total_seconds()) < 60*60*12
else:
valid_duration, injected_time_str = out.split(",", 1)
injected_time_str = injected_time_str.replace('\"', '').replace('\'', '')
Expand Down
2 changes: 1 addition & 1 deletion system/statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_influxdb_line(measurement: str, value: float | dict[str, float], timest
# flush when started state changes or after FLUSH_TIME_S
if (time.monotonic() > last_flush_time + STATS_FLUSH_TIME_S) or (sm['deviceState'].started != started_prev):
result = ""
current_time = datetime.utcnow().replace(tzinfo=UTC)
current_time = datetime.now(UTC)
tags['started'] = sm['deviceState'].started

for key, value in gauges.items():
Expand Down
4 changes: 2 additions & 2 deletions system/ubloxd/pigeond.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import struct
import requests
import urllib.parse
from datetime import datetime
from datetime import datetime, UTC

from cereal import messaging
from openpilot.common.params import Params
Expand Down Expand Up @@ -196,7 +196,7 @@ def initialize_pigeon(pigeon: TTYPigeon) -> bool:
cloudlog.error(f"failed to restore almanac backup, status: {restore_status}")

# sending time to ublox
t_now = datetime.utcnow()
t_now = datetime.now(UTC).replace(tzinfo=None)
if t_now >= datetime(2021, 6, 1):
cloudlog.warning("Sending current time to ublox")

Expand Down
10 changes: 5 additions & 5 deletions system/updated/updated.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def sleep(self, t: float) -> None:
self.ready_event.wait(timeout=t)

def write_time_to_param(params, param) -> None:
t = datetime.datetime.utcnow()
t = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
params.put(param, t.isoformat().encode('utf8'))

def read_time_from_param(params, param) -> datetime.datetime | None:
Expand Down Expand Up @@ -279,7 +279,7 @@ def set_params(self, update_success: bool, failed_count: int, exception: str | N
if len(self.branches):
self.params.put("UpdaterAvailableBranches", ','.join(self.branches.keys()))

last_update = datetime.datetime.utcnow()
last_update = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
if update_success:
write_time_to_param(self.params, "LastUpdateTime")
else:
Expand Down Expand Up @@ -323,7 +323,7 @@ def get_description(basedir: str) -> str:
for alert in ("Offroad_UpdateFailed", "Offroad_ConnectivityNeeded", "Offroad_ConnectivityNeededPrompt"):
set_offroad_alert(alert, False)

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
dt = now - last_update
build_metadata = get_build_metadata()
if failed_count > 15 and exception is not None and self.has_internet:
Expand Down Expand Up @@ -429,7 +429,7 @@ def main() -> None:
cloudlog.event("update installed")

if not params.get("InstallDate"):
t = datetime.datetime.utcnow().isoformat()
t = datetime.datetime.now(datetime.UTC).replace(tzinfo=None).isoformat()
params.put("InstallDate", t.encode('utf8'))

updater = Updater()
Expand Down Expand Up @@ -469,7 +469,7 @@ def main() -> None:

# download update
last_fetch = read_time_from_param(params, "UpdaterLastFetchTime")
timed_out = last_fetch is None or (datetime.datetime.utcnow() - last_fetch > datetime.timedelta(days=3))
timed_out = last_fetch is None or (datetime.datetime.now(datetime.UTC).replace(tzinfo=None) - last_fetch > datetime.timedelta(days=3))
user_requested_fetch = wait_helper.user_request == UserRequest.FETCH
if params.get_bool("NetworkMetered") and not timed_out and not user_requested_fetch:
cloudlog.info("skipping fetch, connection metered")
Expand Down
1 change: 1 addition & 0 deletions system/webrtc/tests/test_stream_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# for aiortc and its dependencies
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=RuntimeWarning) # TODO: remove this when google-crc32c publish a python3.12 wheel

from aiortc import RTCDataChannel
from aiortc.mediastreams import VIDEO_CLOCK_RATE, VIDEO_TIME_BASE
Expand Down
1 change: 1 addition & 0 deletions system/webrtc/tests/test_webrtcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# for aiortc and its dependencies
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=RuntimeWarning) # TODO: remove this when google-crc32c publish a python3.12 wheel
maxime-desroches marked this conversation as resolved.
Show resolved Hide resolved

from openpilot.system.webrtc.webrtcd import get_stream

Expand Down
1 change: 1 addition & 0 deletions system/webrtc/webrtcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# aiortc and its dependencies have lots of internal warnings :(
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=RuntimeWarning) # TODO: remove this when google-crc32c publish a python3.12 wheel

import capnp
from aiohttp import web
Expand Down
4 changes: 2 additions & 2 deletions tools/lib/azure_container.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from datetime import datetime, timedelta
from datetime import datetime, timedelta, UTC
from functools import lru_cache
from pathlib import Path
from typing import IO
Expand All @@ -20,7 +20,7 @@ def get_azure_credential():
@lru_cache
def get_container_sas(account_name: str, container_name: str):
from azure.storage.blob import BlobServiceClient, ContainerSasPermissions, generate_container_sas
start_time = datetime.utcnow()
start_time = datetime.now(UTC).replace(tzinfo=None)
expiry_time = start_time + timedelta(hours=1)
blob_service = BlobServiceClient(
account_url=f"https://{account_name}.blob.core.windows.net",
Expand Down
Loading