Skip to content

Commit df75e51

Browse files
authored
Merge pull request #262 from digital-asset/python-daml-lf-1.14
python: Add support for Daml-LF 1.14 archives.
2 parents de2a7cc + 40a43b2 commit df75e51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+891
-889
lines changed

Makefile

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
cache_dir=.cache
5-
daml_proto_version=1.9.0
5+
daml_proto_version=1.15.0-snapshot.20210705.7286.0.62aabcc4
66

77
download_protos_zip := $(cache_dir)/download/protobufs-$(daml_proto_version).zip
8-
download_status_proto := $(cache_dir)/download/google/rpc/status.proto
98
proto_dir := $(cache_dir)/protos
109
proto_manifest := $(proto_dir)/manifest.json
1110
python := poetry run python3
11+
# TODO: Is there a programmatic way to get this path?
12+
venv_site_packages := .venv/lib/python3.6/site-packages
1213

1314
version := $(shell python3 -c "import configparser; config = configparser.ConfigParser(); config.read('pyproject.toml'); print(config['tool.poetry']['version'][1:-1])")
1415
py_src := $(shell find python/dazl -name '*.py[i]') README.md pyproject.toml
@@ -49,16 +50,8 @@ $(download_protos_zip):
4950
curl -sSL https://github.com/digital-asset/daml/releases/download/v$(daml_proto_version)/protobufs-$(daml_proto_version).zip -o $@
5051

5152

52-
$(download_status_proto):
53-
@mkdir -p $(@D)
54-
curl -sSL https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/status.proto -o $@
55-
56-
57-
$(proto_manifest): $(download_protos_zip) $(download_status_proto)
58-
_build/unpack.py \
59-
-i $(download_protos_zip) \
60-
-i $(download_status_proto) \
61-
-o $(@D) -m $@
53+
$(proto_manifest): $(download_protos_zip)
54+
_build/unpack.py -i $^ -o $(@D) -m $@
6255

6356

6457
.PHONY: unpack-protos

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.5.5
1+
7.5.6

_build/python/make-fragment

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def generate(manifest_file):
8181
print()
8282
print(f'$(_py_gen_tmp_dir)/{p}_pb2.py: $(proto_dir)/{p}.proto .venv/poetry.lock')
8383
print('\t@mkdir -p $(_py_gen_tmp_dir)')
84-
print('\t$(python) -m grpc_tools.protoc -I$(proto_dir) --python_out=$(_py_gen_tmp_dir) $<')
84+
print('\t$(python) -m grpc_tools.protoc -I$(venv_site_packages) -I$(proto_dir) --python_out=$(_py_gen_tmp_dir) $<')
8585

8686
if 'grpc' in types:
8787
print()
@@ -95,7 +95,7 @@ def generate(manifest_file):
9595
print()
9696
print(f'$(_py_gen_tmp_dir)/{p}_pb2.py $(_py_gen_tmp_dir)/{p}_pb2_grpc.py: $(proto_dir)/{p}.proto COPYRIGHT')
9797
print('\t@mkdir -p $(_py_gen_tmp_dir)')
98-
print('\t$(python) -m grpc_tools.protoc -I$(proto_dir) --python_out=$(_py_gen_tmp_dir) --grpc_python_out=$(_py_gen_tmp_dir) $<')
98+
print('\t$(python) -m grpc_tools.protoc -I$(venv_site_packages) -I$(proto_dir) --python_out=$(_py_gen_tmp_dir) --grpc_python_out=$(_py_gen_tmp_dir) $<')
9999

100100

101101
if __name__ == '__main__':

_build/unpack.py

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import json
66
import logging
7+
import os
78
from os.path import basename
89
from pathlib import Path
9-
from typing import Mapping, Sequence
10+
from typing import Mapping, Sequence, Union, Dict
1011
from zipfile import ZipFile
1112
from io import TextIOWrapper
1213

@@ -19,7 +20,7 @@ def main():
1920

2021
logging.basicConfig(level=logging.INFO)
2122

22-
parser = ArgumentParser(description='Unpack the DAML SDK protobuf package.')
23+
parser = ArgumentParser(description='Unpack the Daml Connect Protobuf package.')
2324
parser.add_argument('--input', '-i', required=True, action='append')
2425
parser.add_argument('--output', '-o', required=True)
2526
parser.add_argument('--output-manifest', '-m')
@@ -48,83 +49,60 @@ def run(self) -> 'Manifest':
4849
for input_path in self.inputs:
4950
if input_path.suffix == '.zip':
5051
manifest.update(self._process_zip(input_path))
51-
elif input_path.suffix == '.proto':
52-
manifest.update(self._process_proto(input_path))
5352
else:
54-
raise ValueError(f"don't know how to process {input_path.path}")
53+
raise ValueError(f"don't know how to process {input_path}")
5554

5655
return manifest
5756

5857
def _process_zip(self, path: 'Path') -> 'Manifest':
59-
proto_packages = {} # type: Manifest
58+
proto_packages = {} # type: Dict[str, Sequence[str]]
6059
with ZipFile(path) as z:
61-
logging.info('Procesing zip file: %s', path)
60+
logging.info('Processing zip file: %s', path)
6261
for zi in z.infolist():
6362
logging.info(' Processing file: %s', zi.filename)
6463
if is_valid_proto(zi.filename) and not zi.is_dir():
64+
# strip off the top-level directory name; we don't need it
65+
_, _, path = zi.filename.partition('/')
6566
with z.open(zi) as f:
6667
with TextIOWrapper(f) as text_buf:
6768
contents = text_buf.read()
6869
try:
69-
proto_packages.update(self._process_proto_contents(basename(zi.filename), contents))
70+
proto_packages.update(self._process_proto_contents(path, contents))
7071
except ValueError:
7172
logging.exception('Could not process %s', zi.filename)
7273
return proto_packages
7374

74-
def _process_proto(self, path: 'Path') -> 'Manifest':
75-
try:
76-
return self._process_proto_contents(path.name, path.read_text())
77-
except ValueError:
78-
logging.exception('Could not process %s', path)
79-
return {}
80-
81-
def _process_proto_contents(self, short_name: str, contents: str) -> 'Manifest':
75+
def _process_proto_contents(self, rel_file: str, contents: str) -> 'Manifest':
8276
lines = contents.splitlines()
8377
if not lines:
8478
return {}
8579

86-
# look for a package directive
87-
package_lines = [line for line in lines if line.startswith('package ')]
88-
if not package_lines:
89-
raise ValueError('file is missing a package directive')
90-
91-
package = package_lines[0].rstrip(';')[8:]
92-
9380
is_grpc = any(line.startswith('service') for line in lines)
9481

95-
rel_file = dest_dir(package) + '/' + short_name
96-
9782
out_file = self.output / rel_file
9883
out_file.parent.mkdir(parents=True, exist_ok=True)
9984
out_file.write_text(contents)
10085

10186
return { rel_file.rpartition('.')[0]: ['pb', 'grpc'] if is_grpc else ['pb'] }
10287

10388

104-
def dest_dir(package: str) -> str:
105-
"""
106-
Modify the package directive in a Protobuf file to put it in a more "expected" place.
107-
"""
108-
if package in ('daml_lf_dev', 'daml_lf_1'):
109-
return 'com/daml/daml_lf_dev'
110-
else:
111-
return package.replace('.', '/')
112-
113-
114-
def is_valid_proto(path: 'Path') -> bool:
89+
def is_valid_proto(path: 'Union[str, Path]') -> bool:
11590
# We prefer DAML-LF 1.dev because dev is always a strict superset of
11691
# the latest 1.x version, but also allows us to build and test support for
11792
# experimental features before they are released.
11893
if path is None:
11994
return False
12095

121-
p = str(path)
96+
p = os.fspath(path)
12297
return p.endswith('.proto') and \
12398
'/daml_lf_1_6/' not in p and \
12499
'/daml_lf_1_7/' not in p and \
125100
'/daml_lf_1_8/' not in p and \
126-
'/daml_lf_1_11/' not in p
127-
101+
'/daml_lf_1_11/' not in p and \
102+
'/daml_lf_1_12/' not in p and \
103+
'/daml_lf_1_13/' not in p and \
104+
'/daml_lf_dev/' not in p
105+
128106

129107
if __name__ == '__main__':
130108
main()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[tool.poetry]
55
name = "dazl"
6-
version = "7.5.5"
6+
version = "7.5.6"
77
description = "high-level Ledger API client for DAML ledgers"
88
license = "Apache-2.0"
99
authors = ["Davin K. Tanabe <davin.tanabe@digitalasset.com>"]
File renamed without changes.

python/dazl/_gen/com/daml/daml_lf_dev/daml_lf_1_pb2.py renamed to python/dazl/_gen/com/daml/daml_lf_1_14/daml_lf_1_pb2.py

Lines changed: 628 additions & 474 deletions
Large diffs are not rendered by default.

python/dazl/_gen/com/daml/daml_lf_dev/daml_lf_pb2.py renamed to python/dazl/_gen/com/daml/daml_lf_1_14/daml_lf_pb2.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33
# -*- coding: utf-8 -*-
44
# Generated by the protocol buffer compiler. DO NOT EDIT!
5-
# source: com/daml/daml_lf_dev/daml_lf.proto
6-
5+
# source: com/daml/daml_lf_1_14/daml_lf.proto
6+
"""Generated protocol buffer code."""
77
from google.protobuf import (
88
descriptor as _descriptor,
99
message as _message,
@@ -17,23 +17,23 @@
1717
_sym_db = _symbol_database.Default()
1818

1919

20-
from . import daml_lf_1_pb2 as com_dot_daml_dot_daml__lf__dev_dot_daml__lf__1__pb2
20+
from . import daml_lf_1_pb2 as com_dot_daml_dot_daml__lf__1__14_dot_daml__lf__1__pb2
2121

2222
DESCRIPTOR = _descriptor.FileDescriptor(
23-
name="com/daml/daml_lf_dev/daml_lf.proto",
24-
package="daml_lf_dev",
23+
name="com/daml/daml_lf_1_14/daml_lf.proto",
24+
package="daml_lf_1_13",
2525
syntax="proto3",
26-
serialized_options=b"\n\024com.daml.daml_lf_dev\252\002\033Com.Daml.Daml_Lf_Dev.DamlLf",
26+
serialized_options=b"\n\025com.daml.daml_lf_1_14\252\002\034Com.Daml.Daml_Lf_1_14.DamlLf",
2727
create_key=_descriptor._internal_create_key,
28-
serialized_pb=b'\n"com/daml/daml_lf_dev/daml_lf.proto\x12\x0b\x64\x61ml_lf_dev\x1a$com/daml/daml_lf_dev/daml_lf_1.proto"]\n\x0e\x41rchivePayload\x12\r\n\x05minor\x18\x03 \x01(\t\x12\'\n\tdaml_lf_1\x18\x02 \x01(\x0b\x32\x12.daml_lf_1.PackageH\x00\x42\x05\n\x03SumJ\x06\x08\x8fN\x10\x90NJ\x04\x08\x01\x10\x02"Z\n\x07\x41rchive\x12\x30\n\rhash_function\x18\x01 \x01(\x0e\x32\x19.daml_lf_dev.HashFunction\x12\x0f\n\x07payload\x18\x03 \x01(\x0c\x12\x0c\n\x04hash\x18\x04 \x01(\t*\x1a\n\x0cHashFunction\x12\n\n\x06SHA256\x10\x00\x42\x34\n\x14\x63om.daml.daml_lf_dev\xaa\x02\x1b\x43om.Daml.Daml_Lf_Dev.DamlLfb\x06proto3',
28+
serialized_pb=b'\n#com/daml/daml_lf_1_14/daml_lf.proto\x12\x0c\x64\x61ml_lf_1_13\x1a%com/daml/daml_lf_1_14/daml_lf_1.proto"]\n\x0e\x41rchivePayload\x12\r\n\x05minor\x18\x03 \x01(\t\x12\'\n\tdaml_lf_1\x18\x02 \x01(\x0b\x32\x12.daml_lf_1.PackageH\x00\x42\x05\n\x03SumJ\x06\x08\x8fN\x10\x90NJ\x04\x08\x01\x10\x02"[\n\x07\x41rchive\x12\x31\n\rhash_function\x18\x01 \x01(\x0e\x32\x1a.daml_lf_1_13.HashFunction\x12\x0f\n\x07payload\x18\x03 \x01(\x0c\x12\x0c\n\x04hash\x18\x04 \x01(\t*\x1a\n\x0cHashFunction\x12\n\n\x06SHA256\x10\x00\x42\x36\n\x15\x63om.daml.daml_lf_1_14\xaa\x02\x1c\x43om.Daml.Daml_Lf_1_14.DamlLfb\x06proto3',
2929
dependencies=[
30-
com_dot_daml_dot_daml__lf__dev_dot_daml__lf__1__pb2.DESCRIPTOR,
30+
com_dot_daml_dot_daml__lf__1__14_dot_daml__lf__1__pb2.DESCRIPTOR,
3131
],
3232
)
3333

3434
_HASHFUNCTION = _descriptor.EnumDescriptor(
3535
name="HashFunction",
36-
full_name="daml_lf_dev.HashFunction",
36+
full_name="daml_lf_1_13.HashFunction",
3737
filename=None,
3838
file=DESCRIPTOR,
3939
create_key=_descriptor._internal_create_key,
@@ -49,8 +49,8 @@
4949
],
5050
containing_type=None,
5151
serialized_options=None,
52-
serialized_start=276,
53-
serialized_end=302,
52+
serialized_start=280,
53+
serialized_end=306,
5454
)
5555
_sym_db.RegisterEnumDescriptor(_HASHFUNCTION)
5656

@@ -60,15 +60,15 @@
6060

6161
_ARCHIVEPAYLOAD = _descriptor.Descriptor(
6262
name="ArchivePayload",
63-
full_name="daml_lf_dev.ArchivePayload",
63+
full_name="daml_lf_1_13.ArchivePayload",
6464
filename=None,
6565
file=DESCRIPTOR,
6666
containing_type=None,
6767
create_key=_descriptor._internal_create_key,
6868
fields=[
6969
_descriptor.FieldDescriptor(
7070
name="minor",
71-
full_name="daml_lf_dev.ArchivePayload.minor",
71+
full_name="daml_lf_1_13.ArchivePayload.minor",
7272
index=0,
7373
number=3,
7474
type=9,
@@ -87,7 +87,7 @@
8787
),
8888
_descriptor.FieldDescriptor(
8989
name="daml_lf_1",
90-
full_name="daml_lf_dev.ArchivePayload.daml_lf_1",
90+
full_name="daml_lf_1_13.ArchivePayload.daml_lf_1",
9191
index=1,
9292
number=2,
9393
type=11,
@@ -115,29 +115,29 @@
115115
oneofs=[
116116
_descriptor.OneofDescriptor(
117117
name="Sum",
118-
full_name="daml_lf_dev.ArchivePayload.Sum",
118+
full_name="daml_lf_1_13.ArchivePayload.Sum",
119119
index=0,
120120
containing_type=None,
121121
create_key=_descriptor._internal_create_key,
122122
fields=[],
123123
),
124124
],
125-
serialized_start=89,
126-
serialized_end=182,
125+
serialized_start=92,
126+
serialized_end=185,
127127
)
128128

129129

130130
_ARCHIVE = _descriptor.Descriptor(
131131
name="Archive",
132-
full_name="daml_lf_dev.Archive",
132+
full_name="daml_lf_1_13.Archive",
133133
filename=None,
134134
file=DESCRIPTOR,
135135
containing_type=None,
136136
create_key=_descriptor._internal_create_key,
137137
fields=[
138138
_descriptor.FieldDescriptor(
139139
name="hash_function",
140-
full_name="daml_lf_dev.Archive.hash_function",
140+
full_name="daml_lf_1_13.Archive.hash_function",
141141
index=0,
142142
number=1,
143143
type=14,
@@ -156,7 +156,7 @@
156156
),
157157
_descriptor.FieldDescriptor(
158158
name="payload",
159-
full_name="daml_lf_dev.Archive.payload",
159+
full_name="daml_lf_1_13.Archive.payload",
160160
index=1,
161161
number=3,
162162
type=12,
@@ -175,7 +175,7 @@
175175
),
176176
_descriptor.FieldDescriptor(
177177
name="hash",
178-
full_name="daml_lf_dev.Archive.hash",
178+
full_name="daml_lf_1_13.Archive.hash",
179179
index=2,
180180
number=4,
181181
type=9,
@@ -201,13 +201,13 @@
201201
syntax="proto3",
202202
extension_ranges=[],
203203
oneofs=[],
204-
serialized_start=184,
205-
serialized_end=274,
204+
serialized_start=187,
205+
serialized_end=278,
206206
)
207207

208208
_ARCHIVEPAYLOAD.fields_by_name[
209209
"daml_lf_1"
210-
].message_type = com_dot_daml_dot_daml__lf__dev_dot_daml__lf__1__pb2._PACKAGE
210+
].message_type = com_dot_daml_dot_daml__lf__1__14_dot_daml__lf__1__pb2._PACKAGE
211211
_ARCHIVEPAYLOAD.oneofs_by_name["Sum"].fields.append(_ARCHIVEPAYLOAD.fields_by_name["daml_lf_1"])
212212
_ARCHIVEPAYLOAD.fields_by_name["daml_lf_1"].containing_oneof = _ARCHIVEPAYLOAD.oneofs_by_name["Sum"]
213213
_ARCHIVE.fields_by_name["hash_function"].enum_type = _HASHFUNCTION
@@ -221,8 +221,8 @@
221221
(_message.Message,),
222222
{
223223
"DESCRIPTOR": _ARCHIVEPAYLOAD,
224-
"__module__": "com.daml.daml_lf_dev.daml_lf_pb2"
225-
# @@protoc_insertion_point(class_scope:daml_lf_dev.ArchivePayload)
224+
"__module__": "com.daml.daml_lf_1_14.daml_lf_pb2"
225+
# @@protoc_insertion_point(class_scope:daml_lf_1_13.ArchivePayload)
226226
},
227227
)
228228
_sym_db.RegisterMessage(ArchivePayload)
@@ -232,8 +232,8 @@
232232
(_message.Message,),
233233
{
234234
"DESCRIPTOR": _ARCHIVE,
235-
"__module__": "com.daml.daml_lf_dev.daml_lf_pb2"
236-
# @@protoc_insertion_point(class_scope:daml_lf_dev.Archive)
235+
"__module__": "com.daml.daml_lf_1_14.daml_lf_pb2"
236+
# @@protoc_insertion_point(class_scope:daml_lf_1_13.Archive)
237237
},
238238
)
239239
_sym_db.RegisterMessage(Archive)

python/dazl/_gen/com/daml/daml_lf_dev/daml_lf_pb2.pyi renamed to python/dazl/_gen/com/daml/daml_lf_1_14/daml_lf_pb2.pyi

File renamed without changes.

0 commit comments

Comments
 (0)