github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/testing/load_tests/build.gradle (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one
     3   * or more contributor license agreements.  See the NOTICE file
     4   * distributed with this work for additional information
     5   * regarding copyright ownership.  The ASF licenses this file
     6   * to you under the Apache License, Version 2.0 (the
     7   * License); you may not use this file except in compliance
     8   * with the License.  You may obtain a copy of the License at
     9   *
    10   *     http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an AS IS BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  
    20  apply plugin: org.apache.beam.gradle.BeamModulePlugin
    21  applyPythonNature()
    22  
    23  dependencies {
    24      distTarBall project(path: ":sdks:python", configuration: "distTarBall")
    25  }
    26  
    27  description = "Apache Beam :: SDKs :: Python :: Load Tests"
    28  
    29  def mainClassProperty = "loadTest.mainClass"
    30  def mainClass = project.findProperty(mainClassProperty)
    31  
    32  def loadTestArgsProperty = "loadTest.args"
    33  
    34  def runnerProperty = "runner"
    35  
    36  def requirementsTxtFileProperty = "loadTest.requirementsTxtFile"
    37  
    38  task run(type: Exec, dependsOn: installGcpTest) {
    39      def loadTestArgs = project.findProperty(loadTestArgsProperty) ?: ""
    40  
    41      def runnerArg = project.findProperty(runnerProperty) ?: ""
    42      if (runnerArg == 'DataflowRunner' || runnerArg == 'TestDataflowRunner') {
    43          dependsOn ':sdks:python:sdist'
    44          loadTestArgs +=" --sdk_location=${files(configurations.distTarBall.files).singleFile}"
    45      }
    46  
    47      String requirementsTxtFileArg = project.findProperty(requirementsTxtFileProperty) ?: null
    48      if (requirementsTxtFileArg != null) {
    49      doFirst {
    50          exec {
    51            setWorkingDir "${project.rootDir}/sdks/python"
    52            executable 'sh'
    53            args '-c', "${project.ext.envdir}/bin/python -m pip install -r ${requirementsTxtFileArg}"
    54          }
    55       }
    56     }
    57      setWorkingDir "${project.rootDir}/sdks/python"
    58      commandLine 'sh', '-c', "${project.ext.envdir}/bin/python -m ${mainClass} --test-pipeline-options=\"${parseOptions(loadTestArgs)}\" --ignore-files \'.*py3\\d?\\.py\$\'"
    59      ignoreExitValue true
    60  
    61      doLast {
    62          if (execResult.exitValue != 0) {
    63              throw new GradleException('error occurred')
    64          }
    65      }
    66  }
    67  
    68  def parseOptions(String option) {
    69      option.replace('\"', '\\"')
    70  }