proud-dentist-22844
04/09/2021, 5:53 PMUnicodeEncodeError
when running ./pants dependencies --type=3rdparty ::
Traceback (most recent call last):
File "./__parse_python_imports.py", line 113, in <module>
print("\n".join(sorted(string_imports)))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 38-40: ordinal not in range(128)
proud-dentist-22844
04/09/2021, 5:54 PM% ./pants dependencies --type=3rdparty :: --print-stacktrace
13:45:03.92 [ERROR] Exception caught: (pants.engine.internals.scheduler.ExecutionError)
File "/Users/jafloyd/.cache/pants/setup/bootstrap-Darwin-x86_64/2.3.0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 246, in run
engine_result = self._perform_run(goals)
File "/Users/jafloyd/.cache/pants/setup/bootstrap-Darwin-x86_64/2.3.0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 167, in _perform_run
return self._perform_run_body(goals, poll=False)
File "/Users/jafloyd/.cache/pants/setup/bootstrap-Darwin-x86_64/2.3.0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 189, in _perform_run_body
poll_delay=(0.1 if poll else None),
File "/Users/jafloyd/.cache/pants/setup/bootstrap-Darwin-x86_64/2.3.0_py37/lib/python3.7/site-packages/pants/init/engine_initializer.py", line 131, in run_goal_rules
goal_product, params, poll=poll, poll_delay=poll_delay
File "/Users/jafloyd/.cache/pants/setup/bootstrap-Darwin-x86_64/2.3.0_py37/lib/python3.7/site-packages/pants/engine/internals/scheduler.py", line 568, in run_goal_rule
self._raise_on_error([t for _, t in throws])
File "/Users/jafloyd/.cache/pants/setup/bootstrap-Darwin-x86_64/2.3.0_py37/lib/python3.7/site-packages/pants/engine/internals/scheduler.py", line 532, in _raise_on_error
wrapped_exceptions=tuple(t.exc for t in throws),
Exception message: 1 Exception encountered:
Engine traceback:
in select
in pants.backend.project_info.dependencies.dependencies
in pants.engine.internals.graph.resolve_targets (st2api/tests/unit/controllers/v1:tests)
in pants.engine.internals.graph.resolve_unexpanded_targets (st2api/tests/unit/controllers/v1:tests)
in pants.engine.internals.graph.resolve_dependencies (st2api/tests/unit/controllers/v1:tests)
in pants.backend.python.dependency_inference.rules.infer_python_dependencies_via_imports (st2api/tests/unit/controllers/v1:tests)
in pants.backend.python.dependency_inference.import_parser.parse_python_imports
in pants.engine.process.fallible_to_exec_result_or_raise
Traceback (most recent call last):
File "/Users/jafloyd/.cache/pants/setup/bootstrap-Darwin-x86_64/2.3.0_py37/lib/python3.7/site-packages/pants/engine/process.py", line 267, in fallible_to_exec_result_or_raise
description.value,
pants.engine.process.ProcessExecutionFailure: Process 'Determine Python imports for st2api/tests/unit/controllers/v1:tests' failed with exit code 1.
stdout:
[snip]
--
stderr:
Traceback (most recent call last):
File "./__parse_python_imports.py", line 113, in <module>
print("\n".join(sorted(string_imports)))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 38-40: ordinal not in range(128)
hundreds-father-404
04/09/2021, 5:55 PMst2api/tests/unit/controllers/v1:tests
with us, i.e. all the test files in that folder? Totally fine if over DMproud-dentist-22844
04/09/2021, 5:56 PMproud-dentist-22844
04/09/2021, 5:56 PMhundreds-father-404
04/09/2021, 7:43 PMdiff --git a/testprojects/src/python/hello/main/BUILD b/testprojects/src/python/hello/main/BUILD
index c83f898cc..f0e17d2f2 100644
--- a/testprojects/src/python/hello/main/BUILD
+++ b/testprojects/src/python/hello/main/BUILD
@@ -1,5 +1,5 @@
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
-python_library(name="lib")
+python_library(name="lib", interpreter_constraints=['==3.6.*'])
pex_binary(name="main", entry_point='main.py')
diff --git a/testprojects/src/python/hello/main/main.py b/testprojects/src/python/hello/main/main.py
index 0b569ea48..ba528a21b 100644
--- a/testprojects/src/python/hello/main/main.py
+++ b/testprojects/src/python/hello/main/main.py
@@ -9,3 +9,7 @@ if __name__ == "__main__":
greetees = sys.argv[1:] or ["world"]
for greetee in greetees:
print(greet(greetee))
+
+"dummy_pack_1.st2.dummy.action_unicode_我爱狗"
+"st2.dummy.action_unicode_我爱狗"
+
Then run ./pants dependencies testprojects/src/python/hello/main/main.py
. The weird thing is using --no-process-execution-local-cleanup
, then running the __run.sh
script, works fine. I suspect this has something to do with environment variables, I'm not sure how else the __run.sh script would diverge from Pants running the processhundreds-father-404
04/09/2021, 7:52 PMinterpreter_constraints=['==3.7.*']
on the python_tests()
target so that Py36 isn't used to parse the imports
Pardon the bug and thank you for the report!happy-kitchen-89482
04/09/2021, 8:00 PMhappy-kitchen-89482
04/09/2021, 8:01 PMhundreds-father-404
04/09/2021, 8:05 PMstring_imports
code path, specifically trying to call "\n".join()
on the collection (see line # from Jacob's stack trace)
Might be worth iterating on that collection and asserting isinstance(x, str)
proud-dentist-22844
04/09/2021, 8:30 PMhundreds-father-404
04/09/2021, 8:32 PMproud-dentist-22844
04/09/2021, 8:34 PMdummy_pack_1.st2.dummy.action_unicode_我爱狗"
st2.dummy.action_unicode_我爱
Why are they “requirement strings”?hundreds-father-404
04/09/2021, 8:35 PM[python-infer].string_imports
, where we attempt to infer deps on strings that look like imports, e.g. importlib.import_module("<http://path.to|path.to>.module")
. It's off by default, but can be useful in repos like Django onesproud-dentist-22844
04/09/2021, 8:39 PMhundreds-father-404
04/09/2021, 8:41 PMproud-dentist-22844
04/09/2021, 8:50 PMproud-dentist-22844
04/09/2021, 8:52 PMhundreds-father-404
04/09/2021, 8:54 PM[python-setup].interpreter_constraints
option, which sets the default for every Python target. You can then override it by setting interpreter_constraints
field on individual targets. https://www.pantsbuild.org/docs/python-interpreter-compatibility
But, you're right that the workaround could cause issues if your repo is very strictly Py36. If you set those specific tests to be ==3.7, all the code they depend on would need to be compatible with 3.7 too, e.g. >=3.6,<3.8
. Which it sounds like you do not want to do yet. Checkout this tip to see what would need to be updated by activating this backend and then running ./pants py-constraints st2api/tests/unit/controllers/v1:tests
hundreds-father-404
04/09/2021, 8:55 PMproud-dentist-22844
04/09/2021, 9:34 PMproud-dentist-22844
04/09/2021, 9:34 PMpolite-garden-50641
04/10/2021, 12:27 AMpolite-garden-50641
04/10/2021, 12:28 AMpants lint ::
) is something to do with a schema json file
File "/Users/asher/.cache/pants/named_caches/pex_root/venvs/short/2149e2c0/lib/python3.8/site-packages/astroid/transforms.py", line 57, in _visit
return self._transform(node)
File "/Users/asher/.cache/pants/named_caches/pex_root/venvs/short/2149e2c0/lib/python3.8/site-packages/astroid/transforms.py", line 40, in _transform
ret = transform_func(node)
File "pylint_plugins/api_models.py", line 49, in transform
module = __import__(module_name, fromlist=[class_name])
File "/private/var/folders/hv/p6g7p3p95d19gtm5cfkrk5w00000gn/T/process-execution0GJVND/st2common/st2common/models/api/pack.py", line 25, in <module>
from st2common.util import schema as util_schema
File "/private/var/folders/hv/p6g7p3p95d19gtm5cfkrk5w00000gn/T/process-execution0GJVND/st2common/st2common/util/schema/__init__.py", line 53, in <module>
"draft4": jsonify.load_file(os.path.join(PATH, "draft4.json")),
File "/private/var/folders/hv/p6g7p3p95d19gtm5cfkrk5w00000gn/T/process-execution0GJVND/st2common/st2common/util/jsonify.py", line 140, in load_file
with open(path, "r") as fd:
FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/hv/p6g7p3p95d19gtm5cfkrk5w00000gn/T/process-execution0GJVND/st2common/st2common/util/schema/draft4.json'
polite-garden-50641
04/10/2021, 12:29 AMpolite-garden-50641
04/10/2021, 12:29 AMpolite-garden-50641
04/10/2021, 12:30 AMeval "$(pyenv init -)" && pyenv global 3.8.6
to make sure the correct python is available to pants.proud-dentist-22844
04/10/2021, 1:52 AMhappy-kitchen-89482
04/10/2021, 1:56 AMhappy-kitchen-89482
04/10/2021, 1:58 AMhappy-kitchen-89482
04/10/2021, 2:03 AM\w*
parthappy-kitchen-89482
04/10/2021, 2:04 AMhappy-kitchen-89482
04/10/2021, 2:39 AM"\n".join()
part, that is joining unicode strings just fine. The issue is trying to print()
a unicode string without explicitly encoding it, so python tries to encode it with the default encoding, which is ascii
in some cases.happy-kitchen-89482
04/10/2021, 2:39 AMhappy-kitchen-89482
04/10/2021, 5:05 AMproud-dentist-22844
04/10/2021, 5:51 PMproud-dentist-22844
04/10/2021, 5:52 PMhappy-kitchen-89482
04/10/2021, 6:34 PMproud-dentist-22844
04/10/2021, 7:54 PMhundreds-father-404
04/28/2021, 11:45 PMSo, it’s collecting the possible string_imports even though that option is off?Now fixed in 2.5, which gives an ever so slight perf boost: https://github.com/pantsbuild/pants/pull/11975