https://pantsbuild.org/ logo
f

fast-nail-55400

04/19/2022, 10:37 PM
I’d like to use lock files in a JVM test to avoid having to code a whole bunch of jar metadata into Python code. Is there a preferred way to be able to generate and use lock files in that manner?
essentially the lock file would be a test fixture
h

hundreds-father-404

04/19/2022, 10:37 PM
Like load it as a resource?
f

fast-nail-55400

04/19/2022, 10:38 PM
exactly
h

hundreds-father-404

04/19/2022, 10:38 PM
No prior convention
f

fast-nail-55400

04/19/2022, 10:38 PM
to clarify, it wouldn’t be a python resource, just a test fixture for the test
my question is really on how to trigger regenerating the lockfile
since test code should not be hooked up into the
generate-lockfiles
goal
That is, manually generate it. When manually generating, set this option so that future readers know how to manually regenerate
f

fast-nail-55400

04/19/2022, 10:40 PM
right but that would still mean having a LockfileSentinnel (or whatever it is called) for tests,
h

hundreds-father-404

04/19/2022, 10:40 PM
What are you testing? If it's a real tool, can you coerce the options for pants to generate a lock file for that tool
f

fast-nail-55400

04/19/2022, 10:41 PM
versus having a script that could use a
RuleRunner
to invoke the correct logic and write out the lock file
it’s for various JVM tests where we currently hard-code a whole bunch of artifacts
via
TestCoursierWrapper
updating those artifacts is a chore which had me copying SHA-256 hashes into Python after manually running
sha256sum
👍 1
trying to avoid that chore
h

hundreds-father-404

04/19/2022, 10:43 PM
Rule runner cannot write to the build root, but I think that you can manipulate things like
Path(get_buildroot())
maybe
f

fast-nail-55400

04/19/2022, 10:44 PM
well a helper script that does a resolve via
RuleRunner
and then gets some output it writes to disk outside of the engine could work
coke 1
h

hundreds-father-404

04/19/2022, 10:44 PM
or use a pex_binary script to generate fixtures?
Yeah that sounds better. I was envisioning doing it within the test goal, but that's a horrible idea
f

fast-nail-55400

04/19/2022, 10:44 PM
yeah no, these are test fixtures that should only be read during tests
otherwise we would sort of invalidate the test by having the fixtures potentially vary during the test
👍 1
I was thinking that tests could declare the artifacts for their lock file via annotations read by the external regeneration script.
any way, good discussion with some ideas for me to move forward with. thanks!
❤️ 1
h

hundreds-father-404

04/19/2022, 10:47 PM
Thank you for thinking this through! FYI this is an issue with Python too, only that we punt around it because Python is much more generous with letting you not have a lock file
f

fast-nail-55400

04/19/2022, 11:38 PM
how would I specify in a BUILD file that the regeneration script depends on all of
src/pants/python::
?
I want to be able to run the pytest test collection algorithm to gather the tests and then inspect them for the custom decorator that I have defined caling for a lockfile.
pytets can do that if I find a way to bring all of the python files into the execution sandbox
f

fast-nail-55400

04/19/2022, 11:40 PM
does that include test files though?
h

hundreds-father-404

04/19/2022, 11:40 PM
dont directly use the python_distribution - it would result in pants first building the dist
does that include test files though?
no
f

fast-nail-55400

04/19/2022, 11:41 PM
yeah I need the test files so pytest can introspect them …
h

hundreds-father-404

04/19/2022, 11:42 PM
f

fast-nail-55400

04/19/2022, 11:43 PM
I can just have deps directly on test directories with known lockfiles.
adding a lockfile in another dir will require adding it to the deps list, which is fine for now.
coke 1
h

hundreds-father-404

04/19/2022, 11:43 PM
I want to be able to run the pytest test collection algorithm to gather the tests and then inspect them for the custom decorator that I have defined caling for a lockfile. (
Can you simply hardcode it? Less magical, but avoids a wild goose chase
f

fast-nail-55400

04/19/2022, 11:43 PM
yes I just said that
h

hundreds-father-404

04/19/2022, 11:44 PM
coke == ditto. I sent before seeing you said that
f

fast-nail-55400

04/19/2022, 11:44 PM
👍
async communication pretending to be real time …
🔥 1
🙂
@hundreds-father-404: would love your input on the approach so far, especially around BUILD file stuff