Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[internal] Replace bespoke explorer dependency rules with new visibility rules #17573

Merged
merged 3 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ backend_packages.add = [
"pants.backend.experimental.scala",
"pants.backend.experimental.scala.lint.scalafmt",
"pants.backend.experimental.scala.debug_goals",
"pants.backend.experimental.visibility",
"internal_plugins.releases",
"internal_plugins.test_lockfile_fixtures",
]
Expand Down
12 changes: 12 additions & 0 deletions src/python/pants/backend/explorer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ python_tests(
name="tests",
dependencies=[":explorer"],
)


__dependents_rules__(
# Block any outside sources from pulling in code from this backend, as it is self contained and
# have 3rd party dependencies that we don't want to leak to the core Pants distribution.
(
"*",
build_file_dir(),
kaos marked this conversation as resolved.
Show resolved Hide resolved
build_file_dir() / "*",
"!*",
),
)
2 changes: 0 additions & 2 deletions src/python/pants/backend/explorer/graphql/query/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pants.backend.docker.target_types import DockerImageTarget
from pants.backend.explorer.graphql.rules import rules
from pants.backend.explorer.graphql.setup import create_schema
from pants.backend.explorer.rules import validate_explorer_dependencies
from pants.backend.project_info import peek
from pants.engine.environment import EnvironmentName
from pants.engine.explorer import RequestState
Expand Down Expand Up @@ -57,7 +56,6 @@ def fake_consumed_scopes_mapper(scope: str) -> tuple[str, ...]:
def rule_runner() -> RuleRunner:
return RuleRunner(
rules=(
validate_explorer_dependencies,
*peek.rules(),
*rules(),
),
Expand Down
9 changes: 2 additions & 7 deletions src/python/pants/backend/explorer/graphql/query/rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
{"name": r"\.explorer\."},
{
"rules": [
{"name": "pants.backend.explorer.rules.validate_explorer_dependencies"},
{"name": "pants.backend.explorer.graphql.rules.get_graphql_uvicorn_setup"},
]
},
Expand All @@ -27,12 +26,8 @@
},
),
(
{"limit": 1},
{
"rules": [
{"name": "pants.backend.explorer.rules.validate_explorer_dependencies"},
]
},
{"limit": 0},
{"rules": []},
),
(
{"limit": 0},
Expand Down
2 changes: 0 additions & 2 deletions src/python/pants/backend/explorer/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
from __future__ import annotations

from pants.backend.explorer import browser
from pants.backend.explorer import rules as explorer
from pants.backend.explorer.graphql import rules as graphql
from pants.backend.explorer.server import uvicorn


def rules():
return (
*browser.rules(),
*explorer.rules(),
*graphql.rules(),
*uvicorn.rules(),
)
57 changes: 0 additions & 57 deletions src/python/pants/backend/explorer/rules.py

This file was deleted.

3 changes: 2 additions & 1 deletion src/python/pants/backend/visibility/rule_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os.path
from dataclasses import dataclass, field
from fnmatch import fnmatch, fnmatchcase
from pathlib import PurePath
from typing import Any, Iterable, Iterator, Sequence, cast

from pants.engine.internals.dep_rules import (
Expand Down Expand Up @@ -67,7 +68,7 @@ def flatten(xs) -> Iterator[str]:
yield xs
elif isinstance(xs, Iterable):
yield from itertools.chain.from_iterable(flatten(x) for x in xs)
elif type(xs).__name__ == "Registrar":
elif type(xs).__name__ == "Registrar" or isinstance(xs, PurePath):
kaos marked this conversation as resolved.
Show resolved Hide resolved
yield str(xs)
else:
raise ValueError(f"expected a string but got: {xs!r}")
Expand Down
5 changes: 5 additions & 0 deletions src/python/pants/backend/visibility/rule_types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

import logging
from pathlib import PurePath
from textwrap import dedent
from typing import Any

Expand Down Expand Up @@ -71,6 +72,10 @@
),
),
),
(
["src/test"],
PurePath("src/test"),
),
],
)
def test_flatten(expected, xs) -> None:
Expand Down