Skip to content

Commit

Permalink
Fix datetime deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Dec 9, 2024
1 parent 2ce5f93 commit d0bafb2
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion conda-store-server/conda_store_server/_internal/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def update_packages(self, db, subdirs=None):

logger.info(f"DONE for architecture : {architecture}")

self.last_update = datetime.datetime.utcnow()
self.last_update = datetime.datetime.now(datetime.UTC)
db.commit()
logger.info("update packages DONE ")

Expand Down
4 changes: 2 additions & 2 deletions conda-store-server/conda_store_server/_internal/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

def _datetime_factory(offset: datetime.timedelta):
"""Utcnow datetime + timezone as string"""
return datetime.datetime.utcnow() + offset
return datetime.datetime.now(datetime.UTC) + offset


# An ARN is a string which matches namespaces and environments. For example:
Expand Down Expand Up @@ -453,7 +453,7 @@ def __str__(self):

def _docker_datetime_factory():
"""Utcnow datetime + timezone as string"""
return datetime.datetime.utcnow().astimezone().isoformat()
return datetime.datetime.now(datetime.UTC).astimezone().isoformat()


class DockerManifestLayer(BaseModel):
Expand Down
16 changes: 8 additions & 8 deletions conda-store-server/conda_store_server/_internal/worker/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def append_to_logs(db: Session, conda_store, build, logs: typing.Union[str, byte

def set_build_started(db: Session, build: orm.Build):
build.status = schema.BuildStatus.BUILDING
build.started_on = datetime.datetime.utcnow()
build.started_on = datetime.datetime.now(datetime.UTC)
db.commit()


Expand All @@ -82,7 +82,7 @@ def set_build_failed(
):
build.status = schema.BuildStatus.FAILED
build.status_info = status_info
build.ended_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.now(datetime.UTC)
db.commit()


Expand All @@ -91,13 +91,13 @@ def set_build_canceled(
):
build.status = schema.BuildStatus.CANCELED
build.status_info = status_info
build.ended_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.now(datetime.UTC)
db.commit()


def set_build_completed(db: Session, conda_store, build: orm.Build):
build.status = schema.BuildStatus.COMPLETED
build.ended_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.now(datetime.UTC)

directory_build_artifact = orm.BuildArtifact(
build_id=build.id,
Expand Down Expand Up @@ -161,7 +161,7 @@ def build_cleanup(
and str(build.id) not in build_active_tasks
and (
build.started_on
< (datetime.datetime.utcnow() - datetime.timedelta(seconds=5))
< (datetime.datetime.now(datetime.UTC) - datetime.timedelta(seconds=5))
)
):
conda_store.log.warning(
Expand Down Expand Up @@ -193,7 +193,7 @@ def build_conda_environment(db: Session, conda_store, build):
db,
conda_store,
build,
f"starting build of conda environment {datetime.datetime.utcnow()} UTC\n",
f"starting build of conda environment {datetime.datetime.now(datetime.UTC)} UTC\n",
)

settings = conda_store.get_settings(
Expand Down Expand Up @@ -335,7 +335,7 @@ def build_conda_environment(db: Session, conda_store, build):


def solve_conda_environment(db: Session, conda_store, solve: orm.Solve):
solve.started_on = datetime.datetime.utcnow()
solve.started_on = datetime.datetime.now(datetime.UTC)
db.commit()

_, locker = conda_store.lock_plugin()
Expand All @@ -351,7 +351,7 @@ def solve_conda_environment(db: Session, conda_store, solve: orm.Solve):
solve_id=solve.id,
)

solve.ended_on = datetime.datetime.utcnow()
solve.ended_on = datetime.datetime.now(datetime.UTC)
db.commit()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def task_delete_build(self, build_id):
delete_build_artifact(db, conda_store, build_artifact)

# Updates build size and marks build as deleted
build.deleted_on = datetime.datetime.utcnow()
build.deleted_on = datetime.datetime.now(datetime.UTC)
build.size = 0

db.commit()
Expand Down
4 changes: 2 additions & 2 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def delete_environment(self, db: Session, namespace: str, name: str):
f"environment namespace={namespace} name={name} does not exist"
)

utcnow = datetime.datetime.utcnow()
utcnow = datetime.datetime.now(datetime.UTC)
environment.deleted_on = utcnow
for build in environment.builds:
build.deleted_on = utcnow
Expand Down Expand Up @@ -877,7 +877,7 @@ def delete_build(self, db: Session, build_id: int):
"cannot delete build since not finished building"
)

build.deleted_on = datetime.datetime.utcnow()
build.deleted_on = datetime.datetime.now(datetime.UTC)
db.commit()

self.celery_app
Expand Down
2 changes: 1 addition & 1 deletion conda-store-server/conda_store_server/server/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ async def post_login_method(
domain=self.cookie_domain,
# set cookie to expire at same time as jwt
max_age=int(
(authentication_token.exp - datetime.datetime.utcnow()).total_seconds()
(authentication_token.exp - datetime.datetime.now(datetime.UTC)).total_seconds()
),
)
return response
Expand Down
4 changes: 2 additions & 2 deletions conda-store-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def seed_conda_store(db, conda_store):

# for testing purposes make build 4 complete
build = api.get_build(db, build_id=4)
build.started_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.utcnow()
build.started_on = datetime.datetime.now(datetime.UTC)
build.ended_on = datetime.datetime.now(datetime.UTC)
build.status = schema.BuildStatus.COMPLETED
db.commit()
return db
Expand Down
2 changes: 1 addition & 1 deletion conda-store-server/tests/server/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_expired_token():
token = authentication.encrypt_token(
AuthenticationToken(
primary_namespace="default",
exp=datetime.datetime.utcnow() - datetime.timedelta(hours=1),
exp=datetime.datetime.now(datetime.UTC) - datetime.timedelta(hours=1),
role_bindings={
"default/*": ["viewer"],
"e*/e*": ["admin"],
Expand Down

0 comments on commit d0bafb2

Please sign in to comment.