Skip to content

Commit

Permalink
Run "pyupgrade --py311-plus --keep-runtime-typing" over all code
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhelba committed Nov 6, 2023
1 parent eccce82 commit 3475e00
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 14 deletions.
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

0 comments on commit 3475e00

Please sign in to comment.