Skip to content

Commit

Permalink
Remove project tree (#11457)
Browse files Browse the repository at this point in the history
### Problem

The `ProjectTree` and `FileSystemProjectTree` classes are obsolete, only being used in actual code in a vestigial fashion in one test helper function.

### Solution

Modify the test helper function to no longer use `FileSystemProjectTree`, adding some type annotations along the way. This allows us to completely remove the `ProjectTree` and `FileSystemProjectTree` code.
  • Loading branch information
gshuflin authored Jan 13, 2021
1 parent d37f4bd commit a3f6119
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 280 deletions.
55 changes: 0 additions & 55 deletions src/python/pants/base/file_system_project_tree.py

This file was deleted.

187 changes: 0 additions & 187 deletions src/python/pants/base/project_tree.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/python/pants/engine/internals/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
from pants.option.global_options import ExecutionOptions
from pants.util.contextutil import temporary_file_path
from pants.util.logging import LogLevel
from pants.util.ordered_set import FrozenOrderedSet
from pants.util.strutil import pluralize

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -97,7 +96,7 @@ def __init__(
local_execution_root_dir: str,
named_caches_dir: str,
ca_certs_path: Optional[str],
rules: FrozenOrderedSet[Rule],
rules: Iterable[Rule],
union_membership: UnionMembership,
execution_options: ExecutionOptions,
executor: PyExecutor,
Expand Down
47 changes: 12 additions & 35 deletions src/python/pants/engine/internals/scheduler_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import os
import shutil
from dataclasses import asdict

from pants.base.file_system_project_tree import FileSystemProjectTree
from pants.engine.internals.native import Native
from pants.engine.internals.native_engine import PyExecutor
from pants.engine.internals.scheduler import Scheduler, SchedulerSession
from pants.engine.unions import UnionMembership
from pants.option.global_options import DEFAULT_EXECUTION_OPTIONS, ExecutionOptions
from pants.option.global_options import DEFAULT_EXECUTION_OPTIONS
from pants.util.contextutil import temporary_file_path
from pants.util.dirutil import safe_mkdtemp, safe_rmtree

Expand All @@ -29,53 +26,33 @@ def _create_work_dir(self):
self.addCleanup(safe_rmtree, work_dir)
return work_dir

def mk_fs_tree(self, build_root_src=None, ignore_patterns=None, work_dir=None):
"""Create a temporary FilesystemProjectTree.
:param build_root_src: Optional directory to pre-populate from; otherwise, empty.
:returns: A FilesystemProjectTree.
"""
work_dir = work_dir or self._create_work_dir()
build_root = os.path.join(work_dir, "build_root")
if build_root_src is not None:
shutil.copytree(build_root_src, build_root, symlinks=True)
else:
os.makedirs(build_root)
return FileSystemProjectTree(build_root, ignore_patterns=ignore_patterns)

def mk_scheduler(
self,
rules=None,
project_tree=None,
work_dir=None,
include_trace_on_error=True,
execution_options=None,
ca_certs_path=None,
rules,
include_trace_on_error: bool = True,
) -> SchedulerSession:
"""Creates a SchedulerSession for a Scheduler with the given Rules installed."""
rules = rules or []
work_dir = work_dir or self._create_work_dir()
project_tree = project_tree or self.mk_fs_tree(work_dir=work_dir)
work_dir = self._create_work_dir()

build_root = os.path.join(work_dir, "build_root")
os.makedirs(build_root)

local_store_dir = os.path.realpath(safe_mkdtemp())
local_execution_root_dir = os.path.realpath(safe_mkdtemp())
named_caches_dir = os.path.realpath(safe_mkdtemp())
if execution_options is not None:
eo = asdict(DEFAULT_EXECUTION_OPTIONS)
eo.update(execution_options)
execution_options = ExecutionOptions(**eo)
scheduler = Scheduler(
native=self._native,
ignore_patterns=project_tree.ignore_patterns,
ignore_patterns=[],
use_gitignore=False,
build_root=project_tree.build_root,
build_root=build_root,
local_store_dir=local_store_dir,
local_execution_root_dir=local_execution_root_dir,
named_caches_dir=named_caches_dir,
ca_certs_path=ca_certs_path,
ca_certs_path=None,
rules=rules,
union_membership=UnionMembership({}),
executor=self._executor,
execution_options=execution_options or DEFAULT_EXECUTION_OPTIONS,
execution_options=DEFAULT_EXECUTION_OPTIONS,
include_trace_on_error=include_trace_on_error,
)
return scheduler.new_session(
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/engine/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class RuleIndex:
union_rules: FrozenOrderedSet[UnionRule]

@classmethod
def create(cls, rule_entries) -> RuleIndex:
def create(cls, rule_entries: Iterable[Rule]) -> RuleIndex:
"""Creates a RuleIndex with tasks indexed by their output type."""
rules: OrderedSet[TaskRule] = OrderedSet()
queries: OrderedSet[QueryRule] = OrderedSet()
Expand Down

0 comments on commit a3f6119

Please sign in to comment.