def create_python_awslambda(self, addr: str) -> Tuple[str, bytes]:
     lambdex_setup = self.request_single_product(
         LambdexSetup,
         Params(
             PythonSetup.global_instance(),
             PythonNativeCode.global_instance(),
             SubprocessEnvironment.global_instance(),
             Lambdex.global_instance(),
         ))
     target = self.request_single_product(HydratedTarget,
                                          Address.parse(addr))
     created_awslambda = self.request_single_product(
         CreatedAWSLambda,
         Params(
             target.adaptor,
             lambdex_setup,
             SourceRootConfig.global_instance(),
             PythonSetup.global_instance(),
             PythonNativeCode.global_instance(),
             SubprocessEnvironment.global_instance(),
         ))
     files_content = list(
         self.request_single_product(FilesContent,
                                     Params(created_awslambda.digest)))
     assert len(files_content) == 1
     return created_awslambda.name, files_content[0].content
Beispiel #2
0
 def run_flake8(
     self,
     source_files: List[FileContent],
     *,
     config: Optional[str] = None,
     passthrough_args: Optional[Sequence[str]] = None,
     interpreter_constraints: Optional[Sequence[str]] = None,
     skip: bool = False,
 ) -> LintResult:
     if config is not None:
         self.create_file(relpath=".flake8", contents=config)
     input_snapshot = self.request_single_product(
         Snapshot, InputFilesContent(source_files))
     target = Flake8Target(
         PythonTargetAdaptor(
             sources=EagerFilesetWithSpec('test', {'globs': []},
                                          snapshot=input_snapshot),
             address=Address.parse("test:target"),
             compatibility=interpreter_constraints,
         ))
     flake8_subsystem = global_subsystem_instance(
         Flake8,
         options={
             Flake8.options_scope: {
                 "config": ".flake8" if config else None,
                 "args": passthrough_args or [],
                 "skip": skip,
             }
         })
     return self.request_single_product(
         LintResult,
         Params(target, flake8_subsystem,
                PythonNativeCode.global_instance(),
                PythonSetup.global_instance(),
                SubprocessEnvironment.global_instance()))
Beispiel #3
0
 def subsystem_dependencies(cls):
     return super(BuildLocalPythonDistributions,
                  cls).subsystem_dependencies() + (
                      BuildSetupRequiresPex.scoped(cls),
                      NativeBuildSettings,
                      PythonNativeCode.scoped(cls),
                  )
Beispiel #4
0
    def create_pex_and_get_all_data(
            self,
            *,
            requirements=PexRequirements(),
            entry_point=None,
            interpreter_constraints=PexInterpreterConstraints(),
            input_files: Digest = None) -> (Dict, List[str]):
        def hashify_optional_collection(iterable):
            return tuple(sorted(iterable)) if iterable is not None else tuple()

        request = CreatePex(
            output_filename="test.pex",
            requirements=requirements,
            interpreter_constraints=interpreter_constraints,
            entry_point=entry_point,
            input_files_digest=input_files,
        )
        requirements_pex = self.request_single_product(
            Pex,
            Params(request, PythonSetup.global_instance(),
                   SubprocessEnvironment.global_instance(),
                   PythonNativeCode.global_instance()))
        self.scheduler.materialize_directory(
            DirectoryToMaterialize(requirements_pex.directory_digest), )
        with zipfile.ZipFile(os.path.join(self.build_root, "test.pex"),
                             "r") as pex:
            with pex.open("PEX-INFO", "r") as pex_info:
                pex_info_content = pex_info.readline().decode()
                pex_list = pex.namelist()
        return {
            'pex': requirements_pex,
            'info': json.loads(pex_info_content),
            'files': pex_list
        }
Beispiel #5
0
 def subsystem_dependencies(cls):
     return super(ResolveRequirementsTaskBase,
                  cls).subsystem_dependencies() + (
                      PexBuilderWrapper.Factory,
                      PythonNativeCode.scoped(cls),
                      PythonSetup.scoped(cls),
                  )
 def subsystem_dependencies(cls):
     return super(ResolveRequirementsTaskBase,
                  cls).subsystem_dependencies() + (
                      PythonNativeCode.scoped(cls),
                      PythonRepos,
                      PythonSetup,
                  )
  def create_pex_and_get_pex_info(
    self, *, requirements=None, entry_point=None, interpreter_constraints=None
  ):
    def hashify_optional_collection(iterable):
      return tuple(sorted(iterable)) if iterable is not None else tuple()

    request = RequirementsPexRequest(
      output_filename="test.pex",
      requirements=hashify_optional_collection(requirements),
      interpreter_constraints=hashify_optional_collection(interpreter_constraints),
      entry_point=entry_point,
    )
    requirements_pex = assert_single_element(
      self.scheduler.product_request(RequirementsPex, [Params(
        request,
        PythonSetup.global_instance(),
        PythonNativeCode.global_instance()
      )])
    )
    with temporary_dir() as tmp_dir:
      self.scheduler.materialize_directories((
        DirectoryToMaterialize(path=tmp_dir, directory_digest=requirements_pex.directory_digest),
      ))
      with zipfile.ZipFile(os.path.join(tmp_dir, "test.pex"), "r") as pex:
        with pex.open("PEX-INFO", "r") as pex_info:
          pex_info_content = pex_info.readline().decode()
    return json.loads(pex_info_content)
Beispiel #8
0
 def run_black(
     self,
     source_files: List[FileContent],
     *,
     config: Optional[str] = None,
     passthrough_args: Optional[Sequence[str]] = None,
 ) -> Tuple[LintResult, FmtResult]:
     if config is not None:
         self.create_file(relpath="pyproject.toml", contents=config)
     input_snapshot = self.request_single_product(
         Snapshot, InputFilesContent(source_files))
     target = FormattablePythonTarget(
         TargetAdaptor(
             sources=EagerFilesetWithSpec('test', {'globs': []},
                                          snapshot=input_snapshot),
             address=Address.parse("test:target"),
         ))
     black_subsystem = global_subsystem_instance(
         Black,
         options={
             Black.options_scope: {
                 "config": "pyproject.toml" if config else None,
                 "args": passthrough_args or [],
             }
         })
     black_setup = self.request_single_product(
         BlackSetup,
         Params(
             black_subsystem,
             PythonNativeCode.global_instance(),
             PythonSetup.global_instance(),
             SubprocessEnvironment.global_instance(),
         ))
     fmt_and_lint_params = Params(target, black_setup,
                                  PythonSetup.global_instance(),
                                  SubprocessEnvironment.global_instance())
     lint_result = self.request_single_product(LintResult,
                                               fmt_and_lint_params)
     fmt_result = self.request_single_product(FmtResult,
                                              fmt_and_lint_params)
     return lint_result, fmt_result
 def run_isort(
   self,
   source_files: List[FileContent],
   *,
   config: Optional[str] = None,
   passthrough_args: Optional[Sequence[str]] = None,
   skip: bool = False,
 ) -> Tuple[LintResult, FmtResult]:
   if config is not None:
     self.create_file(relpath=".isort.cfg", contents=config)
   input_snapshot = self.request_single_product(Snapshot, InputFilesContent(source_files))
   target_adaptor = TargetAdaptor(
     sources=EagerFilesetWithSpec('test', {'globs': []}, snapshot=input_snapshot),
     address=Address.parse("test:target"),
   )
   lint_target = IsortTarget(target_adaptor)
   fmt_target = IsortTarget(target_adaptor, prior_formatter_result_digest=input_snapshot.directory_digest)
   isort_subsystem = global_subsystem_instance(
     Isort, options={Isort.options_scope: {
       "config": [".isort.cfg"] if config else None,
       "args": passthrough_args or [],
       "skip": skip,
     }}
   )
   python_subsystems = [
     PythonNativeCode.global_instance(),
     PythonSetup.global_instance(),
     SubprocessEnvironment.global_instance(),
   ]
   isort_setup = self.request_single_product(
     IsortSetup, Params(isort_subsystem, *python_subsystems)
   )
   lint_result = self.request_single_product(
     LintResult, Params(lint_target, isort_setup, *python_subsystems)
   )
   fmt_result = self.request_single_product(
     FmtResult, Params(fmt_target, isort_setup, *python_subsystems)
   )
   return lint_result, fmt_result
Beispiel #10
0
 def subsystem_dependencies(cls):
   return super().subsystem_dependencies() + (
     PexBuilderWrapper.Factory,
     PythonSetup,
     PythonNativeCode.scoped(cls),
   )
 def subsystem_dependencies(cls):
     return super().subsystem_dependencies() + (
         SetupPyRunner.Factory.scoped(cls),
         PythonNativeCode.scoped(cls),
     )
 def subsystem_dependencies(cls):
     return super(
         BuildLocalPythonDistributions,
         cls).subsystem_dependencies() + (PythonNativeCode.scoped(cls), )
Beispiel #13
0
 def subsystem_dependencies(cls):
     return super(PythonBinaryCreate, cls).subsystem_dependencies() + (
         PythonNativeCode.scoped(cls), )
 def subsystem_dependencies(cls):
     return super().subsystem_dependencies() + (
         BuildSetupRequiresPex.scoped(cls),
         PythonNativeCode.scoped(cls),
     )
 def subsystem_dependencies(cls):
   return super(ResolveRequirementsTaskBase, cls).subsystem_dependencies() + (
     PythonNativeCode.scoped(cls),
   )
 def _python_native_code_settings(self):
   return PythonNativeCode.scoped_instance(self)
 def subsystem_dependencies(cls):
   return super(PythonBinaryCreate, cls).subsystem_dependencies() + (PythonNativeCode.scoped(cls),)
 def subsystem_dependencies(cls):
   return super(PythonBinaryCreate, cls).subsystem_dependencies() + (
     PexBuilderWrapper.Factory,
     PythonNativeCode.scoped(cls),
   )
Beispiel #19
0
 def subsystem_dependencies(cls):
     return super(PythonBinaryCreate, cls).subsystem_dependencies() + (
         PexBuilderWrapper.Factory,
         PythonNativeCode.scoped(cls),
     )
 def subsystem_dependencies(cls):
   return super(ResolveRequirementsTaskBase, cls).subsystem_dependencies() + (
     PexBuilderWrapper.Factory,
     PythonSetup,
     PythonNativeCode.scoped(cls),
   )
 def _python_native_code_settings(self):
     return PythonNativeCode.scoped_instance(self)
 def subsystem_dependencies(cls):
   return super(BuildLocalPythonDistributions, cls).subsystem_dependencies() + (
     BuildSetupRequiresPex.scoped(cls),
     PythonNativeCode.scoped(cls),
   )