summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2022-07-30 22:26:31 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2022-07-30 22:26:31 +0300
commit0bc26e22b458ec0f013c467ef6206130257d03be (patch)
tree429ba941a1208241402b7a6696c009610dedf3c9
parentd59ce8d6a7b5f88ad38fd91f2f8bb92ee1f632ba (diff)
downloadapscheduler-0bc26e22b458ec0f013c467ef6206130257d03be.tar.gz
Made the apscheduler.structures module private and re-exported its code
-rw-r--r--src/apscheduler/__init__.py7
-rw-r--r--src/apscheduler/_structures.py (renamed from src/apscheduler/structures.py)28
-rw-r--r--src/apscheduler/abc.py5
-rw-r--r--src/apscheduler/datastores/async_adapter.py2
-rw-r--r--src/apscheduler/datastores/async_sqlalchemy.py4
-rw-r--r--src/apscheduler/datastores/memory.py3
-rw-r--r--src/apscheduler/datastores/mongodb.py4
-rw-r--r--src/apscheduler/datastores/sqlalchemy.py4
-rw-r--r--src/apscheduler/schedulers/async_.py4
-rw-r--r--src/apscheduler/schedulers/sync.py2
-rw-r--r--src/apscheduler/workers/async_.py4
-rw-r--r--src/apscheduler/workers/sync.py2
-rw-r--r--tests/test_datastores.py11
-rw-r--r--tests/test_schedulers.py10
-rw-r--r--tests/test_workers.py5
15 files changed, 48 insertions, 47 deletions
diff --git a/src/apscheduler/__init__.py b/src/apscheduler/__init__.py
index e2ad001..630ca51 100644
--- a/src/apscheduler/__init__.py
+++ b/src/apscheduler/__init__.py
@@ -5,15 +5,21 @@ __all__ = [
"ConflictPolicy",
"ConflictingIdError",
"DeserializationError",
+ "Job",
"JobCancelled",
"JobDeadlineMissed",
+ "JobInfo",
"JobLookupError",
"JobOutcome",
+ "JobResult",
"JobResultNotReady",
"MaxIterationsReached",
+ "RetrySettings",
"RunState",
+ "Schedule",
"ScheduleLookupError",
"SerializationError",
+ "Task",
"TaskLookupError",
]
@@ -32,6 +38,7 @@ from ._exceptions import (
SerializationError,
TaskLookupError,
)
+from ._structures import Job, JobInfo, JobResult, RetrySettings, Schedule, Task
# Re-export imports, so they look like they live directly in this package
value: Any
diff --git a/src/apscheduler/structures.py b/src/apscheduler/_structures.py
index 148f0db..1835112 100644
--- a/src/apscheduler/structures.py
+++ b/src/apscheduler/_structures.py
@@ -2,7 +2,7 @@ from __future__ import annotations
from datetime import datetime, timedelta, timezone
from functools import partial
-from typing import Any, Callable
+from typing import TYPE_CHECKING, Any, Callable
from uuid import UUID, uuid4
import attrs
@@ -10,11 +10,13 @@ import tenacity.stop
import tenacity.wait
from attrs.validators import instance_of
-from . import abc
from ._converters import as_enum, as_timedelta
from ._enums import CoalescePolicy, JobOutcome
from .marshalling import callable_from_ref, callable_to_ref
+if TYPE_CHECKING:
+ from .abc import Serializer, Trigger
+
def serialize(inst, field, value):
if isinstance(value, frozenset):
@@ -33,14 +35,14 @@ class Task:
)
state: Any = None
- def marshal(self, serializer: abc.Serializer) -> dict[str, Any]:
+ def marshal(self, serializer: Serializer) -> dict[str, Any]:
marshalled = attrs.asdict(self, value_serializer=serialize)
marshalled["func"] = callable_to_ref(self.func)
marshalled["state"] = serializer.serialize(self.state) if self.state else None
return marshalled
@classmethod
- def unmarshal(cls, serializer: abc.Serializer, marshalled: dict[str, Any]) -> Task:
+ def unmarshal(cls, serializer: Serializer, marshalled: dict[str, Any]) -> Task:
marshalled["func"] = callable_from_ref(marshalled["func"])
if marshalled["state"] is not None:
marshalled["state"] = serializer.deserialize(marshalled["state"])
@@ -52,7 +54,7 @@ class Task:
class Schedule:
id: str
task_id: str = attrs.field(eq=False, order=False)
- trigger: abc.Trigger = attrs.field(eq=False, order=False)
+ trigger: Trigger = attrs.field(eq=False, order=False)
args: tuple = attrs.field(eq=False, order=False, converter=tuple, default=())
kwargs: dict[str, Any] = attrs.field(
eq=False, order=False, converter=dict, default=()
@@ -77,7 +79,7 @@ class Schedule:
acquired_by: str | None = attrs.field(eq=False, order=False, default=None)
acquired_until: datetime | None = attrs.field(eq=False, order=False, default=None)
- def marshal(self, serializer: abc.Serializer) -> dict[str, Any]:
+ def marshal(self, serializer: Serializer) -> dict[str, Any]:
marshalled = attrs.asdict(self, value_serializer=serialize)
marshalled["trigger"] = serializer.serialize(self.trigger)
marshalled["args"] = serializer.serialize(self.args)
@@ -89,9 +91,7 @@ class Schedule:
return marshalled
@classmethod
- def unmarshal(
- cls, serializer: abc.Serializer, marshalled: dict[str, Any]
- ) -> Schedule:
+ def unmarshal(cls, serializer: Serializer, marshalled: dict[str, Any]) -> Schedule:
marshalled["trigger"] = serializer.deserialize(marshalled["trigger"])
marshalled["args"] = serializer.deserialize(marshalled["args"])
marshalled["kwargs"] = serializer.deserialize(marshalled["kwargs"])
@@ -139,7 +139,7 @@ class Job:
return self.scheduled_fire_time - self.jitter
- def marshal(self, serializer: abc.Serializer) -> dict[str, Any]:
+ def marshal(self, serializer: Serializer) -> dict[str, Any]:
marshalled = attrs.asdict(self, value_serializer=serialize)
marshalled["args"] = serializer.serialize(self.args)
marshalled["kwargs"] = serializer.serialize(self.kwargs)
@@ -150,7 +150,7 @@ class Job:
return marshalled
@classmethod
- def unmarshal(cls, serializer: abc.Serializer, marshalled: dict[str, Any]) -> Job:
+ def unmarshal(cls, serializer: Serializer, marshalled: dict[str, Any]) -> Job:
marshalled["args"] = serializer.deserialize(marshalled["args"])
marshalled["kwargs"] = serializer.deserialize(marshalled["kwargs"])
return cls(**marshalled)
@@ -191,7 +191,7 @@ class JobResult:
exception: BaseException | None = attrs.field(eq=False, order=False, default=None)
return_value: Any = attrs.field(eq=False, order=False, default=None)
- def marshal(self, serializer: abc.Serializer) -> dict[str, Any]:
+ def marshal(self, serializer: Serializer) -> dict[str, Any]:
marshalled = attrs.asdict(self, value_serializer=serialize)
if self.outcome is JobOutcome.error:
marshalled["exception"] = serializer.serialize(self.exception)
@@ -206,9 +206,7 @@ class JobResult:
return marshalled
@classmethod
- def unmarshal(
- cls, serializer: abc.Serializer, marshalled: dict[str, Any]
- ) -> JobResult:
+ def unmarshal(cls, serializer: Serializer, marshalled: dict[str, Any]) -> JobResult:
if marshalled.get("exception"):
marshalled["exception"] = serializer.deserialize(marshalled["exception"])
elif marshalled.get("return_value"):
diff --git a/src/apscheduler/abc.py b/src/apscheduler/abc.py
index dad6e47..e277158 100644
--- a/src/apscheduler/abc.py
+++ b/src/apscheduler/abc.py
@@ -6,10 +6,9 @@ from datetime import datetime
from typing import TYPE_CHECKING, Any, Callable, Iterable, Iterator
from uuid import UUID
-from ._enums import ConflictPolicy
-from .structures import Job, JobResult, Schedule, Task
-
if TYPE_CHECKING:
+ from ._enums import ConflictPolicy
+ from ._structures import Job, JobResult, Schedule, Task
from .events import Event
diff --git a/src/apscheduler/datastores/async_adapter.py b/src/apscheduler/datastores/async_adapter.py
index e155116..d16ae56 100644
--- a/src/apscheduler/datastores/async_adapter.py
+++ b/src/apscheduler/datastores/async_adapter.py
@@ -10,9 +10,9 @@ from anyio import to_thread
from anyio.from_thread import BlockingPortal
from .._enums import ConflictPolicy
+from .._structures import Job, JobResult, Schedule, Task
from ..abc import AsyncEventBroker, DataStore
from ..eventbrokers.async_adapter import AsyncEventBrokerAdapter, SyncEventBrokerAdapter
-from ..structures import Job, JobResult, Schedule, Task
from .base import BaseAsyncDataStore
diff --git a/src/apscheduler/datastores/async_sqlalchemy.py b/src/apscheduler/datastores/async_sqlalchemy.py
index 2f2f37e..fbf55d9 100644
--- a/src/apscheduler/datastores/async_sqlalchemy.py
+++ b/src/apscheduler/datastores/async_sqlalchemy.py
@@ -19,7 +19,8 @@ from sqlalchemy.sql.elements import BindParameter
from .._enums import ConflictPolicy
from .._exceptions import ConflictingIdError, SerializationError, TaskLookupError
-from ..abc import AsyncEventBroker, Job, Schedule
+from .._structures import Job, JobResult, Schedule, Task
+from ..abc import AsyncEventBroker
from ..events import (
DataStoreEvent,
JobAcquired,
@@ -34,7 +35,6 @@ from ..events import (
TaskUpdated,
)
from ..marshalling import callable_to_ref
-from ..structures import JobResult, Task
from .base import BaseAsyncDataStore
from .sqlalchemy import _BaseSQLAlchemyDataStore
diff --git a/src/apscheduler/datastores/memory.py b/src/apscheduler/datastores/memory.py
index d131327..dbc7672 100644
--- a/src/apscheduler/datastores/memory.py
+++ b/src/apscheduler/datastores/memory.py
@@ -11,7 +11,7 @@ import attrs
from .._enums import ConflictPolicy
from .._exceptions import ConflictingIdError, TaskLookupError
-from ..abc import Job, Schedule
+from .._structures import Job, JobResult, Schedule, Task
from ..events import (
JobAcquired,
JobAdded,
@@ -23,7 +23,6 @@ from ..events import (
TaskRemoved,
TaskUpdated,
)
-from ..structures import JobResult, Task
from .base import BaseDataStore
max_datetime = datetime(MAXYEAR, 12, 31, 23, 59, 59, 999999, tzinfo=timezone.utc)
diff --git a/src/apscheduler/datastores/mongodb.py b/src/apscheduler/datastores/mongodb.py
index 5f0b5ef..4a1339a 100644
--- a/src/apscheduler/datastores/mongodb.py
+++ b/src/apscheduler/datastores/mongodb.py
@@ -24,7 +24,8 @@ from .._exceptions import (
SerializationError,
TaskLookupError,
)
-from ..abc import EventBroker, Job, Schedule, Serializer
+from .._structures import Job, JobResult, RetrySettings, Schedule, Task
+from ..abc import EventBroker, Serializer
from ..eventbrokers.local import LocalEventBroker
from ..events import (
DataStoreEvent,
@@ -39,7 +40,6 @@ from ..events import (
TaskUpdated,
)
from ..serializers.pickle import PickleSerializer
-from ..structures import JobResult, RetrySettings, Task
from .base import BaseDataStore
diff --git a/src/apscheduler/datastores/sqlalchemy.py b/src/apscheduler/datastores/sqlalchemy.py
index c920d52..3110e4d 100644
--- a/src/apscheduler/datastores/sqlalchemy.py
+++ b/src/apscheduler/datastores/sqlalchemy.py
@@ -33,7 +33,8 @@ from sqlalchemy.sql.elements import BindParameter, literal
from .._enums import CoalescePolicy, ConflictPolicy, JobOutcome
from .._exceptions import ConflictingIdError, SerializationError, TaskLookupError
-from ..abc import EventBroker, Job, Schedule, Serializer
+from .._structures import Job, JobResult, RetrySettings, Schedule, Task
+from ..abc import EventBroker, Serializer
from ..events import (
Event,
JobAcquired,
@@ -50,7 +51,6 @@ from ..events import (
)
from ..marshalling import callable_to_ref
from ..serializers.pickle import PickleSerializer
-from ..structures import JobResult, RetrySettings, Task
from .base import BaseDataStore
diff --git a/src/apscheduler/schedulers/async_.py b/src/apscheduler/schedulers/async_.py
index ca8ab37..cbe8887 100644
--- a/src/apscheduler/schedulers/async_.py
+++ b/src/apscheduler/schedulers/async_.py
@@ -22,7 +22,8 @@ from .._exceptions import (
JobLookupError,
ScheduleLookupError,
)
-from ..abc import AsyncDataStore, AsyncEventBroker, Job, Schedule, Subscription, Trigger
+from .._structures import Job, JobResult, Schedule, Task
+from ..abc import AsyncDataStore, AsyncEventBroker, Subscription, Trigger
from ..context import current_scheduler
from ..datastores.memory import MemoryDataStore
from ..eventbrokers.async_local import LocalAsyncEventBroker
@@ -35,7 +36,6 @@ from ..events import (
ScheduleUpdated,
)
from ..marshalling import callable_to_ref
-from ..structures import JobResult, Task
from ..workers.async_ import AsyncWorker
_microsecond_delta = timedelta(microseconds=1)
diff --git a/src/apscheduler/schedulers/sync.py b/src/apscheduler/schedulers/sync.py
index c3e9207..162e6b9 100644
--- a/src/apscheduler/schedulers/sync.py
+++ b/src/apscheduler/schedulers/sync.py
@@ -22,6 +22,7 @@ from .._exceptions import (
JobLookupError,
ScheduleLookupError,
)
+from .._structures import Job, JobResult, Schedule, Task
from ..abc import DataStore, EventBroker, Trigger
from ..context import current_scheduler
from ..datastores.memory import MemoryDataStore
@@ -35,7 +36,6 @@ from ..events import (
ScheduleUpdated,
)
from ..marshalling import callable_to_ref
-from ..structures import Job, JobResult, Schedule, Task
from ..workers.sync import Worker
_microsecond_delta = timedelta(microseconds=1)
diff --git a/src/apscheduler/workers/async_.py b/src/apscheduler/workers/async_.py
index 601fc4e..ffd6e4d 100644
--- a/src/apscheduler/workers/async_.py
+++ b/src/apscheduler/workers/async_.py
@@ -22,12 +22,12 @@ from anyio.abc import CancelScope, TaskGroup
from .._converters import as_async_datastore, as_async_eventbroker
from .._enums import JobOutcome, RunState
+from .._structures import Job, JobInfo, JobResult
from .._validators import positive_integer
-from ..abc import AsyncDataStore, AsyncEventBroker, Job
+from ..abc import AsyncDataStore, AsyncEventBroker
from ..context import current_worker, job_info
from ..eventbrokers.async_local import LocalAsyncEventBroker
from ..events import JobAdded, WorkerStarted, WorkerStopped
-from ..structures import JobInfo, JobResult
@attrs.define(eq=False)
diff --git a/src/apscheduler/workers/sync.py b/src/apscheduler/workers/sync.py
index 686cb26..61f23ad 100644
--- a/src/apscheduler/workers/sync.py
+++ b/src/apscheduler/workers/sync.py
@@ -16,12 +16,12 @@ from uuid import UUID
import attrs
from .._enums import JobOutcome, RunState
+from .._structures import Job, JobInfo, JobResult
from .._validators import positive_integer
from ..abc import DataStore, EventBroker
from ..context import current_worker, job_info
from ..eventbrokers.local import LocalEventBroker
from ..events import JobAdded, WorkerStarted, WorkerStopped
-from ..structures import Job, JobInfo, JobResult
@attrs.define(eq=False)
diff --git a/tests/test_datastores.py b/tests/test_datastores.py
index 3e23828..51e11b4 100644
--- a/tests/test_datastores.py
+++ b/tests/test_datastores.py
@@ -15,14 +15,8 @@ from freezegun.api import FrozenDateTimeFactory
from pytest_lazyfixture import lazy_fixture
from apscheduler import CoalescePolicy, ConflictPolicy, JobOutcome, TaskLookupError
-from apscheduler.abc import (
- AsyncDataStore,
- AsyncEventBroker,
- DataStore,
- EventBroker,
- Job,
- Schedule,
-)
+from apscheduler._structures import Job, JobResult, Schedule, Task
+from apscheduler.abc import AsyncDataStore, AsyncEventBroker, DataStore, EventBroker
from apscheduler.datastores.async_adapter import AsyncDataStoreAdapter
from apscheduler.datastores.memory import MemoryDataStore
from apscheduler.eventbrokers.async_local import LocalAsyncEventBroker
@@ -35,7 +29,6 @@ from apscheduler.events import (
TaskAdded,
TaskUpdated,
)
-from apscheduler.structures import JobResult, Task
from apscheduler.triggers.date import DateTrigger
diff --git a/tests/test_schedulers.py b/tests/test_schedulers.py
index b093e74..cd64b34 100644
--- a/tests/test_schedulers.py
+++ b/tests/test_schedulers.py
@@ -11,7 +11,14 @@ import pytest
from anyio import fail_after
from pytest_mock import MockerFixture
-from apscheduler import JobLookupError, JobOutcome, ScheduleLookupError
+from apscheduler import (
+ Job,
+ JobLookupError,
+ JobOutcome,
+ Schedule,
+ ScheduleLookupError,
+ Task,
+)
from apscheduler.context import current_scheduler, current_worker, job_info
from apscheduler.events import (
Event,
@@ -23,7 +30,6 @@ from apscheduler.events import (
)
from apscheduler.schedulers.async_ import AsyncScheduler
from apscheduler.schedulers.sync import Scheduler
-from apscheduler.structures import Job, Schedule, Task
from apscheduler.triggers.date import DateTrigger
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.workers.async_ import AsyncWorker
diff --git a/tests/test_workers.py b/tests/test_workers.py
index de9958c..7f86aca 100644
--- a/tests/test_workers.py
+++ b/tests/test_workers.py
@@ -8,8 +8,8 @@ import anyio
import pytest
from anyio import fail_after
-from apscheduler import JobOutcome
-from apscheduler.abc import Job
+from apscheduler import Job, JobOutcome
+from apscheduler._structures import Task
from apscheduler.datastores.memory import MemoryDataStore
from apscheduler.events import (
Event,
@@ -19,7 +19,6 @@ from apscheduler.events import (
TaskAdded,
WorkerStopped,
)
-from apscheduler.structures import Task
from apscheduler.workers.async_ import AsyncWorker
from apscheduler.workers.sync import Worker