예제 #1
0
 def test_interpreter_constraints_parsing(self):
   python_setup = global_subsystem_instance(PythonSetup)
   target_adaptors = [
     # NB: This target will use the global --python-setup-interpreter-constraints.
     PythonTargetAdaptor(compatibility=None),
     PythonTargetAdaptor(compatibility=["CPython>=400"]),
   ]
   self.assertEqual(
     parse_interpreter_constraints(python_setup, target_adaptors),
     [
       "--interpreter-constraint", "CPython>=2.7,<3",
       "--interpreter-constraint", "CPython>=3.6,<4",
       "--interpreter-constraint", "CPython>=400"
     ]
   )
예제 #2
0
 def run_bandit(
   self,
   source_files: List[FileContent],
   *,
   config: Optional[str] = None,
   passthrough_args: Optional[str] = None,
   interpreter_constraints: Optional[str] = None,
   skip: bool = False,
 ) -> LintResult:
   args = ["--backend-packages2=pants.backend.python.lint.bandit"]
   if config:
     # TODO: figure out how to get this file to exist...
     self.create_file(relpath=".bandit", contents=config)
     args.append("--bandit-config=.bandit")
   if passthrough_args:
     args.append(f"--bandit-args={passthrough_args}")
   if skip:
     args.append(f"--bandit-skip")
   input_snapshot = self.request_single_product(Snapshot, InputFilesContent(source_files))
   target = BanditTarget(
     PythonTargetAdaptor(
       sources=EagerFilesetWithSpec('test', {'globs': []}, snapshot=input_snapshot),
       address=Address.parse("test:target"),
       compatibility=[interpreter_constraints] if interpreter_constraints else None,
     )
   )
   return self.request_single_product(
     LintResult, Params(target, create_options_bootstrapper(args=args)),
   )
예제 #3
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()))
예제 #4
0
 def make_target_with_origin(
     self,
     source_files: List[FileContent],
     *,
     interpreter_constraints: Optional[str] = None,
     origin: Optional[OriginSpec] = None,
 ) -> PythonTargetAdaptorWithOrigin:
     input_snapshot = self.request_single_product(Snapshot, InputFilesContent(source_files))
     adaptor_kwargs = dict(
         sources=EagerFilesetWithSpec("test", {"globs": []}, snapshot=input_snapshot),
         address=Address.parse("test:target"),
     )
     if interpreter_constraints:
         adaptor_kwargs["compatibility"] = interpreter_constraints
     if origin is None:
         origin = SingleAddress(directory="test", name="target")
     return PythonTargetAdaptorWithOrigin(PythonTargetAdaptor(**adaptor_kwargs), origin)