当前位置: 首页>>代码示例>>Python>>正文


Python Bootstrapper.execute方法代码示例

本文整理汇总了Python中pants.ivy.bootstrapper.Bootstrapper.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Bootstrapper.execute方法的具体用法?Python Bootstrapper.execute怎么用?Python Bootstrapper.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pants.ivy.bootstrapper.Bootstrapper的用法示例。


在下文中一共展示了Bootstrapper.execute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute_junit_runner

# 需要导入模块: from pants.ivy.bootstrapper import Bootstrapper [as 别名]
# 或者: from pants.ivy.bootstrapper.Bootstrapper import execute [as 别名]
  def execute_junit_runner(self, content):

    # Create the temporary base test directory
    test_rel_path = 'tests/java/org/pantsbuild/foo'
    test_abs_path = os.path.join(self.build_root, test_rel_path)
    self.create_dir(test_rel_path)

    # Generate the temporary java test source code.
    test_java_file_rel_path = os.path.join(test_rel_path, 'FooTest.java')
    test_java_file_abs_path = os.path.join(self.build_root, test_java_file_rel_path)
    self.create_file(test_java_file_rel_path, content)

    # Invoke ivy to resolve classpath for junit.
    classpath_file_abs_path = os.path.join(test_abs_path, 'junit.classpath')
    with subsystem_instance(IvySubsystem) as ivy_subsystem:
      distribution = DistributionLocator.cached(jdk=True)
      ivy = Bootstrapper(ivy_subsystem=ivy_subsystem).ivy()
      ivy.execute(args=['-cachepath', classpath_file_abs_path,
                        '-dependency', 'junit', 'junit-dep', '4.10'],
                  executor=SubprocessExecutor(distribution=distribution))

    with open(classpath_file_abs_path) as fp:
      classpath = fp.read()

    # Now directly invoking javac to compile the test java code into java class
    # so later we can inject the class into products mapping for JUnitRun to execute
    # the test on.
    javac = distribution.binary('javac')
    subprocess.check_call(
      [javac, '-d', test_abs_path, '-cp', classpath, test_java_file_abs_path])

    # Create a java_tests target and a synthetic resource target.
    java_tests = self.create_library(test_rel_path, 'java_tests', 'foo_test', ['FooTest.java'])
    resources = self.make_target('some_resources', Resources)

    # Set the context with the two targets, one java_tests target and
    # one synthetic resources target.
    # The synthetic resources target is to make sure we won't regress
    # in the future with bug like https://github.com/pantsbuild/pants/issues/508. Note
    # in that bug, the resources target must be the first one in the list.
    context = self.context(target_roots=[resources, java_tests])

    # Before we run the task, we need to inject the "classes_by_target" with
    # the compiled test java classes that JUnitRun will know which test
    # classes to execute. In a normal run, this "classes_by_target" will be
    # populated by java compiling step.
    class_products = context.products.get_data(
      'classes_by_target', lambda: defaultdict(MultipleRootedProducts))
    java_tests_products = MultipleRootedProducts()
    java_tests_products.add_rel_paths(test_abs_path, ['FooTest.class'])
    class_products[java_tests] = java_tests_products

    # Also we need to add the FooTest.class's classpath to the compile_classpath
    # products data mapping so JUnitRun will be able to add that into the final
    # classpath under which the junit will be executed.
    self.populate_compile_classpath(context=context, classpath=[test_abs_path])

    # Finally execute the task.
    self.execute(context)
开发者ID:sameerparekh,项目名称:pants,代码行数:61,代码来源:test_junit_run.py

示例2: execute_junit_runner

# 需要导入模块: from pants.ivy.bootstrapper import Bootstrapper [as 别名]
# 或者: from pants.ivy.bootstrapper.Bootstrapper import execute [as 别名]
  def execute_junit_runner(self, content, create_some_resources=True, **kwargs):
    # Create the temporary base test directory
    test_rel_path = 'tests/java/org/pantsbuild/foo'
    test_abs_path = self.create_dir(test_rel_path)

    # Generate the temporary java test source code.
    test_java_file_rel_path = os.path.join(test_rel_path, 'FooTest.java')
    test_java_file_abs_path = self.create_file(test_java_file_rel_path, content)

    # Create the temporary classes directory under work dir
    test_classes_abs_path = self.create_workdir_dir(test_rel_path)

    # Invoke ivy to resolve classpath for junit.
    classpath_file_abs_path = os.path.join(test_abs_path, 'junit.classpath')
    ivy_subsystem = global_subsystem_instance(IvySubsystem)
    distribution = DistributionLocator.cached(jdk=True)
    ivy = Bootstrapper(ivy_subsystem=ivy_subsystem).ivy()
    ivy.execute(args=['-cachepath', classpath_file_abs_path,
                      '-dependency', 'junit', 'junit-dep', '4.10'],
                executor=SubprocessExecutor(distribution=distribution))

    with open(classpath_file_abs_path) as fp:
      classpath = fp.read()

    # Now directly invoking javac to compile the test java code into java class
    # so later we can inject the class into products mapping for JUnitRun to execute
    # the test on.
    javac = distribution.binary('javac')
    subprocess.check_call(
      [javac, '-d', test_classes_abs_path, '-cp', classpath, test_java_file_abs_path])

    # If a target_name is specified create a target with it, otherwise create a java_tests target.
    if 'target_name' in kwargs:
      target = self.target(kwargs['target_name'])
    else:
      target = self.create_library(test_rel_path, 'java_tests', 'foo_test', ['FooTest.java'])

    target_roots = []
    if create_some_resources:
      # Create a synthetic resource target.
      target_roots.append(self.make_target('some_resources', Resources))
    target_roots.append(target)

    # Set the context with the two targets, one java_tests target and
    # one synthetic resources target.
    # The synthetic resources target is to make sure we won't regress
    # in the future with bug like https://github.com/pantsbuild/pants/issues/508. Note
    # in that bug, the resources target must be the first one in the list.
    context = self.context(target_roots=target_roots)

    # Before we run the task, we need to inject the "runtime_classpath" with
    # the compiled test java classes that JUnitRun will know which test
    # classes to execute. In a normal run, this "runtime_classpath" will be
    # populated by java compilation step.
    self.populate_runtime_classpath(context=context, classpath=[test_classes_abs_path])

    # Finally execute the task.
    self.execute(context)
开发者ID:UnrememberMe,项目名称:pants,代码行数:60,代码来源:test_junit_run.py

示例3: execute_junit_runner

# 需要导入模块: from pants.ivy.bootstrapper import Bootstrapper [as 别名]
# 或者: from pants.ivy.bootstrapper.Bootstrapper import execute [as 别名]
    def execute_junit_runner(self, content):
        # Create the temporary base test directory
        test_rel_path = "tests/java/org/pantsbuild/foo"
        test_abs_path = self.create_dir(test_rel_path)

        # Generate the temporary java test source code.
        test_java_file_rel_path = os.path.join(test_rel_path, "FooTest.java")
        test_java_file_abs_path = self.create_file(test_java_file_rel_path, content)

        # Create the temporary classes directory under work dir
        test_classes_abs_path = self.create_workdir_dir(test_rel_path)

        # Invoke ivy to resolve classpath for junit.
        classpath_file_abs_path = os.path.join(test_abs_path, "junit.classpath")
        with subsystem_instance(IvySubsystem) as ivy_subsystem:
            distribution = DistributionLocator.cached(jdk=True)
            ivy = Bootstrapper(ivy_subsystem=ivy_subsystem).ivy()
            ivy.execute(
                args=["-cachepath", classpath_file_abs_path, "-dependency", "junit", "junit-dep", "4.10"],
                executor=SubprocessExecutor(distribution=distribution),
            )

        with open(classpath_file_abs_path) as fp:
            classpath = fp.read()

        # Now directly invoking javac to compile the test java code into java class
        # so later we can inject the class into products mapping for JUnitRun to execute
        # the test on.
        javac = distribution.binary("javac")
        subprocess.check_call([javac, "-d", test_classes_abs_path, "-cp", classpath, test_java_file_abs_path])

        # Create a java_tests target and a synthetic resource target.
        java_tests = self.create_library(test_rel_path, "java_tests", "foo_test", ["FooTest.java"])
        resources = self.make_target("some_resources", Resources)

        # Set the context with the two targets, one java_tests target and
        # one synthetic resources target.
        # The synthetic resources target is to make sure we won't regress
        # in the future with bug like https://github.com/pantsbuild/pants/issues/508. Note
        # in that bug, the resources target must be the first one in the list.
        context = self.context(target_roots=[resources, java_tests])

        # Before we run the task, we need to inject the "runtime_classpath" with
        # the compiled test java classes that JUnitRun will know which test
        # classes to execute. In a normal run, this "runtime_classpath" will be
        # populated by java compilation step.
        self.populate_runtime_classpath(context=context, classpath=[test_classes_abs_path])

        # Finally execute the task.
        self.execute(context)
开发者ID:alanpaulin,项目名称:pants,代码行数:52,代码来源:test_junit_run.py


注:本文中的pants.ivy.bootstrapper.Bootstrapper.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。