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 backend to Python 3.12 #1719

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.12"
- name: Install tox
run: |
pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cli-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
fail-fast: false
matrix:
python:
- "3.10"
- "3.12"
dandi-version:
- release
- master
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/frontend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.12'

- name: Install latest version of pip
run: pip install --upgrade pip

- uses: actions/cache@v3
id: pip-cache
with:
path: ${{ env.pythonLocation}}/lib/python3.10/site-packages/*
path: ${{ env.pythonLocation}}/lib/python3.12/site-packages/*
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('setup.py') }}

- name: Install dandi-api dependencies
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ but allows developers to run Python code on their native system.
### Initial Setup
1. Install [Docker](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/)
2. Run `docker-compose -f ./docker-compose.yml up -d`
3. Install Python 3.10
3. Install Python 3.12
4. Install
[`psycopg2` build prerequisites](https://www.psycopg.org/docs/install.html#build-prerequisites).
Example `psycopg2` installation on Ubuntu 20.04:
Expand Down
4 changes: 2 additions & 2 deletions dandiapi/analytics/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import Counter
from collections.abc import Generator
from pathlib import Path
from typing import Generator

from celery.app import shared_task
from celery.utils.log import get_task_logger
Expand Down Expand Up @@ -79,7 +79,7 @@ def process_s3_log_file_task(bucket: LogBucket, s3_log_key: str) -> None:
download_counts = Counter()

for log_entry in s3logparse.parse_log_lines(
(line.decode('utf8') for line in data['Body'].iter_lines())
line.decode('utf8') for line in data['Body'].iter_lines()
):
if log_entry.operation == 'REST.GET.OBJECT' and log_entry.status_code == 200:
download_counts.update({log_entry.s3_key: 1})
Expand Down
2 changes: 1 addition & 1 deletion dandiapi/api/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def full_metadata(self):

def published_metadata(self):
"""Generate the metadata of this asset as if it were being published."""
now = datetime.datetime.now(datetime.timezone.utc)
now = datetime.datetime.now(datetime.UTC)
# Inject the publishedBy and datePublished fields
return {
**self.full_metadata,
Expand Down
2 changes: 1 addition & 1 deletion dandiapi/api/models/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def datetime_to_version(time: datetime.datetime) -> str:

@classmethod
def next_published_version(cls, dandiset: Dandiset) -> str:
time = datetime.datetime.now(datetime.timezone.utc)
time = datetime.datetime.now(datetime.UTC)
# increment time until there are no collisions
while True:
version = cls.datetime_to_version(time)
Expand Down
10 changes: 4 additions & 6 deletions dandiapi/api/services/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ def version_aggregate_assets_summary(version: Version) -> None:
raise VersionHasBeenPublished()

version.metadata['assetsSummary'] = aggregate_assets_summary(
(
asset.full_metadata
for asset in version.assets.filter(status=Asset.Status.VALID)
.select_related('blob', 'zarr')
.iterator()
)
asset.full_metadata
for asset in version.assets.filter(status=Asset.Status.VALID)
.select_related('blob', 'zarr')
.iterator()
)

Version.objects.filter(id=version.id, version='draft').update(
Expand Down
2 changes: 1 addition & 1 deletion dandiapi/api/services/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _build_publishable_version_from_draft(draft_version: Version) -> Version:
version=Version.next_published_version(draft_version.dandiset),
)

now = datetime.datetime.now(datetime.timezone.utc)
now = datetime.datetime.now(datetime.UTC)
# inject the publishedBy and datePublished fields
publishable_version.metadata.update(
{
Expand Down
2 changes: 1 addition & 1 deletion dandiapi/api/tasks/scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

This module is imported from celery.py in a post-app-load hook.
"""
from collections.abc import Iterable
from datetime import timedelta
import time
from typing import Iterable

from celery import shared_task
from celery.app.base import Celery
Expand Down
2 changes: 1 addition & 1 deletion dandiapi/api/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Meta:
def _create(cls, *args, **kwargs):
version: Version = super()._create(*args, **kwargs)
version.doi = f'10.80507/dandi.{version.dandiset.identifier}/{version.version}'
now = datetime.datetime.now(datetime.timezone.utc)
now = datetime.datetime.now(datetime.UTC)
version.metadata = {
**version.metadata,
'publishedBy': version.published_by(now),
Expand Down
2 changes: 1 addition & 1 deletion dandiapi/api/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_validate_asset_metadata_saves_version(draft_asset: Asset, draft_version
draft_version.assets.add(draft_asset)

# Update version with queryset so modified isn't auto incremented
old_datetime = datetime.datetime.fromtimestamp(1573782390).astimezone(datetime.timezone.utc)
old_datetime = datetime.datetime.fromtimestamp(1573782390).astimezone(datetime.UTC)
Version.objects.filter(id=draft_version.id).update(modified=old_datetime)

# Run task
Expand Down
2 changes: 1 addition & 1 deletion dev/django-public.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.12-slim
# Install system librarires for Python packages:
# * psycopg2
RUN apt-get update && \
Expand Down
2 changes: 1 addition & 1 deletion dev/django.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.12-slim
# Install system librarires for Python packages:
# * psycopg2
RUN apt-get update && \
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.black]
line-length = 100
skip-string-normalization = true
target-version = ["py310"]
target-version = ["py312"]
exclude='\.eggs|\.git|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist'

[tool.isort]
Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.10.11
python-3.12.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python',
],
python_requires='>=3.10',
python_requires='>=3.12',
packages=find_namespace_packages(include=['dandiapi*']),
include_package_data=True,
install_requires=[
Expand Down
Loading