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

Remove unused SingleFileExecutable #10443

Merged
merged 1 commit into from Jul 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/python/pants/backend/project_info/cloc.py
@@ -1,8 +1,6 @@
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from dataclasses import dataclass

from pants.core.util_rules.external_tool import (
DownloadedExternalTool,
ExternalTool,
Expand All @@ -15,7 +13,6 @@
DigestContents,
FileContent,
MergeDigests,
SingleFileExecutable,
SourcesSnapshot,
)
from pants.engine.goal import Goal, GoalSubsystem
Expand All @@ -42,21 +39,6 @@ def generate_url(self, plat: Platform) -> str:
return f"https://github.com/AlDanial/cloc/releases/download/{version}/cloc-{version}.pl"


@dataclass(frozen=True)
class DownloadedClocScript:
"""Cloc script as downloaded from the pantsbuild binaries repo."""

exe: SingleFileExecutable

@property
def script_path(self) -> str:
return self.exe.exe_filename

@property
def digest(self) -> Digest:
return self.exe.digest


class CountLinesOfCodeOptions(GoalSubsystem):
"""Count lines of code."""

Expand Down
36 changes: 1 addition & 35 deletions src/python/pants/engine/fs.py
Expand Up @@ -10,12 +10,7 @@
from pants.engine.rules import RootRule, side_effecting
from pants.option.custom_types import GlobExpansionConjunction as GlobExpansionConjunction
from pants.option.global_options import GlobMatchErrorBehavior as GlobMatchErrorBehavior
from pants.util.dirutil import (
ensure_relative_file_name,
maybe_read_file,
safe_delete,
safe_file_dump,
)
from pants.util.dirutil import maybe_read_file, safe_delete, safe_file_dump
from pants.util.meta import frozen_after_init


Expand Down Expand Up @@ -308,35 +303,6 @@ def materialize_directories(
EMPTY_SNAPSHOT = Snapshot(EMPTY_DIGEST, files=(), dirs=())


@frozen_after_init
@dataclass(unsafe_hash=True)
class SingleFileExecutable:
"""Wraps a `Snapshot` and ensures that it only contains a single file."""

_exe_filename: Path
digest: Digest

@property
def exe_filename(self) -> str:
return ensure_relative_file_name(self._exe_filename)

class ValidationError(ValueError):
pass

@classmethod
def _raise_validation_error(cls, snapshot: Snapshot, should_message: str) -> None:
raise cls.ValidationError(f"snapshot {snapshot} used for {cls} should {should_message}")

def __init__(self, snapshot: Snapshot) -> None:
if len(snapshot.files) != 1:
self._raise_validation_error(snapshot, "have exactly 1 file!")
if snapshot.digest == EMPTY_DIGEST:
self._raise_validation_error(snapshot, "have a non-empty digest!")

self._exe_filename = Path(snapshot.files[0])
self.digest = snapshot.digest


@dataclass(frozen=True)
class SourcesSnapshot:
"""Sources matched by command line specs.
Expand Down
44 changes: 0 additions & 44 deletions src/python/pants/fs/fs_test.py
Expand Up @@ -6,15 +6,12 @@

from pants.engine.console import Console
from pants.engine.fs import (
EMPTY_DIGEST,
CreateDigest,
Digest,
DirectoryToMaterialize,
FileContent,
MaterializeDirectoriesResult,
MaterializeDirectoryResult,
SingleFileExecutable,
Snapshot,
Workspace,
)
from pants.engine.goal import Goal, GoalSubsystem
Expand Down Expand Up @@ -115,44 +112,3 @@ def test_is_child_of(self):

assert not is_child_of(Path("/other/random/directory/root/dist/dir"), mock_build_root)
assert not is_child_of(Path("../not_root/dist/dir"), mock_build_root)


class SingleFileExecutableTest(TestBase):
def test_raises_with_multiple_files(self):
snapshot = self.request_single_product(
Snapshot,
CreateDigest(
[
FileContent(path="a.txt", content=b"test file contents"),
FileContent(path="b.txt", content=b"more test file contents"),
]
),
)

with self.assertRaisesWithMessage(
SingleFileExecutable.ValidationError,
f"snapshot {snapshot} used for {SingleFileExecutable} should have exactly 1 file!",
):
SingleFileExecutable(snapshot)

def test_raises_empty_digest(self):
snapshot = Snapshot(EMPTY_DIGEST, files=("a.txt",), dirs=())

with self.assertRaisesWithMessage(
SingleFileExecutable.ValidationError,
f"snapshot {snapshot} used for {SingleFileExecutable} should have a non-empty digest!",
):
SingleFileExecutable(snapshot)

def test_accepts_single_file_snapshot(self):
snapshot = self.request_single_product(
Snapshot,
CreateDigest([FileContent(path="subdir/a.txt", content=b"test file contents")]),
)
assert SingleFileExecutable(snapshot).exe_filename == "./subdir/a.txt"

snapshot = self.request_single_product(
Snapshot,
CreateDigest([FileContent(path="some_silly_file_name", content=b"test file contents")]),
)
assert SingleFileExecutable(snapshot).exe_filename == "./some_silly_file_name"