The docs <Passing arguments> section for the `run`...
# general
The docs Passing arguments section for the
goal mentions running an executable like this:
Copy code
$ ./pants run project/
I am confused — if there is a file
in the
directory, one wouldn’t be able to run it with the command above.
Copy code
Exception message: 1 Exception encountered:

  NoApplicableTargetsException: No applicable files or targets matched. The `run` goal works with these target types:

  * pex_binary

However, you only specified files with these target types:

  * python_library
If I have a
with the name
, then the
target name would be
. Is the documentation slightly misleading or am I missing something obvious?
It does work, if you have a
that uses ``:
Copy code
$ ./pants run src/
Hello from
with this simple repro:
Copy code
$ git diff --staged
diff --git a/pants.toml b/pants.toml
new file mode 100644
index 0000000..d17ff58
--- /dev/null
+++ b/pants.toml
@@ -0,0 +1,6 @@
+pants_version = "2.5.1"
+backend_packages = [
+  'pants.backend.python'
diff --git a/src/BUILD b/src/BUILD
new file mode 100644
index 0000000..2bdbb8a
--- /dev/null
+++ b/src/BUILD
@@ -0,0 +1,6 @@
+    name="cli",
+    entry_point=""
diff --git a/src/ b/src/
new file mode 100644
index 0000000..73b5b7f
--- /dev/null
+++ b/src/
@@ -0,0 +1,9 @@
+def hello():
+    print("Hello from")
+if __name__ == "__main__":
+    hello()
👍 1
✔️ 1
I guess the docs could be clearer, with an example BUILD file showing how to tie it all together..
👍 1
Yeah, it's why we recommend using the entry point as a file name, rather than module name But I see how that's confusing because it does depend on how you set things up
@hundreds-father-404 wow I had no idea you could do a file name
— I haven’t seen a single simple example like this online! So your recommendation is to use the file name in the entry point, right? Is it specifically to allow
./pants run project/
commands? FWIW, having
Copy code
lets one do both:
Copy code
$ ./pants run project:custom-pex-name
$ ./pants run project/
Hm, have you been seeing examples that don't use file name? I tried to audit everywhere to update to use it because it's preferred, but may have missed some places See for more
Is it specifically to allow ./pants run project/ commands?
Yep, exactly! And less boilerplate than
🙏 1
have you been seeing examples that don’t use file name?
I mean online on Python related resources, not Pants docs 🙂 E.g.
Copy code
        'console_scripts': [
            'yourscript = yourpackage.scripts.yourscript:cli',
And less boilerplate than
Wouldn’t you need to provide the full path to the file (in case it’s some nested directory)? So the difference would be to use a
instead of
? I guess I am missing something important here, sorry 😞
reading the docs page you’ve shared now, I’ve totally missed this, hugely useful
oh I understand now why I haven’t seen the file path examples online — because standard
Python expects a module, but Pants does the conversion. And the path is relative to the
, it all makes sense now
Yep, exactly on Pants doing the conversion :)