robertwb commented on a change in pull request #15857:
URL: https://github.com/apache/beam/pull/15857#discussion_r749781170



##########
File path: sdks/python/apache_beam/utils/subprocess_server.py
##########
@@ -158,7 +161,11 @@ class JavaJarServer(SubprocessServer):
       'local', (threading.local, ),
       dict(__init__=lambda self: setattr(self, 'replacements', {})))()
 
-  def __init__(self, stub_class, path_to_jar, java_arguments):
+  def __init__(self, stub_class, path_to_jar, java_arguments, classpath=None):
+    if classpath or True:

Review comment:
       Thanks for catching this. (I was just trying to run all existing tests 
through this code.)

##########
File path: sdks/python/apache_beam/utils/subprocess_server.py
##########
@@ -283,6 +290,39 @@ def beam_services(cls, replacements):
     finally:
       cls._BEAM_SERVICES.replacements = old
 
+  @classmethod
+  def make_classpath_jar(cls, main_jar, extra_jars, cache_dir=None):

Review comment:
       Done.

##########
File path: sdks/python/apache_beam/utils/subprocess_server.py
##########
@@ -283,6 +290,39 @@ def beam_services(cls, replacements):
     finally:
       cls._BEAM_SERVICES.replacements = old
 
+  @classmethod
+  def make_classpath_jar(cls, main_jar, extra_jars, cache_dir=None):
+    if cache_dir is None:
+      cache_dir = cls.JAR_CACHE
+    composite_jar_dir = os.path.join(cache_dir, 'composite-jars')
+    os.makedirs(composite_jar_dir, exist_ok=True)
+    classpath = []
+    # Class-Path references from a jar must be relative.
+    for pattern in [main_jar] + list(extra_jars):
+      for path in glob.glob(pattern) or [pattern]:
+        rel_path = hashlib.sha256(
+            path.encode('utf-8')).hexdigest() + os.path.splitext(path)[1]
+        classpath.append(rel_path)
+        if not os.path.lexists(os.path.join(composite_jar_dir, rel_path)):
+          os.symlink(path, os.path.join(composite_jar_dir, rel_path))
+    composite_jar = os.path.join(
+        composite_jar_dir,
+        hashlib.sha256(' '.join(sorted(classpath)).encode('ascii')).hexdigest()
+        + '.jar')
+    if not os.path.exists(composite_jar):

Review comment:
       Fair point. The code here is best-effort, but for anything complicated 
you'll have to roll your own expansion service. (It already went deeper into 
jars than I wanted, but otherwise isn't very useful...)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to