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