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

Fix warnings by updating deprecated functions #547

Merged
merged 4 commits into from
May 29, 2024
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/project_automations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
if: github.event_name == 'issues' && github.event.action == 'opened' || github.event.action == 'reopened'
steps:
- name: 'Move issue to "Todo"'
uses: leonsteinhaeuser/project-beta-automations@v1.0.2
uses: leonsteinhaeuser/project-beta-automations@v2.1.0
with:
gh_token: ${{ secrets.MY_GITHUB_TOKEN }}
organization: equinor
Expand All @@ -32,7 +32,7 @@ jobs:
if: github.event_name == 'issues' && github.event.action == 'closed'
steps:
- name: 'Moved issue to "Done"'
uses: leonsteinhaeuser/project-beta-automations@v1.0.2
uses: leonsteinhaeuser/project-beta-automations@v2.1.0
with:
gh_token: ${{ secrets.MY_GITHUB_TOKEN }}
organization: equinor
Expand All @@ -45,7 +45,7 @@ jobs:
if: github.event_name == 'pull_request' && github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'review_requested'
steps:
- name: 'Move PR to "In Progress"'
uses: leonsteinhaeuser/project-beta-automations@v1.0.2
uses: leonsteinhaeuser/project-beta-automations@v2.1.0
with:
gh_token: ${{ secrets.MY_GITHUB_TOKEN }}
organization: equinor
Expand All @@ -58,7 +58,7 @@ jobs:
if: github.event_name == 'pull_request' && github.event.action == 'ready_for_review'
steps:
- name: 'Move PR to "Review"'
uses: leonsteinhaeuser/project-beta-automations@v1.0.2
uses: leonsteinhaeuser/project-beta-automations@v2.1.0
with:
gh_token: ${{ secrets.MY_GITHUB_TOKEN }}
organization: equinor
Expand All @@ -71,7 +71,7 @@ jobs:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
steps:
- name: 'Move PR to "Done"'
uses: leonsteinhaeuser/project-beta-automations@v1.0.2
uses: leonsteinhaeuser/project-beta-automations@v2.1.0
with:
gh_token: ${{ secrets.MY_GITHUB_TOKEN }}
organization: equinor
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish_isar_base_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
Expand Down
27 changes: 13 additions & 14 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@ name: Mark stale issues and pull requests
on:
workflow_dispatch:
schedule:
- cron: '35 8 * * *'
- cron: "35 8 * * *"

jobs:
stale:

runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- name: Close Stale Issues
uses: actions/stale@v9.0.0
with:
repo-token: ${{ secrets.STALE_ISSUE_TOKEN }}
stale-issue-message: 'This issue has automatically been marked as stale as there has been no activity for 60 days.'
stale-pr-message: 'This pull request has automatically been marked as stale as there has been no activity for 30 days.'
stale-issue-label: 'stale'
stale-pr-label: 'stale'
close-issue-message: 'This issue has been closed automatically due to a lack of activity.'
close-pr-message: 'This pull request has been closed automatically due to a lack of activity.'
days-before-pr-stale: 30
days-before-close: -1
- name: Close Stale Issues
uses: actions/stale@v9
with:
repo-token: ${{ secrets.STALE_ISSUE_TOKEN }}
stale-issue-message: "This issue has automatically been marked as stale as there has been no activity for 60 days."
stale-pr-message: "This pull request has automatically been marked as stale as there has been no activity for 30 days."
stale-issue-label: "stale"
stale-pr-label: "stale"
close-issue-message: "This issue has been closed automatically due to a lack of activity."
close-pr-message: "This pull request has been closed automatically due to a lack of activity."
days-before-pr-stale: 30
days-before-close: -1
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim AS builder
FROM python:3.12-slim AS builder

WORKDIR /app
RUN apt-get update
Expand All @@ -15,7 +15,7 @@ RUN pip install .
# Install the base isar-robot package
RUN pip install isar-robot

FROM python:3.10-slim
FROM python:3.12-slim
WORKDIR /app
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@
"sphinx",
]
},
python_requires=">=3.10",
python_requires=">=3.11",
)
6 changes: 3 additions & 3 deletions src/isar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pkg_resources import DistributionNotFound, get_distribution
from importlib.metadata import PackageNotFoundError, distribution

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
__version__ = distribution(__name__).version
except PackageNotFoundError:
pass # package is not installed
7 changes: 4 additions & 3 deletions src/isar/config/log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import importlib.resources as pkg_resources
import logging
import logging.config
from importlib.resources import as_file, files

import yaml
from opencensus.ext.azure.log_exporter import AzureLogHandler
Expand All @@ -14,8 +14,9 @@

def setup_loggers(keyvault: Keyvault) -> None:
log_levels: dict = settings.LOG_LEVELS
with pkg_resources.path("isar.config", "logging.conf") as path:
log_config = yaml.safe_load(open(path))
source = files("isar").joinpath("config").joinpath("logging.conf")
with as_file(source) as f:
log_config = yaml.safe_load(open(f))

logging.config.dictConfig(log_config)

Expand Down
26 changes: 15 additions & 11 deletions src/isar/config/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import importlib.resources as pkg_resources
import os
from importlib.resources import as_file, files
from typing import Any, List, Optional

from dotenv import load_dotenv
Expand All @@ -14,11 +14,12 @@
class Settings(BaseSettings):
def __init__(self) -> None:
try:
with pkg_resources.path(f"isar.config", "settings.env") as path:
env_file_path = path
source = files("isar").joinpath("config").joinpath("settings.env")
with as_file(source) as eml:
env_file = eml
except ModuleNotFoundError:
env_file_path = None
super().__init__(_env_file=env_file_path)
env_file = None
super().__init__(_env_file=env_file)

# Determines which robot package ISAR will attempt to import
# Name must match with an installed python package in the local environment
Expand Down Expand Up @@ -310,13 +311,16 @@ def prefix_isar_topics(cls, v: Any, info: ValidationInfo):
class RobotSettings(BaseSettings):
def __init__(self) -> None:
try:
with pkg_resources.path(
f"{settings.ROBOT_PACKAGE}.config", "settings.env"
) as path:
env_file_path = path
source = (
files(f"{settings.ROBOT_PACKAGE}")
.joinpath("config")
.joinpath("settings.env")
)
with as_file(source) as eml:
env_file = eml
except ModuleNotFoundError:
env_file_path = None
super().__init__(_env_file=env_file_path)
env_file = None
super().__init__(_env_file=env_file)

# ISAR steps the robot is capable of performing
# This should be set in the robot package settings.env file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import time
from datetime import datetime
from datetime import UTC, datetime
from queue import Queue

from isar.config.settings import settings
Expand All @@ -18,7 +18,7 @@ def run(self) -> None:
payload: RobotHeartbeatPayload = RobotHeartbeatPayload(
isar_id=settings.ISAR_ID,
robot_name=settings.ROBOT_NAME,
timestamp=datetime.utcnow(),
timestamp=datetime.now(UTC),
)

self.mqtt_publisher.publish(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import time
from datetime import datetime
from datetime import UTC, datetime
from queue import Queue

from isar.config.settings import robot_settings, settings
Expand All @@ -25,7 +25,7 @@ def run(self) -> None:
host=settings.API_HOST_VIEWED_EXTERNALLY,
port=settings.API_PORT,
capabilities=robot_settings.CAPABILITIES,
timestamp=datetime.utcnow(),
timestamp=datetime.now(UTC),
)

self.mqtt_publisher.publish(
Expand Down
10 changes: 5 additions & 5 deletions src/isar/state_machine/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import queue
from collections import deque
from datetime import datetime
from datetime import UTC, datetime
from typing import Deque, List, Optional

from alitra import Pose
Expand Down Expand Up @@ -508,7 +508,7 @@ def publish_mission_status(self) -> None:
"error_description": (
error_message.error_description if error_message else None
),
"timestamp": datetime.utcnow(),
"timestamp": datetime.now(UTC),
},
cls=EnhancedJSONEncoder,
)
Expand Down Expand Up @@ -540,7 +540,7 @@ def publish_task_status(self, task: Task) -> None:
"error_description": (
error_message.error_description if error_message else None
),
"timestamp": datetime.utcnow(),
"timestamp": datetime.now(UTC),
},
cls=EnhancedJSONEncoder,
)
Expand Down Expand Up @@ -574,7 +574,7 @@ def publish_step_status(self, step: Step) -> None:
"error_description": (
error_message.error_description if error_message else None
),
"timestamp": datetime.utcnow(),
"timestamp": datetime.now(UTC),
},
cls=EnhancedJSONEncoder,
)
Expand All @@ -593,7 +593,7 @@ def publish_status(self) -> None:
"isar_id": settings.ISAR_ID,
"robot_name": settings.ROBOT_NAME,
"status": self._current_status(),
"timestamp": datetime.utcnow(),
"timestamp": datetime.now(UTC),
},
cls=EnhancedJSONEncoder,
)
Expand Down
12 changes: 6 additions & 6 deletions src/isar/storage/uploader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
from dataclasses import dataclass
from datetime import datetime, timedelta
from datetime import UTC, datetime, timedelta
from queue import Empty, Queue
from typing import List, Union

Expand All @@ -22,23 +22,23 @@ class UploaderQueueItem:
mission: Mission
storage_handler: StorageInterface
_retry_count: int
_next_retry_time: datetime = datetime.utcnow()
_next_retry_time: datetime = datetime.now(UTC)

def increment_retry(self, max_wait_time: int) -> None:
self._retry_count += 1
seconds_until_retry: int = min(2**self._retry_count, max_wait_time)
self._next_retry_time = datetime.utcnow() + timedelta(
self._next_retry_time = datetime.now(UTC) + timedelta(
seconds=seconds_until_retry
)

def get_retry_count(self) -> int:
return self._retry_count

def is_ready_for_upload(self) -> bool:
return datetime.utcnow() >= self._next_retry_time
return datetime.now(UTC) >= self._next_retry_time

def seconds_until_retry(self) -> int:
return max(0, int((self._next_retry_time - datetime.utcnow()).total_seconds()))
return max(0, int((self._next_retry_time - datetime.now(UTC)).total_seconds()))


class Uploader:
Expand Down Expand Up @@ -154,7 +154,7 @@ def _publish_inspection_result(
"inspection_id": inspection.id,
"inspection_path": inspection_path,
"analysis_type": inspection.metadata.analysis_type,
"timestamp": datetime.utcnow(),
"timestamp": datetime.now(UTC),
},
cls=EnhancedJSONEncoder,
)
Expand Down
6 changes: 3 additions & 3 deletions src/isar/storage/utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import time
from datetime import datetime
from datetime import UTC, datetime
from pathlib import Path
from typing import Tuple

Expand Down Expand Up @@ -37,7 +37,7 @@ def construct_metadata_file(
"mission_id": mission.id,
"mission_name": mission.name,
"plant_name": settings.PLANT_NAME,
"mission_date": datetime.utcnow().date(),
"mission_date": datetime.now(UTC).date(),
"isar_id": settings.ISAR_ID,
"robot_name": settings.ROBOT_NAME,
"analysis_type": (
Expand Down Expand Up @@ -80,4 +80,4 @@ def get_filename(

def get_foldername(mission: Mission) -> str:
mission_name: str = mission.name.replace(" ", "-")
return f"{datetime.utcnow().date()}__{settings.PLANT_SHORT_NAME}__{mission_name}__{mission.id}"
return f"{datetime.now(UTC).date()}__{settings.PLANT_SHORT_NAME}__{mission_name}__{mission.id}"
Loading