Skip to content
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
7 changes: 6 additions & 1 deletion linopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
from linopy.model import Model, Variable, Variables, available_solvers
from linopy.objective import Objective
from linopy.piecewise import breakpoints
from linopy.remote import OetcHandler, RemoteHandler
from linopy.remote import RemoteHandler

try:
from linopy.remote import OetcCredentials, OetcHandler, OetcSettings # noqa: F401
except ImportError:
pass

__all__ = (
"Constraint",
Expand Down
7 changes: 6 additions & 1 deletion linopy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@
add_disjunctive_piecewise_constraints,
add_piecewise_constraints,
)
from linopy.remote import OetcHandler, RemoteHandler
from linopy.remote import RemoteHandler

try:
from linopy.remote import OetcHandler
except ImportError:
OetcHandler = None # type: ignore
from linopy.solver_capabilities import SolverFeature, solver_supports
from linopy.solvers import (
IO_APIS,
Expand Down
6 changes: 5 additions & 1 deletion linopy/remote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
- OetcHandler: Cloud-based execution via OET Cloud service
"""

from linopy.remote.oetc import OetcCredentials, OetcHandler, OetcSettings
from linopy.remote.ssh import RemoteHandler

try:
from linopy.remote.oetc import OetcCredentials, OetcHandler, OetcSettings
except ImportError:
pass

__all__ = [
"RemoteHandler",
"OetcHandler",
Expand Down
18 changes: 14 additions & 4 deletions linopy/remote/oetc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
from datetime import datetime, timedelta
from enum import Enum

import requests
from google.cloud import storage
from google.oauth2 import service_account
from requests import RequestException
try:
import requests
from google.cloud import storage
from google.oauth2 import service_account
from requests import RequestException

_oetc_deps_available = True
except ImportError:
_oetc_deps_available = False

import linopy

Expand Down Expand Up @@ -85,6 +90,11 @@ class JobResult:

class OetcHandler:
def __init__(self, settings: OetcSettings) -> None:
if not _oetc_deps_available:
raise ImportError(
"The 'google-cloud-storage' and 'requests' packages are required "
"for OetcHandler. Install them with: pip install linopy[oetc]"
)
self.settings = settings
self.jwt = self.__sign_in()
self.cloud_provider_credentials = self.__get_cloud_provider_credentials()
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ dependencies = [
"tqdm",
"deprecation",
"packaging",
"google-cloud-storage",
"requests",
]

[project.urls]
Homepage = "https://github.com/PyPSA/linopy"
Source = "https://github.com/PyPSA/linopy"

[project.optional-dependencies]
oetc = [
"google-cloud-storage",
"requests",
]
docs = [
"ipython==8.26.0",
"numpydoc==1.7.0",
Expand Down
7 changes: 4 additions & 3 deletions test/remote/test_oetc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from unittest.mock import Mock, patch

import pytest
import requests
from requests import RequestException

from linopy.remote.oetc import (
requests = pytest.importorskip("requests")
from requests import RequestException # noqa: E402

from linopy.remote.oetc import ( # noqa: E402
AuthenticationResult,
ComputeProvider,
GcpCredentials,
Expand Down
6 changes: 4 additions & 2 deletions test/remote/test_oetc_job_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
from unittest.mock import Mock, patch

import pytest
from requests import RequestException

from linopy.remote.oetc import (
requests = pytest.importorskip("requests")
from requests import RequestException # noqa: E402

from linopy.remote.oetc import ( # noqa: E402
AuthenticationResult,
ComputeProvider,
OetcCredentials,
Expand Down