rich-kite-32423
12/25/2022, 1:24 AM./pants run main/main.py
18:05:39.93 [ERROR] 1 Exception encountered:
NoApplicableTargetsException: No files or targets specified. The `run` goal works with these target types:
* pex_binary
* python_source
* python_test
Please specify relevant file and/or target arguments. Run `./pants --filter-target-type=pex_binary,python_source,python_test list ::` to find all applicable targets in your project, or run `./pants --filter-target-type=pex_binary,python_source,python_test filedeps ::` to find all applicable files.
But then when I get it going in step3, and go back to step2, sometimes it will run successfully! Very strange.enough-analyst-54434
12/25/2022, 1:33 AMenough-analyst-54434
12/25/2022, 1:33 AMrich-kite-32423
12/25/2022, 1:35 AMenough-analyst-54434
12/25/2022, 1:36 AMrich-kite-32423
12/25/2022, 1:37 AMenough-analyst-54434
12/25/2022, 1:43 AMenough-analyst-54434
12/25/2022, 1:44 AMjsirois@Gill-Windows:~/dev/BruceEckel/ConfiguringForPants/step2 (main) $ chmod +x pants
jsirois@Gill-Windows:~/dev/BruceEckel/ConfiguringForPants/step2 (main *) $ ./pants test ::
17:42:14.66 [INFO] Initializing scheduler...
17:42:14.82 [INFO] Scheduler initialized.
17:42:18.72 [INFO] Canceled: Building pytest.pex from pytest_default.lock
17:42:19.09 [INFO] Completed: Building requirements.pex
17:42:21.09 [INFO] Completed: Building pytest.pex from pytest_default.lock
17:42:21.40 [INFO] Completed: Building local_dists.pex
17:42:22.02 [INFO] Completed: Building pytest_runner.pex
17:42:22.49 [INFO] Completed: Run Pytest - test/math_test.py:tests succeeded.
17:42:22.49 [INFO] Completed: Run Pytest - test/string_test.py:tests succeeded.
17:42:22.64 [ERROR] Completed: Run Pytest - test/main_test.py:tests failed (exit code 2).
============================= test session starts ==============================
platform linux -- Python 3.7.14, pytest-7.0.1, pluggy-1.0.0
rootdir: /tmp/pants-sandbox-Wh2XFV
plugins: forked-1.4.0, cov-3.0.0, xdist-2.5.0
collected 0 items / 1 error
==================================== ERRORS ====================================
______________________ ERROR collecting test/main_test.py ______________________
/home/jsirois/.cache/pants/named_caches/pex_root/venvs/s/8feabfd5/venv/lib/python3.7/site-packages/_pytest/python.py:599: in _importtestmodule
mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
/home/jsirois/.cache/pants/named_caches/pex_root/venvs/s/8feabfd5/venv/lib/python3.7/site-packages/_pytest/pathlib.py:533: in import_path
importlib.import_module(module_name)
/home/jsirois/.pyenv/versions/3.7.14/lib/python3.7/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1006: in _gcd_import
???
<frozen importlib._bootstrap>:983: in _find_and_load
???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:677: in _load_unlocked
???
/home/jsirois/.cache/pants/named_caches/pex_root/venvs/s/8feabfd5/venv/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:171: in exec_module
exec(co, module.__dict__)
test/main_test.py:1: in <module>
from main.main import message
E File "<fstring>", line 1
E (sys.version = )
E ^
E SyntaxError: invalid syntax
-- generated xml file: /tmp/pants-sandbox-Wh2XFV/test.main_test.py.tests.xml ---
=========================== short test summary info ============================
ERROR test/main_test.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.16s ===============================
✓ test/math_test.py:tests succeeded in 0.45s.
✓ test/string_test.py:tests succeeded in 0.46s.
✕ test/main_test.py:tests failed in 0.60s.
rich-kite-32423
12/25/2022, 1:44 AMenough-analyst-54434
12/25/2022, 1:44 AMrich-kite-32423
12/25/2022, 1:45 AMenough-analyst-54434
12/25/2022, 1:45 AMenough-analyst-54434
12/25/2022, 1:45 AMenough-analyst-54434
12/25/2022, 1:47 AMrich-kite-32423
12/25/2022, 1:47 AMbruce@groot:/mnt/c/Git/ConfiguringForPants/step2$ ./pants test ::
18:23:15.23 [INFO] Initializing scheduler...
18:23:15.50 [INFO] Scheduler initialized.
18:23:18.79 [INFO] Completed: Run Pytest - test/math_test.py:tests succeeded.
18:23:18.79 [INFO] Completed: Run Pytest - test/string_test.py:tests succeeded.
18:23:18.79 [INFO] Completed: Run Pytest - test/main_test.py:tests succeeded.
✓ test/main_test.py:tests succeeded in 0.47s (cached locally).
✓ test/math_test.py:tests succeeded in 0.55s (cached locally).
✓ test/string_test.py:tests succeeded in 0.54s (cached locally).
which is different than your output.enough-analyst-54434
12/25/2022, 1:47 AMenough-analyst-54434
12/25/2022, 1:48 AMrich-kite-32423
12/25/2022, 1:48 AMenough-analyst-54434
12/25/2022, 1:48 AMrich-kite-32423
12/25/2022, 1:48 AMenough-analyst-54434
12/25/2022, 1:48 AMenough-analyst-54434
12/25/2022, 1:49 AMrich-kite-32423
12/25/2022, 1:49 AMbruce@groot:/mnt/c/Git/ConfiguringForPants/step2$ ./pants test ::
enough-analyst-54434
12/25/2022, 1:49 AMrich-kite-32423
12/25/2022, 1:50 AMenough-analyst-54434
12/25/2022, 1:50 AMenough-analyst-54434
12/25/2022, 1:50 AMrich-kite-32423
12/25/2022, 1:50 AMenough-analyst-54434
12/25/2022, 1:50 AMrich-kite-32423
12/25/2022, 1:51 AMenough-analyst-54434
12/25/2022, 1:51 AMenough-analyst-54434
12/25/2022, 1:51 AMrich-kite-32423
12/25/2022, 1:52 AMenough-analyst-54434
12/25/2022, 1:53 AMjsirois@Gill-Windows:~/dev/BruceEckel/ConfiguringForPants/step2 (main *) $ git diff
diff --git a/step2/pants b/step2/pants
old mode 100644
new mode 100755
diff --git a/step2/pants.toml b/step2/pants.toml
index e1f06c4..ecb26e3 100644
--- a/step2/pants.toml
+++ b/step2/pants.toml
@@ -3,3 +3,6 @@ pants_version = "2.14.0"
backend_packages = ["pants.backend.python"]
[anonymous-telemetry]
enabled = false
+[python]
+interpreter_constraints = ["CPython==3.10.*"]
+
jsirois@Gill-Windows:~/dev/BruceEckel/ConfiguringForPants/step2 (main *) $ ./pants test ::
17:53:07.39 [INFO] Initializing scheduler...
17:53:07.52 [INFO] Scheduler initialized.
17:53:09.27 [INFO] Canceled: Building pytest.pex from pytest_default.lock
17:53:09.66 [INFO] Completed: Building requirements.pex
17:53:10.78 [INFO] Completed: Building pytest.pex from pytest_default.lock
17:53:11.20 [INFO] Completed: Building local_dists.pex
17:53:11.27 [INFO] Completed: Building requirements.pex with 1 requirement: colored>=1.4.4
17:53:11.87 [INFO] Completed: Building pytest_runner.pex
17:53:11.94 [INFO] Completed: Building pytest_runner.pex
17:53:12.26 [INFO] Completed: Run Pytest - test/string_test.py:tests succeeded.
17:53:12.26 [INFO] Completed: Run Pytest - test/math_test.py:tests succeeded.
17:53:12.32 [INFO] Completed: Run Pytest - test/main_test.py:tests succeeded.
✓ test/main_test.py:tests succeeded in 0.38s.
✓ test/math_test.py:tests succeeded in 0.38s.
✓ test/string_test.py:tests succeeded in 0.38s.
enough-analyst-54434
12/25/2022, 1:55 AMenough-analyst-54434
12/25/2022, 1:58 AMenough-analyst-54434
12/25/2022, 2:00 AMrich-kite-32423
12/25/2022, 5:03 PMrich-kite-32423
12/26/2022, 2:46 AM3_add_features
, I suggested adding
[source]
root_patterns = ["/"]
although I noted that it didn't seem to make any difference.rich-kite-32423
12/26/2022, 3:17 AMchmod +x
on all files that should be executable, this somehow doesn't seem to get uploaded to the git repo.enough-analyst-54434
12/26/2022, 3:22 AMrich-kite-32423
12/26/2022, 3:25 AMenough-analyst-54434
12/26/2022, 3:27 AMsys.path
, but that aside - Pants just needs to know the list of directories where your module / package roots are.
So, for layout:
src/
my_package/
a_module.py
You'd need to tell Pants that `src/`is a source root since your Python code should be importable as from my_package import a_module
and not from <http://src.my|src.my>_package import mymodule
.
Confusing things further is that Pants tries to guess the correct source roots and succeeds sometimes! To me, forcing you to be explicit about this would be more clear, but many people like the seeming convenience of the magic working when it does.enough-analyst-54434
12/26/2022, 3:28 AMenough-analyst-54434
12/26/2022, 3:29 AMproject1/src/
project2/src/
...
Or similar.enough-analyst-54434
12/26/2022, 3:31 AMrich-kite-32423
12/26/2022, 3:32 AMfrom my_package import a_module
and not from <http://src.my|src.my>_package import mymodule
."
In my examples I was not using the first form, so maybe if I try that without the source roots it won't work.
I'll also look at adding interpreter constraints.enough-analyst-54434
12/26/2022, 3:33 AMenough-analyst-54434
12/26/2022, 3:34 AMenough-analyst-54434
12/26/2022, 3:36 AMenough-analyst-54434
12/26/2022, 3:36 AMrich-kite-32423
12/26/2022, 4:50 PMroot_patterns
config key is ["/", "src", "src/python", "src/py", "src/java", "src/scala", "src/thrift", "src/protos", "src/protobuf"]
.
These capture a range of common cases, including a source root at the root of the repository. If your source roots match these patterns, you don't need to explicitly configure them.
That's why it works without configuration, and it says "you don't need to explicitly configure them."enough-analyst-54434
12/26/2022, 4:54 PM