Another question, python_binary could only accept ...
# general
b
Another question, python_binary could only accept 1 file in sources ?
ERROR: The 'sources' field in target XXXX:XXXX must have 0 or 1 files, but it had 2 files.
could I include more than 1 file for pants binary ?
h
Hi, for
binary
targets, if it uses more than 1 source file, you’ll want to create a
python_library
with the other files and include it in
dependencies
.
python_binary
should either have no source files or one, such as
app.py
or
main.py
. This allows Pants to infer what the
entry_point
is if you end up leaving off that field. For example
Copy code
# example/BUILD

# this will use the default sources of `*.py`
# and the default target name of `example:example`
python_library()

python_binary(
  name="app",
  dependencies=[':example'],
)
b
got it, so for example, I could only put main.py in my binary and all other codes and resources in library ?
h
Exactly. More specifically, you’d put the other Python code in `python_library`(s) and you would put resource files in the
resources()
target
Btw, not sure if I told you this already, but you can run
./pants target-types
to get a list of all the targets and
./pants target-types --details='resources'
to see all of its fields, including which fields are required etc (If that doesn’t work, try
target-types2
)
👍 1
b
Thanks, it works!
💯 1
h
You can also have the
main.py
in the
python_library
and have no sources at all in the
python_binary
(but you then must explicitly specify the
entry_point=
in the
python_binary
). If you have a single source in your
python_binary
then you can leave off the
entry_point=
because Pants will assume that the single source is the entry point module.
👍 2