witty-crayon-22786
10/27/2021, 5:17 PM2.7.1
final: oops.fast-nail-55400
10/27/2021, 7:30 PMwitty-crayon-22786
10/27/2021, 8:42 PM# python3.8:
>>> cast(dict[str, str], dict())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
# python3.9
>>> cast(dict[str, str], dict())
{}
hundreds-father-404
10/27/2021, 8:53 PMcheck
for Java and Go. 🧵fast-nail-55400
10/27/2021, 11:02 PMsrc/python/pants/jvm/goals/coursier_integration_test.py
is failing in CI for me: https://github.com/pantsbuild/pants/runs/4028069406?check_suite_focus=true#step:13:420. I rebased my branch cleanly on top of main
which includes #13295. Any ideas on what is failing?curved-television-6568
10/28/2021, 12:48 AMcurved-television-6568
10/28/2021, 12:52 AMDockerfile
) for the docker_image
target, the engine complains that I don’t have the required file present for the source field:
E File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executioneZewVW/src/python/pants/engine/internals/graph.py", line 792, in hydrate_sources
E sources_field.validate_resolved_files(snapshot.files)
E File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executioneZewVW/src/python/pants/engine/target.py", line 1570, in validate_resolved_files
E f"The {repr(self.alias)} field in target {self.address} must have "
E pants.engine.target.InvalidFieldException: The 'source' field in target src/docker:docker must have 1 file, but it had 0 files.
However, it will be in the Digest.. any way to work around this?
This is what the test looks like:
def test_synthetic_dockerfile(rule_runner: RuleRunner) -> None:
rule_runner.write_files(
{
"src/docker/BUILD": dedent(
"""\
docker_image(dependencies=[":dockerfile"])
dockerfile(
name="dockerfile",
instructions=[
"FROM python:3.8",
"FROM alpine as interim",
"FROM interim",
"FROM scratch:1-1 as output",
]
)
"""
),
}
)
assert_build_context(
rule_runner,
Address("src/docker"),
expected_files=["src/docker/Dockerfile"],
expected_version_context={
"baseimage": {"tag": "3.8"},
"stage0": {"tag": "3.8"},
"interim": {"tag": "latest"},
"stage2": {"tag": "latest"},
"output": {"tag": "1-1"},
},
)
So there’s a codegen for the dockerfile
target, which produces the Dockerfile
which I want the docker_image
to pick up..hundreds-father-404
10/28/2021, 12:54 AMexpected_num_files = 0
. It's happening because SingleSourceField
sets it to 1 as a "reasonable default"
You can use range(0, 2)
if 0-1 is allowedcurved-television-6568
10/28/2021, 12:56 AMhundreds-father-404
10/28/2021, 12:56 AMcurved-television-6568
10/28/2021, 12:57 AMhundreds-father-404
10/28/2021, 12:57 AMcurved-television-6568
10/28/2021, 12:57 AMcurved-television-6568
10/28/2021, 12:58 AMdockerfile
target, but use a file on disk.hundreds-father-404
10/28/2021, 1:00 AMexpected_num_files
Oh! Are you reusing the same sources field for both the synthetic target and normal target? Instead, you can have the synthetic target subclass and override expected_num_files
. Your rules still use DockerSingleSourceField
, and they work just fine with the subclass SyntheticDockerSingleSourceField
The Target API was designed that way precisely for situations like thiscurved-television-6568
10/28/2021, 1:09 AMdocker_image
is the same, regardless of which variant of Dockerfile I choose to use… so I’d say it doesn’t work to do what you suggest in this case (which could be an indication that I should change how I try to do this…)curved-television-6568
10/28/2021, 1:10 AMcurved-television-6568
10/28/2021, 1:12 AMdockerfile
spec part of the docker_image
, that way it’ll be easier to support linting of the synthetic dockerfile (I assume) and also to run codegen export to inspect it, if desired, etc..hundreds-father-404
10/28/2021, 1:13 AMclass DockerSourceField(SingleSourceField):
default = "Dockerfile"
class SyntheticDockerSourceField(DockerSourceField):
default = None
expected_num_files = 0
alias = "_source"
Then your rules use tgt.get(DockerSourceField)
and are agnostic to knowing SyntheticDockerSourceField
exists, beyond needing to set enable_codegen=True
when you're hydrating sourcescurved-television-6568
10/28/2021, 1:25 AMdocker_image
that proved problematic (but I see a way forward, albeit, perhaps not the most elegant yet..)curved-television-6568
10/28/2021, 1:29 AMenable_codegen=True
… aaahhhh, ok, now perhaps it finally dawned on me, ok, give me a minute to digest pun not intended for a while.. 🙂 (or rather, I should go to bed, and continue this at a later time…)busy-vase-39202
10/28/2021, 1:30 AMhundreds-father-404
10/28/2021, 1:30 AMenable_codegen=True
and for_sources_types=(DockerImageSourceField,)
curved-television-6568
10/28/2021, 1:31 AMcurved-television-6568
10/28/2021, 1:33 AMcurved-television-6568
10/28/2021, 1:34 AMbusy-vase-39202
10/28/2021, 1:40 AMfast-nail-55400
10/28/2021, 2:53 AMFrozenDict
always returns its elements in the same order when running repr
on it?hundreds-father-404
10/28/2021, 4:29 AM~/.cache/pants
? As part of https://github.com/pantsbuild/pants/issues/13390, I think it'd be sweet if Pants could share the GOPATH
(downloaded modules) already on your machine. Ditto pipproud-dentist-22844
10/28/2021, 4:43 AM