Gentoo Archives: gentoo-commits

From: Jason Zaman <perfinion@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sci-libs/keras/, sci-libs/keras/files/
Date: Fri, 23 Sep 2022 03:07:01
Message-Id: 1663902406.4227b7a6e364e31880fa44e0be8bd789a9fe4b6a.perfinion@gentoo
1 commit: 4227b7a6e364e31880fa44e0be8bd789a9fe4b6a
2 Author: Jason Zaman <perfinion <AT> gentoo <DOT> org>
3 AuthorDate: Mon Sep 19 01:52:59 2022 +0000
4 Commit: Jason Zaman <perfinion <AT> gentoo <DOT> org>
5 CommitDate: Fri Sep 23 03:06:46 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4227b7a6
7
8 sci-libs/keras: add 2.10.0
9
10 Signed-off-by: Jason Zaman <perfinion <AT> gentoo.org>
11
12 sci-libs/keras/Manifest | 1 +
13 ...ras-2.10.0-0001-bazel-Use-system-protobuf.patch | 327 +++++++++++++++++++++
14 sci-libs/keras/keras-2.10.0.ebuild | 85 ++++++
15 3 files changed, 413 insertions(+)
16
17 diff --git a/sci-libs/keras/Manifest b/sci-libs/keras/Manifest
18 index 6bd8df8bd0df..c8a8659e2e4b 100644
19 --- a/sci-libs/keras/Manifest
20 +++ b/sci-libs/keras/Manifest
21 @@ -1,4 +1,5 @@
22 DIST bazelbuild-rules_cc-b1c40e1de81913a3c40e5948f78719c28152486d.zip 201360 BLAKE2B 0173a8edb17f344b18e42026e2f8a62a1909d4694ab0be83562b6437a3f1ef38889f069269ddd2308b41062e5f375f791be0d2631a8e52ede668203779813b56 SHA512 2ba1dc316d88947c1d17ec67154c052700e3571b8d03370a9f204cf9fe94a1bd58f93a2c4a3c0b02233ee3250053a4c30a4133b5b38745858c1d04be8c9d973f
23 DIST bazelbuild-rules_java-7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip 9422 BLAKE2B bbc45c97551ee8126335b611ffca6574dac843d4db9b3221b10d26487f8eecfe38ba0cd67a4039a3ad921c25fea6294c43e4f4e7a57a060a30791acd6c4f9d39 SHA512 ba06242feb711e7fb6e821fd9ac029248b4f3e466fb1acf971d0db8196f3efe4d114ef137acbe4913073f8cbe8ccab4d47d8bafa21b867b2d6a6d57f5a647f0c
24 +DIST keras-2.10.0.tar.gz 2250425 BLAKE2B eb05537739cdc81e279b5c400e2e2b77d46f4085e8530fef565bde12414ddccedb44c0b13265106a3353e67c367106e1d341412dc25b32e2221f144a31d76079 SHA512 8682110495a045c2ebc61f31a98d646b88fd9608d5169be78701cf528457ff0d2e39669d885854c14c1e6bebb380b14968957f2a8a34a8a023f8860efc7aeecd
25 DIST keras-2.8.0.tar.gz 2001168 BLAKE2B 64e756da102369bd41b176245f7f8184b2376b6fb714485627e30107af552035931c9fcff18d82def5f4e1b83f2eae2fa3d0c18b030986f8d3a53dffbdbb2963 SHA512 a70ae1409761211f3b59d358df4d5abf6bb76b915f5dde90ada5a867aef2831581836d38876bd2e962f3c345f59373bf76a7c21247cef8aeaec45ba1301f787b
26 DIST keras-2.9.0.tar.gz 2142884 BLAKE2B 9d90ad998ef7215f9a3ab0f0ac9d035f81023f7049e5c73823a0aa8561ead2f697ff762c225f668f3d9fe376d69a2bfbdf8b137128c915a711cee53d809093d6 SHA512 779828aff9aa31970e7f68b32423e47b81f47d2284d9e9734428c3bc3789e6b0e9ef151315e1cae666b14b1cdc387828ddaf520811250f9ad4fa73cf5c98781d
27
28 diff --git a/sci-libs/keras/files/keras-2.10.0-0001-bazel-Use-system-protobuf.patch b/sci-libs/keras/files/keras-2.10.0-0001-bazel-Use-system-protobuf.patch
29 new file mode 100644
30 index 000000000000..d7cb39f70e8c
31 --- /dev/null
32 +++ b/sci-libs/keras/files/keras-2.10.0-0001-bazel-Use-system-protobuf.patch
33 @@ -0,0 +1,327 @@
34 +From bbb2bd19534d6d5aef466dc8707f7c8ad3bab9d8 Mon Sep 17 00:00:00 2001
35 +From: Jason Zaman <jason@×××××××××.com>
36 +Date: Sun, 14 Nov 2021 17:59:39 -0800
37 +Subject: [PATCH] bazel: Use system protobuf
38 +
39 +---
40 + WORKSPACE | 49 ---------
41 + keras/protobuf/BUILD | 2 +-
42 + third_party/BUILD | 8 +-
43 + third_party/protobuf.bzl | 216 +++++++++++++++++++++++++++++++++++++++
44 + 4 files changed, 224 insertions(+), 51 deletions(-)
45 + create mode 100644 third_party/protobuf.bzl
46 +
47 +diff --git a/WORKSPACE b/WORKSPACE
48 +index 898b5b6d..61282aea 100644
49 +--- a/WORKSPACE
50 ++++ b/WORKSPACE
51 +@@ -1,50 +1 @@
52 + workspace(name = "org_keras")
53 +-
54 +-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
55 +-
56 +-# Needed by protobuf
57 +-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
58 +-http_archive(
59 +- name = "bazel_skylib",
60 +- url = "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.1/bazel-skylib-1.0.1.tar.gz",
61 +- sha256 = "f1c8360c01fcf276778d3519394805dc2a71a64274a3a0908bc9edff7b5aebc8",
62 +-)
63 +-load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
64 +-bazel_skylib_workspace()
65 +-
66 +-# Needed by protobuf
67 +-http_archive(
68 +- name = "six_archive",
69 +- build_file = "//third_party:six.BUILD",
70 +- sha256 = "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73",
71 +- strip_prefix = "six-1.12.0",
72 +- urls = [
73 +- "http://mirror.bazel.build/pypi.python.org/packages/source/s/six/six-1.12.0.tar.gz",
74 +- "https://pypi.python.org/packages/source/s/six/six-1.12.0.tar.gz", # 2018-12-10
75 +- ],
76 +-)
77 +-
78 +-bind(
79 +- name = "six",
80 +- actual = "@six_archive//:six",
81 +-)
82 +-
83 +-http_archive(
84 +- name = "com_google_protobuf",
85 +- sha256 = "1fbf1c2962af287607232b2eddeaec9b4f4a7a6f5934e1a9276e9af76952f7e0",
86 +- strip_prefix = "protobuf-3.9.2",
87 +- urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.9.2.tar.gz"],
88 +-)
89 +-
90 +-# ZLIB. Need by com_google_protobuf.
91 +-http_archive(
92 +- name = "zlib",
93 +- build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
94 +- sha256 = "91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9",
95 +- strip_prefix = "zlib-1.2.12",
96 +- urls = ["https://zlib.net/zlib-1.2.12.tar.gz"],
97 +-)
98 +-
99 +-
100 +-load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
101 +-protobuf_deps()
102 +diff --git a/keras/protobuf/BUILD b/keras/protobuf/BUILD
103 +index 413dcb74..80133c06 100644
104 +--- a/keras/protobuf/BUILD
105 ++++ b/keras/protobuf/BUILD
106 +@@ -1,7 +1,7 @@
107 + # Description:
108 + # Contains Keras protobufs
109 +
110 +-load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
111 ++load("//third_party:protobuf.bzl", "py_proto_library")
112 +
113 + package(
114 + default_visibility = [
115 +diff --git a/third_party/BUILD b/third_party/BUILD
116 +index 9be54076..9399232f 100644
117 +--- a/third_party/BUILD
118 ++++ b/third_party/BUILD
119 +@@ -1,4 +1,5 @@
120 + package(
121 ++ default_visibility = ["//visibility:public"],
122 + licenses = ["notice"], # Apache 2.0
123 + )
124 +
125 +@@ -7,4 +8,9 @@ exports_files([
126 + "six.BUILD",
127 + ])
128 +
129 +-package(default_visibility = ["//visibility:public"])
130 ++genrule(
131 ++ name = "protoc",
132 ++ outs = ["protoc.bin"],
133 ++ cmd = "ln -s $$(which protoc) $@",
134 ++ executable = 1,
135 ++)
136 +diff --git a/third_party/protobuf.bzl b/third_party/protobuf.bzl
137 +new file mode 100644
138 +index 00000000..3a7ef0a2
139 +--- /dev/null
140 ++++ b/third_party/protobuf.bzl
141 +@@ -0,0 +1,216 @@
142 ++def _GetPath(ctx, path):
143 ++ if ctx.label.workspace_root:
144 ++ return ctx.label.workspace_root + "/" + path
145 ++ else:
146 ++ return path
147 ++
148 ++def _IsNewExternal(ctx):
149 ++ # Bazel 0.4.4 and older have genfiles paths that look like:
150 ++ # bazel-out/local-fastbuild/genfiles/external/repo/foo
151 ++ # After the exec root rearrangement, they look like:
152 ++ # ../repo/bazel-out/local-fastbuild/genfiles/foo
153 ++ return ctx.label.workspace_root.startswith("../")
154 ++
155 ++def _GenDir(ctx):
156 ++ if _IsNewExternal(ctx):
157 ++ # We are using the fact that Bazel 0.4.4+ provides repository-relative paths
158 ++ # for ctx.genfiles_dir.
159 ++ return ctx.genfiles_dir.path + (
160 ++ "/" + ctx.attr.includes[0] if ctx.attr.includes and ctx.attr.includes[0] else ""
161 ++ )
162 ++
163 ++ # This means that we're either in the old version OR the new version in the local repo.
164 ++ # Either way, appending the source path to the genfiles dir works.
165 ++ return ctx.var["GENDIR"] + "/" + _SourceDir(ctx)
166 ++
167 ++def _SourceDir(ctx):
168 ++ if not ctx.attr.includes:
169 ++ return ctx.label.workspace_root
170 ++ if not ctx.attr.includes[0]:
171 ++ return _GetPath(ctx, ctx.label.package)
172 ++ if not ctx.label.package:
173 ++ return _GetPath(ctx, ctx.attr.includes[0])
174 ++ return _GetPath(ctx, ctx.label.package + "/" + ctx.attr.includes[0])
175 ++
176 ++def _PyOuts(srcs, use_grpc_plugin = False):
177 ++ ret = [s[:-len(".proto")] + "_pb2.py" for s in srcs]
178 ++ if use_grpc_plugin:
179 ++ ret += [s[:-len(".proto")] + "_pb2_grpc.py" for s in srcs]
180 ++ return ret
181 ++
182 ++def _proto_gen_impl(ctx):
183 ++ """General implementation for generating protos"""
184 ++ srcs = ctx.files.srcs
185 ++ deps = []
186 ++ deps += ctx.files.srcs
187 ++ source_dir = _SourceDir(ctx)
188 ++ gen_dir = _GenDir(ctx)
189 ++ if source_dir:
190 ++ import_flags = ["-I" + source_dir, "-I" + gen_dir]
191 ++ else:
192 ++ import_flags = ["-I."]
193 ++
194 ++ for dep in ctx.attr.deps:
195 ++ import_flags += dep.proto.import_flags
196 ++ deps += dep.proto.deps
197 ++ import_flags = depset(import_flags).to_list()
198 ++ deps = depset(deps).to_list()
199 ++
200 ++ args = []
201 ++ if ctx.attr.gen_cc:
202 ++ args += ["--cpp_out=" + gen_dir]
203 ++ if ctx.attr.gen_py:
204 ++ args += ["--python_out=" + gen_dir]
205 ++
206 ++ inputs = srcs + deps
207 ++ tools = [ctx.executable.protoc]
208 ++ if ctx.executable.plugin:
209 ++ plugin = ctx.executable.plugin
210 ++ lang = ctx.attr.plugin_language
211 ++ if not lang and plugin.basename.startswith("protoc-gen-"):
212 ++ lang = plugin.basename[len("protoc-gen-"):]
213 ++ if not lang:
214 ++ fail("cannot infer the target language of plugin", "plugin_language")
215 ++
216 ++ outdir = gen_dir
217 ++ if ctx.attr.plugin_options:
218 ++ outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir
219 ++ args += ["--plugin=protoc-gen-%s=%s" % (lang, plugin.path)]
220 ++ args += ["--%s_out=%s" % (lang, outdir)]
221 ++ tools.append(plugin)
222 ++
223 ++ if args:
224 ++ ctx.actions.run(
225 ++ inputs = inputs,
226 ++ outputs = ctx.outputs.outs,
227 ++ arguments = args + import_flags + [s.path for s in srcs],
228 ++ executable = ctx.executable.protoc,
229 ++ mnemonic = "ProtoCompile",
230 ++ tools = tools,
231 ++ use_default_shell_env = True,
232 ++ )
233 ++
234 ++ return struct(
235 ++ proto = struct(
236 ++ srcs = srcs,
237 ++ import_flags = import_flags,
238 ++ deps = deps,
239 ++ ),
240 ++ )
241 ++
242 ++proto_gen = rule(
243 ++ attrs = {
244 ++ "srcs": attr.label_list(allow_files = True),
245 ++ "deps": attr.label_list(providers = ["proto"]),
246 ++ "includes": attr.string_list(),
247 ++ "protoc": attr.label(
248 ++ cfg = "host",
249 ++ executable = True,
250 ++ allow_single_file = True,
251 ++ mandatory = True,
252 ++ ),
253 ++ "plugin": attr.label(
254 ++ cfg = "host",
255 ++ allow_files = True,
256 ++ executable = True,
257 ++ ),
258 ++ "plugin_language": attr.string(),
259 ++ "plugin_options": attr.string_list(),
260 ++ "gen_cc": attr.bool(),
261 ++ "gen_py": attr.bool(),
262 ++ "outs": attr.output_list(),
263 ++ },
264 ++ output_to_genfiles = True,
265 ++ implementation = _proto_gen_impl,
266 ++)
267 ++"""Generates codes from Protocol Buffers definitions.
268 ++
269 ++This rule helps you to implement Skylark macros specific to the target
270 ++language. You should prefer more specific `cc_proto_library `,
271 ++`py_proto_library` and others unless you are adding such wrapper macros.
272 ++
273 ++Args:
274 ++ srcs: Protocol Buffers definition files (.proto) to run the protocol compiler
275 ++ against.
276 ++ deps: a list of dependency labels; must be other proto libraries.
277 ++ includes: a list of include paths to .proto files.
278 ++ protoc: the label of the protocol compiler to generate the sources.
279 ++ plugin: the label of the protocol compiler plugin to be passed to the protocol
280 ++ compiler.
281 ++ plugin_language: the language of the generated sources
282 ++ plugin_options: a list of options to be passed to the plugin
283 ++ gen_cc: generates C++ sources in addition to the ones from the plugin.
284 ++ gen_py: generates Python sources in addition to the ones from the plugin.
285 ++ outs: a list of labels of the expected outputs from the protocol compiler.
286 ++"""
287 ++
288 ++def py_proto_library(
289 ++ name,
290 ++ srcs = [],
291 ++ deps = [],
292 ++ py_libs = [],
293 ++ py_extra_srcs = [],
294 ++ include = None,
295 ++ default_runtime = None,
296 ++ protoc = "//third_party:protoc",
297 ++ use_grpc_plugin = False,
298 ++ **kwargs):
299 ++ """Bazel rule to create a Python protobuf library from proto source files
300 ++
301 ++ NOTE: the rule is only an internal workaround to generate protos. The
302 ++ interface may change and the rule may be removed when bazel has introduced
303 ++ the native rule.
304 ++
305 ++ Args:
306 ++ name: the name of the py_proto_library.
307 ++ srcs: the .proto files of the py_proto_library.
308 ++ deps: a list of dependency labels; must be py_proto_library.
309 ++ py_libs: a list of other py_library targets depended by the generated
310 ++ py_library.
311 ++ py_extra_srcs: extra source files that will be added to the output
312 ++ py_library. This attribute is used for internal bootstrapping.
313 ++ include: a string indicating the include path of the .proto files.
314 ++ default_runtime: the implicitly default runtime which will be depended on by
315 ++ the generated py_library target.
316 ++ protoc: the label of the protocol compiler to generate the sources.
317 ++ use_grpc_plugin: a flag to indicate whether to call the Python C++ plugin
318 ++ when processing the proto files.
319 ++ **kwargs: other keyword arguments that are passed to py_library.
320 ++
321 ++ """
322 ++ outs = _PyOuts(srcs, use_grpc_plugin)
323 ++
324 ++ includes = []
325 ++ if include != None:
326 ++ includes = [include]
327 ++
328 ++ grpc_python_plugin = None
329 ++ if use_grpc_plugin:
330 ++ grpc_python_plugin = "//external:grpc_python_plugin"
331 ++ # Note: Generated grpc code depends on Python grpc module. This dependency
332 ++ # is not explicitly listed in py_libs. Instead, host system is assumed to
333 ++ # have grpc installed.
334 ++
335 ++ proto_gen(
336 ++ name = name + "_genproto",
337 ++ srcs = srcs,
338 ++ deps = [s + "_genproto" for s in deps],
339 ++ includes = includes,
340 ++ protoc = protoc,
341 ++ gen_py = 1,
342 ++ outs = outs,
343 ++ visibility = ["//visibility:public"],
344 ++ plugin = grpc_python_plugin,
345 ++ plugin_language = "grpc",
346 ++ )
347 ++
348 ++ if default_runtime and not default_runtime in py_libs + deps:
349 ++ py_libs = py_libs + [default_runtime]
350 ++
351 ++ native.py_library(
352 ++ name = name,
353 ++ srcs = outs + py_extra_srcs,
354 ++ deps = py_libs + deps,
355 ++ imports = includes,
356 ++ **kwargs
357 ++ )
358 +--
359 +2.35.1
360 +
361
362 diff --git a/sci-libs/keras/keras-2.10.0.ebuild b/sci-libs/keras/keras-2.10.0.ebuild
363 new file mode 100644
364 index 000000000000..8ee2fa5059b1
365 --- /dev/null
366 +++ b/sci-libs/keras/keras-2.10.0.ebuild
367 @@ -0,0 +1,85 @@
368 +# Copyright 1999-2022 Gentoo Authors
369 +# Distributed under the terms of the GNU General Public License v2
370 +
371 +EAPI=8
372 +
373 +PYTHON_COMPAT=( python3_{8,9,10} )
374 +inherit bazel distutils-r1
375 +
376 +DESCRIPTION="Deep Learning for humans"
377 +HOMEPAGE="https://keras.io/"
378 +
379 +LICENSE="Apache-2.0"
380 +SLOT="0"
381 +KEYWORDS="~amd64"
382 +IUSE=""
383 +
384 +bazel_external_uris="
385 + https://github.com/bazelbuild/rules_cc/archive/b1c40e1de81913a3c40e5948f78719c28152486d.zip -> bazelbuild-rules_cc-b1c40e1de81913a3c40e5948f78719c28152486d.zip
386 + https://github.com/bazelbuild/rules_java/archive/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip -> bazelbuild-rules_java-7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip"
387 +
388 +SRC_URI="https://github.com/keras-team/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz
389 + ${bazel_external_uris}"
390 +
391 +RDEPEND="
392 + >=dev-libs/protobuf-3.13.0:=
393 + dev-python/absl-py[${PYTHON_USEDEP}]
394 + dev-python/h5py[${PYTHON_USEDEP}]
395 + dev-python/numpy[${PYTHON_USEDEP}]
396 + dev-python/pandas[${PYTHON_USEDEP}]
397 + dev-python/pillow[${PYTHON_USEDEP}]
398 + >=dev-python/protobuf-python-3.13.0[${PYTHON_USEDEP}]
399 + dev-python/six[${PYTHON_USEDEP}]
400 + >=sci-libs/keras-applications-1.0.8[${PYTHON_USEDEP}]
401 + >=sci-libs/keras-preprocessing-1.1.2[${PYTHON_USEDEP}]
402 + >=sci-libs/tensorflow-2.10[python,${PYTHON_USEDEP}]"
403 +DEPEND="${RDEPEND}
404 + dev-python/setuptools[${PYTHON_USEDEP}]"
405 +BDEPEND="
406 + app-arch/unzip
407 + >=dev-libs/protobuf-3.13.0
408 + dev-java/java-config
409 + >=dev-util/bazel-4.2.2"
410 +
411 +# Bazel tests not pytest, also want GPU access
412 +RESTRICT="test"
413 +DOCS=( CONTRIBUTING.md README.md )
414 +PATCHES=(
415 + "${FILESDIR}/keras-2.10.0-0001-bazel-Use-system-protobuf.patch"
416 +)
417 +
418 +src_unpack() {
419 + unpack "${P}.tar.gz"
420 + bazel_load_distfiles "${bazel_external_uris}"
421 +}
422 +
423 +src_prepare() {
424 + bazel_setup_bazelrc
425 + default
426 + python_copy_sources
427 +}
428 +
429 +python_compile() {
430 + pushd "${BUILD_DIR}" >/dev/null || die
431 +
432 + ebazel build //keras/tools/pip_package:build_pip_package
433 + ebazel shutdown
434 +
435 + local srcdir="${T}/src-${EPYTHON/./_}"
436 + mkdir -p "${srcdir}" || die
437 + bazel-bin/keras/tools/pip_package/build_pip_package --src "${srcdir}" || die
438 +
439 + popd || die
440 +}
441 +
442 +src_compile() {
443 + export JAVA_HOME=$(java-config --jre-home)
444 + distutils-r1_src_compile
445 +}
446 +
447 +python_install() {
448 + pushd "${T}/src-${EPYTHON/./_}" >/dev/null || die
449 + esetup.py install
450 + python_optimize
451 + popd || die
452 +}