<#18618 Invalid isort configuration is silently ig...
# github-notifications
c
#18618 Invalid isort configuration is silently ignored Issue created by huonw Describe the bug When an isort config file (
.isort.cfg
or
pyproject.toml
) is invalid,
isort
just emits a warning, and the whole invocation succeeds (exit code = 0). The invocation succeeding means
pants fmt ::
won't surface the warning, and thus people may be unintentionally running with a default isort configuration if they made a mistake while editing the configuration. NB. fixing this to be an error instead may be a breaking change, since
pants fmt ::
invocations with invalid config were previously succeeding and would start failing. Reproducer, configured to generate an invalid
.isort.cfg
by default, but can be switched to `pyproject.toml`:
Copy code
cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.15.0"

backend_packages = [
  "pants.backend.python",
  "pants.backend.python.lint.isort",
]

[anonymous-telemetry]
enabled = false
EOF

if true; then # switch to false to generate pyproject.toml
  cat > .isort.cfg <<EOF
[settings]
force_single_line = true
# invalid setting:
no_sections = this should be a bool, but isnt
EOF
else
  cat > pyproject.toml <<EOF
[tool.isort]
force_single_line = true
# invalid setting:
no_sections = "this should be a bool, but isnt"
EOF
fi

cat > example.py <<EOF
from foo import bar, baz
EOF

echo "BUG: this does _NOT_ fix example.py"
pants fmt ::

cat example.py

echo "Running outside of pants:"
pants export --resolve=isort
dist/export/python/virtualenvs/isort/*/bin/isort .
Running
bash run.sh
gives output:
Copy code
BUG: this does _NOT_ fix example.py
09:12:01.84 [INFO] Initializing scheduler...
09:12:02.27 [INFO] Scheduler initialized.
from foo import bar, baz
Copy code
Running outside of pants:
Wrote mutable virtualenv for isort (using Python 3.7.13) to dist/export/python/virtualenvs/isort
/private/var/folders/sv/vd266m4d4lvctgs2wpnhjs9w0000gn/T/tmp.0BEDipYZ/dist/export/python/virtualenvs/isort/3.7.13/lib/python3.7/site-packages/isort/settings.py:771: UserWarning: Failed to pull configuration information from /private/var/folders/sv/vd266m4d4lvctgs2wpnhjs9w0000gn/T/tmp.0BEDipYZ/.isort.cfg
  warn(f"Failed to pull configuration information from {potential_config_file}")
Skipped 2 files
In particular, note: • the
example.py
isn't changed: it should become
from foo import bar
from foo import baz
on separate lines due to
force_single_line = true
• running isort directly gives a
Failed to pull configuration information from ...
warning Pants version 2.15.0 OS macOS Additional info N/A pantsbuild/pants