def make_target_with_origin( self, source_files: List[FileContent], *, name: str = "target", interpreter_constraints: Optional[str] = None, origin: Optional[OriginSpec] = None, dependencies: Optional[List[Address]] = None, ) -> TargetWithOrigin: for source_file in source_files: self.create_file(source_file.path, source_file.content.decode()) source_globs = [ PurePath(source_file.path).name for source_file in source_files ] self.create_library(path=self.source_root, target_type=PythonLibrary.alias, name=name, sources=source_globs) # We must re-write the files because `create_library` will have over-written the content. for source_file in source_files: self.create_file(source_file.path, source_file.content.decode()) target = PythonLibrary( { Sources.alias: source_globs, Dependencies.alias: dependencies, PythonInterpreterCompatibility.alias: interpreter_constraints, }, address=Address(self.source_root, name), ) if origin is None: origin = SingleAddress(directory=self.source_root, name=name) return TargetWithOrigin(target, origin)
def make_target_with_origin( self, source_files: List[FileContent], *, name: str = "target", interpreter_constraints: Optional[str] = None, origin: Optional[OriginSpec] = None, dependencies: Optional[List[Address]] = None, ) -> TargetWithOrigin: for source_file in source_files: self.create_file(source_file.path, source_file.content.decode()) source_globs = [ PurePath(source_file.path).name for source_file in source_files ] self.add_to_build_file( self.source_root, f"python_library(name='{name}', sources={source_globs})\n") target = PythonLibrary( { Sources.alias: source_globs, Dependencies.alias: dependencies, PythonInterpreterCompatibility.alias: interpreter_constraints, }, address=Address(self.source_root, name), ) if origin is None: origin = SingleAddress(directory=self.source_root, name=name) return TargetWithOrigin(target, origin)
def make_target( self, source_files: List[FileContent], *, interpreter_constraints: Optional[str] = None ) -> Target: for source_file in source_files: self.create_file(source_file.path, source_file.content.decode()) return PythonLibrary( {PythonInterpreterCompatibility.alias: interpreter_constraints}, address=Address.parse(":target"), )
def make_target_with_origin( self, source_files: List[FileContent], *, origin: Optional[OriginSpec] = None, ) -> TargetWithOrigin: for source_file in source_files: self.create_file(f"{source_file.path}", source_file.content.decode()) target = PythonLibrary({}, address=Address.parse(":target")) if origin is None: origin = SingleAddress(directory="", name="target") return TargetWithOrigin(target, origin)
def make_target( rule_runner: RuleRunner, source_files: List[FileContent], *, interpreter_constraints: Optional[str] = None, ) -> Target: for source_file in source_files: rule_runner.create_file(source_file.path, source_file.content.decode()) return PythonLibrary( {PythonInterpreterCompatibility.alias: interpreter_constraints}, address=Address("", target_name="target"), )
def make_target_with_origin( self, source_files: List[FileContent], *, interpreter_constraints: Optional[str] = None, origin: Optional[OriginSpec] = None, ) -> TargetWithOrigin: for source_file in source_files: self.create_file(source_file.path, source_file.content.decode()) target = PythonLibrary( {PythonInterpreterCompatibility.alias: interpreter_constraints}, address=Address.parse(":target"), ) if origin is None: origin = SingleAddress(directory="test", name="target") return TargetWithOrigin(target, origin)
def run_black_and_isort( self, source_files: List[FileContent], *, name: str, extra_args: Optional[List[str]] = None ) -> LanguageFmtResults: for source_file in source_files: self.create_file(source_file.path, source_file.content.decode()) target = PythonLibrary({}, address=Address.parse(f"test:{name}")) origin = SingleAddress(directory="test", name=name) targets = PythonFmtTargets(TargetsWithOrigins([TargetWithOrigin(target, origin)])) args = [ "--backend-packages2=['pants.backend.python.lint.black', 'pants.backend.python.lint.isort']", *(extra_args or []), ] results = self.request_single_product( LanguageFmtResults, Params(targets, create_options_bootstrapper(args=args)), ) return results
def run_black_and_isort( rule_runner: RuleRunner, source_files: List[FileContent], *, name: str, extra_args: Optional[List[str]] = None, ) -> LanguageFmtResults: for source_file in source_files: rule_runner.create_file(source_file.path, source_file.content.decode()) targets = PythonFmtTargets(Targets([PythonLibrary({}, address=Address.parse(f"test:{name}"))])) rule_runner.set_options( [ "--backend-packages=['pants.backend.python.lint.black', 'pants.backend.python.lint.isort']", *(extra_args or []), ] ) results = rule_runner.request(LanguageFmtResults, [targets]) return results
def run_black_and_isort( self, source_files: List[FileContent], *, name: str, extra_args: Optional[List[str]] = None) -> LanguageFmtResults: for source_file in source_files: self.create_file(source_file.path, source_file.content.decode()) targets = PythonFmtTargets( Targets([PythonLibrary({}, address=Address.parse(f"test:{name}"))])) args = [ "--backend-packages=['pants.backend.python.lint.black', 'pants.backend.python.lint.isort']", *(extra_args or []), ] results = self.request_product( LanguageFmtResults, [targets, create_options_bootstrapper(args=args)]) return results
def make_target(rule_runner: RuleRunner, source_files: List[FileContent]) -> Target: for source_file in source_files: rule_runner.create_file(f"{source_file.path}", source_file.content.decode()) return PythonLibrary({}, address=Address.parse(":target"))
def rules(): return [ PythonLibrary.register_plugin_field(SkipPylintField), PythonTests.register_plugin_field(SkipPylintField), ]
def make_target_with_origin(self, source_files: List[FileContent]) -> Target: for source_file in source_files: self.create_file(f"{source_file.path}", source_file.content.decode()) return PythonLibrary({}, address=Address.parse(":target"))
def rules(): return [ PythonLibrary.register_plugin_field(SkipDocformatterField), PythonTests.register_plugin_field(SkipDocformatterField), ]