https://pantsbuild.org/ logo
#general
Title
# general
r

rhythmic-glass-66959

07/26/2022, 8:01 PM
How do you copy a Python file when building a Docker image? I get this message:
Copy code
The following files were not found in the Docker build context:
  * src/python/some_package/some_file.py
h

hundreds-father-404

07/26/2022, 8:02 PM
you want it to show up as a loose file, right? THe answer is not very satisfying and @bitter-ability-32190 has been exploring how to improve it In the meantime, keep the
python_sources
targets, but also add a
file
target like this:
Copy code
file(
  name="some_file-file-tgt",
  source="some_file.py",
)
name
can be what you want. Then I think dependency inference should pick it up
b

bitter-ability-32190

07/26/2022, 8:02 PM
Currently, the Docker plugin doesn't consider any
_source
target when constructing the sandbox. Generally it is assumed you'd be first packaging into a
pex_binary
. (FWIW I have a proposal hoping to shift the paradigm here)
h

hundreds-father-404

07/26/2022, 8:03 PM
Currently, the Docker plugin doesn't consider any _source target when constructing the sandbox.
It considers
file
targets
b

bitter-ability-32190

07/26/2022, 8:03 PM
Right, that's not a
_source
target 🙈
r

rhythmic-glass-66959

07/26/2022, 8:04 PM
Ha ok, I'll try the
file
target...
Thank you, adding a
file
target did the trick!
❤️ 1
h

hundreds-father-404

07/26/2022, 8:11 PM
Great! @rhythmic-glass-66959 any thoughts on how we could better document this? https://www.pantsbuild.org/docs/docker
r

rhythmic-glass-66959

07/26/2022, 8:58 PM
Well, maybe add a warning admonition saying that the
python_sources
target won't work for copying Python files. And also, an example in the example-docker repository would be helpful.
👍 1
9 Views