Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Persistent configuration #15491

Open
2 of 15 tasks
MichaReiser opened this issue Jan 15, 2025 · 0 comments
Open
2 of 15 tasks

[red-knot] Persistent configuration #15491

MichaReiser opened this issue Jan 15, 2025 · 0 comments
Assignees
Labels
red-knot Multi-file analysis & type inference

Comments

@MichaReiser
Copy link
Member

MichaReiser commented Jan 15, 2025

Support configuring Red Knot in a persistent configuration:

  • Configuration in the project's pyproject.toml or knot.toml.
  • Configuration sections:
    • rules: enable and disable rules
    • environment: (python version, platform, search paths)
    • files: Override a sub-set of settings on a path level
    • src: Which files should be considered first-party and what's the src root
    • terminal: Configure color output, etc.
    • root options (for now, only respect-ignore-files)
    • requires-python (I'm leaning towards just making it a field on ProjectMetadata because we only respect the requires-python constraint in the project's configuration file)
  • Path anchoring in configuration files (relative paths are relative to the current working directory, the configuration file, or the project root)
  • Track the source of a configuration value for better error reporting: E.g. clippy tells you why a rule is enabled. Is it because the rule is enabled by default or because you enabled it in the configuration or in the CLI? Ideally, we'd have this for all options so that we can refer users to the right configuration file if we detect an invalid setting.
  • User-level configuration
  • Support overriding configuration options from the CLI
  • Hierarchical configuration (knot.toml in any ancestor directory)
  • Generate a JSON schema
@MichaReiser MichaReiser added the red-knot Multi-file analysis & type inference label Jan 15, 2025
@MichaReiser MichaReiser added this to the Red Knot Q1 2025 milestone Jan 15, 2025
@MichaReiser MichaReiser self-assigned this Jan 15, 2025
MichaReiser added a commit that referenced this issue Jan 15, 2025
This PR adds support for configuring Red Knot in the `tool.knot` section of the project's
`pyproject.toml` section. Options specified on the CLI take precedence over the
options in the configuration file.

For now, this PR only adds support for the `environment` and the `src.root` options.
Other options will be added as separate PRs.

There are also a few concerns that I intentionally ignored as part of this PR:

* Handling of relative paths: We need to anchor paths relative to the current working directory (CLI), or the project (`pyproject.toml` or `knot.toml`)
* Tracking the source of a value. It would be nice for diagnostics to know from which configuration a value comes so that we can point the user to the right configuration file (or CLI) if the configuration is invalid.
* Schema generation, and there's a lot more, see #15491
MichaReiser added a commit that referenced this issue Jan 15, 2025
This PR adds support for configuring Red Knot in the `tool.knot` section of the project's
`pyproject.toml` section. Options specified on the CLI take precedence over the
options in the configuration file.

For now, this PR only adds support for the `environment` and the `src.root` options.
Other options will be added as separate PRs.

There are also a few concerns that I intentionally ignored as part of this PR:

* Handling of relative paths: We need to anchor paths relative to the current working directory (CLI), or the project (`pyproject.toml` or `knot.toml`)
* Tracking the source of a value. It would be nice for diagnostics to know from which configuration a value comes so that we can point the user to the right configuration file (or CLI) if the configuration is invalid.
* Schema generation, and there's a lot more, see #15491
MichaReiser added a commit that referenced this issue Jan 15, 2025
This PR adds support for configuring Red Knot in the `tool.knot` section of the project's
`pyproject.toml` section. Options specified on the CLI take precedence over the
options in the configuration file.

For now, this PR only adds support for the `environment` and the `src.root` options.
Other options will be added as separate PRs.

There are also a few concerns that I intentionally ignored as part of this PR:

* Handling of relative paths: We need to anchor paths relative to the current working directory (CLI), or the project (`pyproject.toml` or `knot.toml`)
* Tracking the source of a value. It would be nice for diagnostics to know from which configuration a value comes so that we can point the user to the right configuration file (or CLI) if the configuration is invalid.
* Schema generation, and there's a lot more, see #15491
MichaReiser added a commit that referenced this issue Jan 15, 2025
This PR adds support for configuring Red Knot in the `tool.knot` section of the project's
`pyproject.toml` section. Options specified on the CLI take precedence over the
options in the configuration file.

For now, this PR only adds support for the `environment` and the `src.root` options.
Other options will be added as separate PRs.

There are also a few concerns that I intentionally ignored as part of this PR:

* Handling of relative paths: We need to anchor paths relative to the current working directory (CLI), or the project (`pyproject.toml` or `knot.toml`)
* Tracking the source of a value. It would be nice for diagnostics to know from which configuration a value comes so that we can point the user to the right configuration file (or CLI) if the configuration is invalid.
* Schema generation, and there's a lot more, see #15491
MichaReiser added a commit that referenced this issue Jan 16, 2025
This PR adds support for configuring Red Knot in the `tool.knot` section of the project's
`pyproject.toml` section. Options specified on the CLI take precedence over the
options in the configuration file.

For now, this PR only adds support for the `environment` and the `src.root` options.
Other options will be added as separate PRs.

There are also a few concerns that I intentionally ignored as part of this PR:

* Handling of relative paths: We need to anchor paths relative to the current working directory (CLI), or the project (`pyproject.toml` or `knot.toml`)
* Tracking the source of a value. It would be nice for diagnostics to know from which configuration a value comes so that we can point the user to the right configuration file (or CLI) if the configuration is invalid.
* Schema generation, and there's a lot more, see #15491
MichaReiser added a commit that referenced this issue Jan 16, 2025
This PR adds support for configuring Red Knot in the `tool.knot` section of the project's
`pyproject.toml` section. Options specified on the CLI take precedence over the
options in the configuration file.

For now, this PR only adds support for the `environment` and the `src.root` options.
Other options will be added as separate PRs.

There are also a few concerns that I intentionally ignored as part of this PR:

* Handling of relative paths: We need to anchor paths relative to the current working directory (CLI), or the project (`pyproject.toml` or `knot.toml`)
* Tracking the source of a value. It would be nice for diagnostics to know from which configuration a value comes so that we can point the user to the right configuration file (or CLI) if the configuration is invalid.
* Schema generation, and there's a lot more, see #15491
MichaReiser added a commit that referenced this issue Jan 16, 2025
This PR adds support for configuring Red Knot in the `tool.knot` section of the project's
`pyproject.toml` section. Options specified on the CLI take precedence over the
options in the configuration file.

For now, this PR only adds support for the `environment` and the `src.root` options.
Other options will be added as separate PRs.

There are also a few concerns that I intentionally ignored as part of this PR:

* Handling of relative paths: We need to anchor paths relative to the current working directory (CLI), or the project (`pyproject.toml` or `knot.toml`)
* Tracking the source of a value. It would be nice for diagnostics to know from which configuration a value comes so that we can point the user to the right configuration file (or CLI) if the configuration is invalid.
* Schema generation, and there's a lot more, see #15491
MichaReiser added a commit that referenced this issue Jan 17, 2025
## Summary

This PR adds support for configuring Red Knot in the `tool.knot` section
of the project's
`pyproject.toml` section. Options specified on the CLI precede the
options in the configuration file.

This PR only supports the `environment` and the `src.root` options for
now.
Other options will be added as separate PRs.

There are also a few concerns that I intentionally ignored as part of
this PR:

* Handling of relative paths: We need to anchor paths relative to the
current working directory (CLI), or the project (`pyproject.toml` or
`knot.toml`)
* Tracking the source of a value. Diagnostics would benefit from knowing
from which configuration a value comes so that we can point the user to
the right configuration file (or CLI) if the configuration is invalid.
* Schema generation and there's a lot more; see
#15491

This PR changes the default for first party codes: Our existing default
was to only add the project root. Now, Red Knot adds the project root
and `src` (if such a directory exists).

Theoretically, we'd have to add a file watcher event that changes the
first-party search paths if a user later creates a `src` directory. I
think this is pretty uncommon, which is why I ignored the complexity for
now but I can be persuaded to handle it if it's considered important.

Part of #15491

## Test Plan

Existing tests, new file watching test demonstrating that changing the
python version and platform is correctly reflected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

No branches or pull requests

1 participant