chilly-tailor-75063
01/04/2023, 9:22 PM./pant fmt ::
multiple times in a row, it reports that changes were made each time. Why is that?bitter-ability-32190
01/04/2023, 9:24 PMchilly-tailor-75063
01/04/2023, 9:24 PMbitter-ability-32190
01/04/2023, 9:24 PMhttps://media.giphy.com/media/eunDUhLbOz1vEZfFXl/giphy-downsized.gif▾
isort
?chilly-tailor-75063
01/04/2023, 9:26 PMplain-night-51324
01/04/2023, 9:26 PMbitter-ability-32190
01/04/2023, 9:27 PMchilly-tailor-75063
01/04/2023, 9:27 PMplain-night-51324
01/04/2023, 9:28 PMbitter-ability-32190
01/04/2023, 9:28 PMchilly-tailor-75063
01/04/2023, 9:29 PMpants.toml
file:
[GLOBAL]
pants_version = "2.14.0"
backend_packages = [
# "pants.backend.docker",
# "pants.backend.docker.lint.hadolint",
"pants.backend.python",
"pants.backend.build_files.fmt.black",
"pants.backend.python.lint.black",
"pants.backend.python.lint.isort",
"pants.backend.python.lint.pylint",
"pants.backend.python.typecheck.mypy",
]
[python]
tailor_pex_binary_targets = false
interpreter_constraints = ["CPython==3.9.*"]
[source]
root_patterns = [
"project/app",
"tests",
]
[anonymous-telemetry]
enabled = false
[pylint]
config = "config/.pylintrc"
[test]
output = "all"
[pytest]
extra_requirements.add = []
[tool.isort]
profile = "black"
line_length = 100
skip_glob = "tests"
[tool.black]
line-length = 100
extend-exclude = "tests"
[tool.pylint."MASTER"]
extension-pkg-whitelist=[
"pydantic",
"pydantic.typing"
]
[tool.pytest.ini_options]
addopts = [
"--import-mode=importlib",
]
plain-night-51324
01/04/2023, 9:32 PMchilly-tailor-75063
01/04/2023, 9:35 PMforce-excluded
generated a lot more “Pants cannot infer owners for the following imports…” messages.broad-processor-92400
01/04/2023, 10:07 PMLooks like I need to change the order of execution of black and isort. Is there a way to make isort run first and then black?I think the order in the
backend_packages
controls the order that they run for fmt
.
---
With isort
specifically, there's https://github.com/pantsbuild/pants/issues/15069 that can result in isort's order changing, but that may not be what you're hitting. Our configuration (that is stable), is:
• `pants.toml`: black first, then isort
• `pyproject.toml`: (I suspect the force_...
etc. aren't relevant, but maybe default_section
is)
[tool.black]
line-length = 88
target-version = ['py39']
skip-magic-trailing-comma = true
[tool.isort]
profile = "black"
py_version = 39
line_length = 88
# attempts to do something similar to zimports
force_single_line = true
force_sort_within_sections = true
order_by_type = false
# FIXME: workaround for <https://github.com/pantsbuild/pants/issues/15069>
default_section = "FIRSTPARTY"
---
I've also noticed that a re-run can report changes even if it doesn't actually make any. I suspect this is if the source code is the same as the last run's output and the invocation is somehow cached/not rerun, but am not sure, although this may not be what you're hitting with your follow-up message about lint
vs fmt
.extend-exclude
and skip_glob
, it may be possible to use __defaults__
(new in 2.14, I believe: https://www.pantsbuild.org/docs/targets#field-default-values) to set skip_black=True
and skip_isort=True
for all python_tests
and python_test_utils
targets, to make the don't-run-on-tests more pants-friendlyplain-night-51324
01/04/2023, 11:06 PMchilly-tailor-75063
01/05/2023, 2:42 PM[tool.isort]
profile = "black"
py_version = 39
line_length = 100
force_single_line = true
force_sort_within_sections = true
order_by_type = true
default_section = "FIRSTPARTY"
filter_files = true
skip_glob = "tests"
[tool.black]
line-length = 100
target-version = ['py39']
skip-magic-trailing-comma = true
force_exclude = "tests"
Using this ./pants fmt ::
and ./pants lint ::
behave in predictable ways, and don’t seem to “undo” each other. Again, thanks very much for your help and insight!enough-analyst-54434
01/05/2023, 4:25 PM