Skip to content

Commit 826cb99

Browse files
authored
Merge pull request #245 from digital-asset/python-rename-pkgloader-aio
python: Move dazl/ledger/pkgloader_aio into dazl/ledger/aio.
2 parents 0964945 + 06c7b59 commit 826cb99

File tree

16 files changed

+138
-101
lines changed

16 files changed

+138
-101
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.5.0a5
1+
7.5.0

python/dazl/client/_network_client_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
from ..damlast.daml_lf_1 import PackageRef
2727
from ..damlast.lookup import MultiPackageLookup
2828
from ..damlast.pkgfile import get_dar_package_ids
29+
from ..ledger.aio import PackageService
2930
from ..ledger.grpc.codec_aio import Codec
30-
from ..ledger.pkgloader_aio import PackageService
3131
from ..metrics import MetricEvents
3232
from ..prim import Party, TimeDeltaLike, to_timedelta
3333
from ..protocols import LedgerNetwork

python/dazl/client/ledger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import TYPE_CHECKING
99
import warnings
1010

11-
from ..ledger.pkgloader_aio import PackageLoader
11+
from ..ledger.aio import PackageLoader
1212
from ..protocols.serializers import Serializer
1313

1414
if TYPE_CHECKING:

python/dazl/client/pkg_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
import warnings
55

6-
from ..ledger.pkgloader_aio_compat import PackageLoader, SyncPackageService
6+
from ..ledger.aio.pkgloader_compat import PackageLoader, SyncPackageService
77

88
warnings.warn(
9-
"dazl.client.pkg_loader is deprecated; use dazl.protocols.pkgloader_aio instead.",
9+
"dazl.client.pkg_loader is deprecated; use dazl.ledger.aio instead.",
1010
DeprecationWarning,
1111
stacklevel=2,
1212
)

python/dazl/ledger/__init__.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"ExerciseCommand",
4242
"ExerciseResponse",
4343
"PartyInfo",
44+
"PackageService",
45+
"Connection",
46+
"QueryStream",
4447
]
4548

4649

@@ -63,8 +66,35 @@ def connect(*, blocking=False, **kwargs):
6366
return GrpcConnection(cfg)
6467

6568

69+
class PackageService(Protocol):
70+
"""
71+
Protocol that describe a service that provides package information. The :class:`Connection`
72+
protocol extends this interface.
73+
"""
74+
75+
def get_package(self, __package_id):
76+
"""
77+
Given a package ID, fetch the binary data for the corresponding DALF.
78+
79+
:param __package_id:
80+
The package ID of the DALF to retrieve.
81+
82+
Note that future versions of dazl reserve the right to rename this parameter name at any
83+
time; it should be passed in as a positional parameter and never by name.
84+
:return:
85+
The byte array contents of the DALF associated with the package ID.
86+
"""
87+
raise NotImplementedError
88+
89+
def list_package_ids(self):
90+
"""
91+
Fetch a list of all known package IDs.
92+
"""
93+
raise NotImplementedError
94+
95+
6696
@runtime_checkable
67-
class Connection(Protocol):
97+
class Connection(PackageService, Protocol):
6898
"""
6999
Protocol that describes a connection to a ledger. You will typically work with the more specific
70100
protocols :class:`dazl.ledger.aio.Connection` or :class:`dazl.ledger.blocking.Connection` that
@@ -453,26 +483,6 @@ def list_known_parties(self):
453483
"""
454484
raise NotImplementedError
455485

456-
def get_package(self, __package_id):
457-
"""
458-
Given a package ID, fetch the binary data for the corresponding DALF.
459-
460-
:param __package_id:
461-
The package ID of the DALF to retrieve.
462-
463-
Note that future versions of dazl reserve the right to rename this parameter name at any
464-
time; it should be passed in as a positional parameter and never by name.
465-
:return:
466-
The byte array contents of the DALF associated with the package ID.
467-
"""
468-
raise NotImplementedError
469-
470-
def list_package_ids(self):
471-
"""
472-
Fetch a list of all known package IDs.
473-
"""
474-
raise NotImplementedError
475-
476486
def upload_package(self, __contents):
477487
"""
478488
Upload a byte array as a DAR file to the remote Daml ledger.

python/dazl/ledger/__init__.pyi

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ __all__ = [
5858
"ExerciseCommand",
5959
"ExerciseResponse",
6060
"PartyInfo",
61+
"PackageService",
62+
"Connection",
63+
"QueryStream",
6164
]
6265

6366
CreateFn = TypeVar("CreateFn", bound=Callable[[CreateEvent], SubmitResponse])
@@ -180,8 +183,15 @@ def connect(
180183
logger_name: Optional[str] = None,
181184
log_level: Optional[str] = None,
182185
) -> Connection: ...
186+
187+
class PackageService(Protocol):
188+
def get_package(self, package_id: PackageRef) -> Union[bytes, Awaitable[bytes]]: ...
189+
def list_package_ids(
190+
self,
191+
) -> Union[AbstractSet[PackageRef], Awaitable[AbstractSet[PackageRef]]]: ...
192+
183193
@runtime_checkable
184-
class Connection(Protocol):
194+
class Connection(PackageService, Protocol):
185195
@property
186196
def config(self) -> Config: ...
187197
@property
@@ -257,10 +267,6 @@ class Connection(Protocol):
257267
self, *, identifier_hint: str = None, display_name: str = None
258268
) -> Union[PartyInfo, Awaitable[PartyInfo]]: ...
259269
def list_known_parties(self) -> Union[Sequence[PartyInfo], Awaitable[Sequence[PartyInfo]]]: ...
260-
def get_package(self, __package_id: PackageRef) -> Union[bytes, Awaitable[bytes]]: ...
261-
def list_package_ids(
262-
self,
263-
) -> Union[AbstractSet[PackageRef], Awaitable[AbstractSet[PackageRef]]]: ...
264270
def upload_package(self, __contents: bytes) -> Union[None, Awaitable[None]]: ...
265271

266272
@runtime_checkable

python/dazl/ledger/aio/__init__.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from typing_extensions import Protocol, runtime_checkable
2323

2424

25-
__all__ = ["Connection", "QueryStream", "QueryStreamBase"]
25+
__all__ = ["PackageService", "Connection", "QueryStream", "QueryStreamBase", "PackageLoader"]
2626

2727
Self = TypeVar("Self")
2828
Ret = Union[None, CreateEvent, ExerciseResponse]
@@ -33,6 +33,19 @@
3333
BOUNDARY = "boundary"
3434

3535

36+
class PackageService(Protocol):
37+
"""
38+
Protocol that describe a service that provides package information. The :class:`Connection`
39+
protocol extends this interface.
40+
"""
41+
42+
async def get_package(self, __package_id) -> bytes:
43+
raise NotImplementedError
44+
45+
async def list_package_ids(self):
46+
raise NotImplementedError
47+
48+
3649
@runtime_checkable
3750
class Connection(_Connection, Protocol):
3851
async def __aenter__(self):
@@ -198,3 +211,7 @@ def decorator(fn):
198211
return fn
199212

200213
return decorator
214+
215+
216+
# Imports internal to this package are at the bottom of the file to avoid circular dependencies
217+
from .pkgloader import PackageLoader # noqa

python/dazl/ledger/aio/__init__.pyi

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import abc
44
import sys
55
from typing import (
6+
AbstractSet,
67
Any,
78
AsyncIterator,
89
Awaitable,
@@ -16,8 +17,12 @@ from typing import (
1617
overload,
1718
)
1819

19-
from .. import Connection as _Connection, QueryStream as _QueryStream
20-
from ...damlast.daml_lf_1 import TypeConName
20+
from .. import (
21+
Connection as _Connection,
22+
PackageService as _PackageService,
23+
QueryStream as _QueryStream,
24+
)
25+
from ...damlast.daml_lf_1 import PackageRef, TypeConName
2126
from ...prim import ContractData, ContractId
2227
from ...query import Queries, Query
2328
from ..api_types import (
@@ -26,15 +31,17 @@ from ..api_types import (
2631
Command,
2732
CreateEvent,
2833
ExerciseResponse,
34+
PartyInfo,
2935
SubmitResponse,
3036
)
37+
from .pkgloader import PackageLoader
3138

3239
if sys.version_info >= (3, 8):
3340
from typing import Protocol, runtime_checkable
3441
else:
3542
from typing_extensions import Protocol, runtime_checkable
3643

37-
__all__ = ["Connection", "QueryStream", "QueryStreamBase"]
44+
__all__ = ["PackageService", "Connection", "QueryStream", "QueryStreamBase", "PackageLoader"]
3845

3946
Self = TypeVar("Self")
4047
CreateFn = TypeVar("CreateFn", bound=Callable[[CreateEvent], SubmitResponse])
@@ -72,8 +79,12 @@ class ABoundaryDecorator(Protocol):
7279
@overload
7380
def __call__(self, __fn: ABoundaryFn) -> ABoundaryFn: ...
7481

82+
class PackageService(_PackageService, Protocol):
83+
async def get_package(self, __package_id: PackageRef) -> bytes: ...
84+
async def list_package_ids(self) -> AbstractSet[PackageRef]: ...
85+
7586
@runtime_checkable
76-
class Connection(_Connection, Protocol):
87+
class Connection(_Connection, PackageService, Protocol):
7788
async def __aenter__(self: Self) -> Self: ...
7889
async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: ...
7990
async def open(self) -> None: ...
@@ -143,6 +154,11 @@ class Connection(_Connection, Protocol):
143154
self, __template_id: str = "*", __query: Query = None, *, offset: Optional[str] = None
144155
) -> QueryStream: ...
145156
def stream_many(self, *q: Queries, offset: Optional[str] = None) -> QueryStream: ...
157+
async def allocate_party(
158+
self, *, identifier_hint: Optional[str] = None, display_name: Optional[str] = None
159+
) -> PartyInfo: ...
160+
async def list_known_parties(self) -> Sequence[PartyInfo]: ...
161+
async def upload_package(self, contents: bytes) -> None: ...
146162

147163
# PyCharm doesn't know what to make of these overloads with respect to the parent protocol,
148164
# but mypy understands that these type signatures do not conflict with the parent base class
Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
# Copyright (c) 2017-2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
34
from asyncio import ensure_future, gather, get_event_loop, sleep, wait_for
45
from concurrent.futures import ThreadPoolExecutor
56
from datetime import timedelta
6-
import sys
7-
from typing import AbstractSet, Awaitable, Callable, Dict, Optional, Set, TypeVar
7+
from typing import Awaitable, Callable, Dict, Optional, Set, TypeVar
88
import warnings
99

10-
from .. import LOG
11-
from ..damlast.daml_lf_1 import Archive, Package, PackageRef
12-
from ..damlast.errors import NameNotFoundError, PackageNotFoundError
13-
from ..damlast.lookup import MultiPackageLookup, validate_template
14-
from ..damlast.pkgfile import Dar
15-
from ..prim import DazlError
16-
17-
if sys.version_info >= (3, 8):
18-
from typing import Protocol
19-
else:
20-
from typing_extensions import Protocol
10+
from . import PackageService
11+
from ... import LOG
12+
from ...damlast.daml_lf_1 import Archive, Package, PackageRef
13+
from ...damlast.errors import NameNotFoundError, PackageNotFoundError
14+
from ...damlast.lookup import MultiPackageLookup, validate_template
15+
from ...damlast.parse import parse_archive
16+
from ...damlast.pkgfile import Dar
17+
from ...prim import DazlError
2118

22-
__all__ = ["PackageService", "PackageLoader", "DEFAULT_TIMEOUT"]
19+
__all__ = ["PackageLoader", "DEFAULT_TIMEOUT"]
2320

2421
T = TypeVar("T")
2522

@@ -28,18 +25,6 @@
2825
DEFAULT_TIMEOUT: timedelta = timedelta(seconds=30)
2926

3027

31-
class PackageService(Protocol):
32-
"""
33-
A service that provides package information.
34-
"""
35-
36-
async def get_package(self, package_id: "PackageRef") -> bytes:
37-
raise NotImplementedError("PackageService.get_package requires an implementation")
38-
39-
async def list_package_ids(self) -> "AbstractSet[PackageRef]":
40-
raise NotImplementedError("PackageService.list_package_ids requires an implementation")
41-
42-
4328
class PackageLoader:
4429
"""
4530
Loader for packages from a remote PackageService.
@@ -165,8 +150,6 @@ async def load(self, ref: "PackageRef") -> "Package":
165150
return package
166151

167152
async def _load_and_parse_package(self, package_id: "PackageRef") -> "Package":
168-
from ..damlast.parse import parse_archive
169-
170153
LOG.info("Loading package: %s", package_id)
171154

172155
loop = get_event_loop()

python/dazl/ledger/pkgloader_aio_compat.py renamed to python/dazl/ledger/aio/pkgloader_compat.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
from typing import AbstractSet, Optional
1414
import warnings
1515

16-
from ..damlast.daml_lf_1 import PackageRef
17-
from ..damlast.lookup import MultiPackageLookup
18-
from .pkgloader_aio import DEFAULT_TIMEOUT, PackageLoader as NewPackageLoader
16+
from dazl.damlast.daml_lf_1 import PackageRef
17+
from dazl.damlast.lookup import MultiPackageLookup
18+
19+
from .pkgloader import DEFAULT_TIMEOUT, PackageLoader as NewPackageLoader
1920

2021
if sys.version_info >= (3, 8):
2122
from typing import Protocol

0 commit comments

Comments
 (0)