Skip to content

Conversation

cognifloyd
Copy link
Member

@cognifloyd cognifloyd commented Aug 10, 2022

Background

I'm working towards introducing pants. Eventually I would like to use pants to run tests to take advantage of the fine-grained per-file caching of results that accounts for dependencies by python files (pants infers the deps by reading the python files).

In order to use the fine-grained caching, Pants needs to know which tests rely on which fixtures. We could add extra metadata to tie the tests to the fixtures, but that would be an additional maintenance burden that will become out-of-date. We can also include all fixtures for all tests, but then we don't benefit from the fine-grained per-file caching. However, pants can already infer dependencies based on python imports, so that is what this PR (and several follow-up PRs) takes advantage of.

Overview

This PR builds on, and follows the patterns established in, #5699.

This PR does the following:

  • turn every fixture into an importable python module with an __init__.py.
  • add a fixture.py file in each fixture that uses the fixturesloader utils (where helpful) to identify itself with PATH and NAME vars.
  • in every test that uses a given fixture, import PATH and/or NAME vars from that fixture.

This PR updates all fixture packs, skipping any fixtures that need something slightly different (like dummy_pack_7 and dummy_pack_9).
Follow-up PRs will address other fixture packs and other sets of fixtures. I will submit those PRs after this one is merged.

Statistics

Stats for this PR:

32 pack fixtures got 62 new files (a fixture.py in each; a __init__.py in all but 2 pack fixtures which already had it)

All 32 copies of fixture.py have the same 16 lines, 13 of which are our copyright/license header.

The remaining 38 files (=100-62) are test files that use the vars from the pack fixtures.
Lines changed in test files:

  • -298 lines
  • +238 lines = 750 lines - 512 lines (512 = 16 copied lines * 32 fixture.py files)

In order for pants to detect which changes need to be re-run after changing
fixtures, pants needs to be able to infer the relevant dependencies.

We could use a super-level target to depend on everything, but then we lose
the fine-grained invalidation. The only way to tell pants that a test file
is using a particular set of fixtures is via python imports.

So, this adds some boilerplate python in every pack dir:
__init__.py
fixture.py
@cognifloyd cognifloyd added this to the 3.8.0 milestone Aug 10, 2022
@cognifloyd cognifloyd self-assigned this Aug 10, 2022
@cognifloyd cognifloyd requested a review from a team August 10, 2022 21:26
@pull-request-size pull-request-size bot added the size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. label Aug 10, 2022
@cognifloyd
Copy link
Member Author

cognifloyd commented Aug 11, 2022

edit: moved to PR description

@cognifloyd cognifloyd enabled auto-merge (squash) August 11, 2022 01:18
Copy link
Member

@rush-skills rush-skills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

@cognifloyd cognifloyd requested a review from a team August 11, 2022 17:26
@cognifloyd cognifloyd changed the title Use python imports to identify fixtures (part 2) Use python imports to identify fixtures (part 2/6) Aug 11, 2022
@cognifloyd cognifloyd merged commit a9f6d59 into master Aug 17, 2022
@cognifloyd cognifloyd deleted the fixtures-loading-2 branch August 17, 2022 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement maintenance pantsbuild refactor size/XXL PR that changes 1000+ lines. You should absolutely split your PR into several. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants