def test_find_putative_targets_for_entry_points( rule_runner: RuleRunner) -> None: mains = ("main1.py", "main2.py", "main3.py") rule_runner.write_files({ f"src/python/foo/{name}": textwrap.dedent(""" if __name__ == "__main__": main() """) for name in mains }) rule_runner.write_files({ "src/python/foo/BUILD": ("pex_binary(name='main1', entry_point='main1.py')\n" "pex_binary(name='main2', entry_point='foo.main2')\n"), }) pts = rule_runner.request( PutativeTargets, [ PutativePythonTargetsRequest(PutativeTargetsSearchPaths(("", ))), AllOwnedSources([f"src/python/foo/{name}" for name in mains]), ], ) assert (PutativeTargets([ PutativeTarget.for_target_type( PexBinary, "src/python/foo", "main3", [], kwargs={"entry_point": "main3.py"}, ), ]) == pts)
def test_find_putative_targets(rule_runner: RuleRunner) -> None: dir_structure = { "src/python/foo/__init__.py": "", "src/python/foo/bar/BUILD": "python_library(sources=['__init__.py', 'baz1.py'])", "src/python/foo/bar/__init__.py": "", "src/python/foo/bar/baz1.py": "", "src/python/foo/bar/baz1_test.py": "", "src/python/foo/bar/baz2.py": "", "src/python/foo/bar/baz2_test.py": "", "src/python/foo/bar/baz3.py": "", } for path, content in dir_structure.items(): rule_runner.create_file(path, content) pts = rule_runner.request(PutativeTargets, [PutativePythonTargetsRequest()]) assert (PutativeTargets([ PutativeTarget.for_target_type(PythonLibrary, "src/python/foo", "foo", ["__init__.py"]), PutativeTarget.for_target_type(PythonLibrary, "src/python/foo/bar", "bar", ["baz2.py", "baz3.py"]), PutativeTarget.for_target_type( PythonTests, "src/python/foo/bar", "tests", ["baz1_test.py", "baz2_test.py"], kwargs={"name": "tests"}, ), ]) == pts)
def test_ignore_solitary_init(rule_runner: RuleRunner) -> None: rule_runner.write_files({ f"src/python/foo/{fp}": "" for fp in ( "__init__.py", "bar/__init__.py", "bar/bar.py", "baz/__init__.py", "qux/qux.py", ) }) pts = rule_runner.request( PutativeTargets, [ PutativePythonTargetsRequest(PutativeTargetsSearchPaths(("", ))), AllOwnedSources([]), ], ) assert (PutativeTargets([ PutativeTarget.for_target_type( PythonSourcesGeneratorTarget, "src/python/foo/bar", "bar", ["__init__.py", "bar.py"], ), PutativeTarget.for_target_type(PythonSourcesGeneratorTarget, "src/python/foo/qux", "qux", ["qux.py"]), ]) == pts)
def test_find_putative_targets_subset(rule_runner: RuleRunner) -> None: rule_runner.write_files({ f"src/python/foo/{fp}": "" for fp in ( "__init__.py", "bar/__init__.py", "bar/bar.py", "bar/bar_test.py", "baz/baz.py", "baz/baz_test.py", "qux/qux.py", ) }) pts = rule_runner.request( PutativeTargets, [ PutativePythonTargetsRequest( PutativeTargetsSearchPaths( ("src/python/foo/bar", "src/python/foo/qux"))), AllOwnedSources([ "src/python/foo/bar/__init__.py", "src/python/foo/bar/bar.py" ]), ], ) assert (PutativeTargets([ PutativeTarget.for_target_type( PythonTestsGeneratorTarget, "src/python/foo/bar", "tests", ["bar_test.py"], ), PutativeTarget.for_target_type(PythonSourcesGeneratorTarget, "src/python/foo/qux", None, ["qux.py"]), ]) == pts)
def test_skip_invalid_requirements(rule_runner: RuleRunner) -> None: rule_runner.set_options(["--no-python-tailor-ignore-solitary-init-files"]) rule_runner.write_files( { "3rdparty/requirements-valid.txt": b"FooProject >= 1.2", "3rdparty/requirements-invalid.txt": b"FooProject LOLOLOLOL 1.2", "pipfile-valid/Pipfile.lock": b"{}", "pipfile-invalid/Pipfile.lock": b"FNARB", "poetry-valid/pyproject.toml": b"[tool.poetry]", "poetry-invalid/pyproject.toml": b"FNARB", } ) pts = rule_runner.request( PutativeTargets, [ PutativePythonTargetsRequest( ( "3rdparty", "pipfile-valid", "pipfile-invalid", "poetry-valid", "poetry-invalid", ) ), AllOwnedSources([]), ], ) assert ( PutativeTargets( [ PutativeTarget.for_target_type( PythonRequirementsTargetGenerator, path="3rdparty", name="reqs", triggering_sources=["3rdparty/requirements-valid.txt"], kwargs={"source": "requirements-valid.txt"}, ), PutativeTarget.for_target_type( PipenvRequirementsTargetGenerator, path="pipfile-valid", name="pipenv", triggering_sources=["pipfile-valid/Pipfile.lock"], ), PutativeTarget.for_target_type( PoetryRequirementsTargetGenerator, path="poetry-valid", name="poetry", triggering_sources=["poetry-valid/pyproject.toml"], ), ] ) == pts )
def test_find_putative_targets(rule_runner: RuleRunner) -> None: rule_runner.set_options( ["--no-python-setup-tailor-ignore-solitary-init-files"]) rule_runner.write_files({ "3rdparty/requirements.txt": "", "3rdparty/requirements-test.txt": "", **{ f"src/python/foo/{fp}": "" for fp in ( "__init__.py", "bar/__init__.py", "bar/baz1.py", "bar/baz1_test.py", "bar/baz2.py", "bar/baz2_test.py", "bar/baz3.py", ) }, }) pts = rule_runner.request( PutativeTargets, [ PutativePythonTargetsRequest(PutativeTargetsSearchPaths(("", ))), AllOwnedSources([ "3rdparty/requirements.txt", "src/python/foo/bar/__init__.py", "src/python/foo/bar/baz1.py", ]), ], ) assert (PutativeTargets([ PutativeTarget( "3rdparty", "requirements-test.txt", "python_requirements", ("3rdparty/requirements-test.txt", ), ("3rdparty/requirements-test.txt", ), addressable=False, kwargs={"requirements_relpath": "requirements-test.txt"}, ), PutativeTarget.for_target_type(PythonLibrary, "src/python/foo", "foo", ["__init__.py"]), PutativeTarget.for_target_type(PythonLibrary, "src/python/foo/bar", "bar", ["baz2.py", "baz3.py"]), PutativeTarget.for_target_type( PythonTests, "src/python/foo/bar", "tests", ["baz1_test.py", "baz2_test.py"], kwargs={"name": "tests"}, ), ]) == pts)
def test_find_putative_targets() -> None: rule_runner = RuleRunner( rules=[ *tailor.rules(), QueryRule(PutativeTargets, (PutativePythonTargetsRequest, AllOwnedSources)), ], target_types=[], ) rule_runner.write_files({ f"src/python/foo/{fp}": "" for fp in ( "__init__.py", "bar/__init__.py", "bar/baz1.py", "bar/baz1_test.py", "bar/baz2.py", "bar/baz2_test.py", "bar/baz3.py", ) }) pts = rule_runner.request( PutativeTargets, [ PutativePythonTargetsRequest(), AllOwnedSources([ "src/python/foo/bar/__init__.py", "src/python/foo/bar/baz1.py" ]), ], ) assert (PutativeTargets([ PutativeTarget.for_target_type(PythonLibrary, "src/python/foo", "foo", ["__init__.py"]), PutativeTarget.for_target_type(PythonLibrary, "src/python/foo/bar", "bar", ["baz2.py", "baz3.py"]), PutativeTarget.for_target_type( PythonTests, "src/python/foo/bar", "tests", ["baz1_test.py", "baz2_test.py"], kwargs={"name": "tests"}, ), ]) == pts)
def test_find_putative_targets(rule_runner: RuleRunner) -> None: rule_runner.set_options([ "--no-python-tailor-ignore-solitary-init-files", "--no-use-deprecated-python-macros" ]) rule_runner.write_files({ "3rdparty/requirements.txt": "", "3rdparty/requirements-test.txt": "", **{ f"src/python/foo/{fp}": "" for fp in ( "__init__.py", "bar/__init__.py", "bar/baz1.py", "bar/baz1_test.py", "bar/baz2.py", "bar/baz2_test.py", "bar/baz3.py", "bar/conftest.py", ) }, }) pts = rule_runner.request( PutativeTargets, [ PutativePythonTargetsRequest(PutativeTargetsSearchPaths(("", ))), AllOwnedSources([ "3rdparty/requirements.txt", "src/python/foo/bar/__init__.py", "src/python/foo/bar/baz1.py", ]), ], ) assert (PutativeTargets([ PutativeTarget( "3rdparty", "requirements-test.txt", "python_requirements", ("3rdparty/requirements-test.txt", ), ("3rdparty/requirements-test.txt", ), addressable=True, kwargs={"source": "requirements-test.txt"}, ), PutativeTarget.for_target_type(PythonSourcesGeneratorTarget, "src/python/foo", None, ["__init__.py"]), PutativeTarget.for_target_type( PythonSourcesGeneratorTarget, "src/python/foo/bar", None, ["baz2.py", "baz3.py"], ), PutativeTarget.for_target_type( PythonTestsGeneratorTarget, "src/python/foo/bar", "tests", ["baz1_test.py", "baz2_test.py"], ), PutativeTarget.for_target_type( PythonTestUtilsGeneratorTarget, "src/python/foo/bar", "test_utils", ["conftest.py"], ), ]) == pts)
def test_find_putative_targets(rule_runner: RuleRunner) -> None: rule_runner.set_options(["--no-python-tailor-ignore-solitary-init-files"]) rule_runner.write_files( { "3rdparty/Pipfile.lock": "{}", "3rdparty/pyproject.toml": "[tool.poetry]", "3rdparty/requirements-test.txt": "", "already_owned/requirements.txt": "", "already_owned/Pipfile.lock": "", "already_owned/pyproject.toml": "[tool.poetry]", "no_match/pyproject.toml": "# no poetry section", **{ f"src/python/foo/{fp}": "" for fp in ( "__init__.py", "bar/__init__.py", "bar/baz1.py", "bar/baz1_test.py", "bar/baz2.py", "bar/baz2_test.py", "bar/baz3.py", "bar/conftest.py", ) }, } ) pts = rule_runner.request( PutativeTargets, [ PutativePythonTargetsRequest( ("3rdparty", "already_owned", "no_match", "src/python/foo", "src/python/foo/bar") ), AllOwnedSources( [ "already_owned/requirements.txt", "already_owned/Pipfile.lock", "already_owned/pyproject.toml", "src/python/foo/bar/__init__.py", "src/python/foo/bar/baz1.py", ] ), ], ) assert ( PutativeTargets( [ PutativeTarget.for_target_type( PipenvRequirementsTargetGenerator, path="3rdparty", name="pipenv", triggering_sources=["3rdparty/Pipfile.lock"], ), PutativeTarget.for_target_type( PoetryRequirementsTargetGenerator, path="3rdparty", name="poetry", triggering_sources=["3rdparty/pyproject.toml"], ), PutativeTarget.for_target_type( PythonRequirementsTargetGenerator, path="3rdparty", name="reqs", triggering_sources=["3rdparty/requirements-test.txt"], kwargs={"source": "requirements-test.txt"}, ), PutativeTarget.for_target_type( PythonSourcesGeneratorTarget, "src/python/foo", None, ["__init__.py"] ), PutativeTarget.for_target_type( PythonSourcesGeneratorTarget, "src/python/foo/bar", None, ["baz2.py", "baz3.py"], ), PutativeTarget.for_target_type( PythonTestsGeneratorTarget, "src/python/foo/bar", "tests", ["baz1_test.py", "baz2_test.py"], ), PutativeTarget.for_target_type( PythonTestUtilsGeneratorTarget, "src/python/foo/bar", "test_utils", ["conftest.py"], ), ] ) == pts )