[ 
https://issues.apache.org/jira/browse/BEAM-9136?focusedWorklogId=412305&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-412305
 ]

ASF GitHub Bot logged work on BEAM-9136:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 30/Mar/20 12:31
            Start Date: 30/Mar/20 12:31
    Worklog Time Spent: 10m 
      Work Description: tvalentyn commented on pull request #11067: 
[BEAM-9136]Add licenses for dependencies for Python
URL: https://github.com/apache/beam/pull/11067#discussion_r399719813
 
 

 ##########
 File path: sdks/python/container/license_scripts/pull_licenses_py.py
 ##########
 @@ -0,0 +1,153 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""A script to pull licenses for Python.
+"""
+import json
+import os
+import shutil
+import subprocess
+import sys
+import wget
+import yaml
+
+from tenacity import retry
+from tenacity import stop_after_attempt
+
+
+def run_bash_command(command):
+  process = subprocess.Popen(
+      command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  result, error = process.communicate()
+  if error:
+    raise RuntimeError(
+        'Error occurred when running a bash command.',
+        'command: {command}, error: {error}'.format(
+            command=command, error=error.decode('utf-8')),
+    )
+  return result.decode('utf-8')
+
+
+def run_pip_licenses():
+  command = 'pip-licenses --with-license-file --format=json'
+  dependencies = run_bash_command(command)
+  return json.loads(dependencies)
+
+
+@retry(stop=stop_after_attempt(3))
+def copy_license_files(dep):
+  source_license_file = dep['LicenseFile']
+  if source_license_file.lower() == 'unknown':
+    return False
+  name = dep['Name'].lower()
+  dest_dir = '/'.join([license_dir, name])
+  try:
+    os.mkdir(dest_dir)
+    shutil.copy(source_license_file, dest_dir + '/LICENSE')
+    print(
+        'Successfully pulled license for {dep} with pip-licenses.'.format(
+            dep=name))
+    return True
+  except Exception as e:
+    print(e)
+    return False
 
 Review comment:
   Tenacity documentation says `@retry` will retry whenever an Exception occurs 
until a value is returned. So I think in this case, the function will return a 
value `False`, and we will not retry anymore.
   
   
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 412305)
    Time Spent: 12h 10m  (was: 12h)

> Add LICENSES and NOTICES to docker images
> -----------------------------------------
>
>                 Key: BEAM-9136
>                 URL: https://issues.apache.org/jira/browse/BEAM-9136
>             Project: Beam
>          Issue Type: Task
>          Components: build-system
>            Reporter: Hannah Jiang
>            Assignee: Hannah Jiang
>            Priority: Major
>          Time Spent: 12h 10m
>  Remaining Estimate: 0h
>
> Scan dependencies and add licenses and notices of the dependencies to SDK 
> docker images.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to