Skip to content

Commit

Permalink
Port the plugin resolver test to v2 test style. (#10424)
Browse files Browse the repository at this point in the history
Previously it used some hackery to get hold of various
subsystems to construct a pex to run setup.py, in order
to create the plugin dists it then tested against.

This change uses v2 test idioms to create and run
that pex.

As a result, we can delete a lot of code that only
hung around because of this one test.

Unfortunately, this required making the test functions
methods of a test class, meaning we can no longer
use pytest.mark.parameterize, and have to "parameterize"
manually.

[ci skip-rust-tests]
  • Loading branch information
benjyw committed Jul 22, 2020
1 parent 8105c6b commit e4b6476
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 728 deletions.
29 changes: 28 additions & 1 deletion src/python/pants/backend/python/rules/inject_ancestor_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import itertools
import os
from dataclasses import dataclass
from pathlib import PurePath
from typing import Sequence, Set

from pants.core.util_rules.strip_source_roots import SourceRootStrippedSources, StripSnapshotRequest
from pants.engine.fs import EMPTY_SNAPSHOT, PathGlobs, Snapshot
from pants.engine.rules import rule
from pants.engine.selectors import Get
from pants.python.pex_build_util import identify_missing_ancestor_files
from pants.source.source_root import AllSourceRoots
from pants.util.ordered_set import FrozenOrderedSet

Expand Down Expand Up @@ -41,6 +42,32 @@ class AncestorFiles:
snapshot: Snapshot


def identify_missing_ancestor_files(name: str, sources: Sequence[str]) -> FrozenOrderedSet[str]:
"""Return the paths of potentially missing ancestor files.
NB: If the sources have not had their source roots (e.g., 'src/python') stripped, this
function will consider superfluous files at and above the source roots, (e.g.,
src/python/<name>, src/<name>). It is the caller's responsibility to filter these
out if necessary. If the sources have had their source roots stripped, then this function
will only identify consider files in actual packages.
"""
packages: Set[str] = set()
for source in sources:
if not source.endswith(".py"):
continue
pkg_dir = os.path.dirname(source)
if not pkg_dir or pkg_dir in packages:
continue
package = ""
for component in pkg_dir.split(os.sep):
package = os.path.join(package, component)
packages.add(package)

return FrozenOrderedSet(
sorted({os.path.join(package, name) for package in packages} - set(sources))
)


@rule
async def find_missing_ancestor_files(
request: AncestorFilesRequest, all_source_roots: AllSourceRoots
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
AncestorFiles,
AncestorFilesRequest,
find_missing_ancestor_files,
identify_missing_ancestor_files,
)
from pants.core.util_rules import strip_source_roots
from pants.engine.fs import DigestContents
Expand Down Expand Up @@ -89,3 +90,29 @@ def test_stripped(self) -> None:
],
expected_discovered=["project/__init__.py"],
)


def test_identify_missing_ancestor_files() -> None:
assert {"a/__init__.py", "a/b/__init__.py", "a/b/c/d/__init__.py"} == set(
identify_missing_ancestor_files(
"__init__.py", ["a/b/foo.py", "a/b/c/__init__.py", "a/b/c/d/bar.py", "a/e/__init__.py"]
)
)

assert {
"src/__init__.py",
"src/python/__init__.py",
"src/python/a/__init__.py",
"src/python/a/b/__init__.py",
"src/python/a/b/c/d/__init__.py",
} == set(
identify_missing_ancestor_files(
"__init__.py",
[
"src/python/a/b/foo.py",
"src/python/a/b/c/__init__.py",
"src/python/a/b/c/d/bar.py",
"src/python/a/e/__init__.py",
],
)
)
45 changes: 0 additions & 45 deletions src/python/pants/python/executable_pex_tool.py

This file was deleted.

Loading

0 comments on commit e4b6476

Please sign in to comment.