Skip to content

Comments

Support knot.toml files in project discovery#15505

Merged
MichaReiser merged 2 commits intomainfrom
micha/knot-toml
Jan 17, 2025
Merged

Support knot.toml files in project discovery#15505
MichaReiser merged 2 commits intomainfrom
micha/knot-toml

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jan 15, 2025

Summary

This PR adds support for knot.toml files during project discovery.

knot.toml files take precedence over any pyproject.toml but we still need to read the pyproject.toml
to get the project's name and any requires-python constraint (not part of this PR).

This PR doesn't add support for:

  • Reading knot.toml files from ancestor directories (hierarchical configuration)
  • Reading a user configuration

Part of astral-sh/ty#219

Test Plan

Added unit test

@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label Jan 15, 2025
Comment on lines 94 to 96
match PyProject::from_toml_str(&pyproject_str) {
Ok(pyproject) => Some(pyproject),
Err(error) => {
return Err(ProjectDiscoveryError::InvalidPyProject {
path: pyproject_path,
source: Box::new(error),
})
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map_err didn't work here (and below). The borrow checker gets mad at me for consuming pyproject_path in the closure and using it further down.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 15, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser marked this pull request as ready for review January 15, 2025 15:57
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

.unwrap_or_else(|| Name::new(root.file_name().unwrap_or("root")))
}

/// Loads a project form a `knot.toml` file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Loads a project form a `knot.toml` file.
/// Loads a project from a `knot.toml` file.

@MichaReiser MichaReiser force-pushed the micha/knot-configuration branch 3 times, most recently from c8a8a01 to b485a63 Compare January 16, 2025 13:54
Base automatically changed from micha/knot-configuration to main January 17, 2025 08:41
@MichaReiser MichaReiser enabled auto-merge (squash) January 17, 2025 08:57
@MichaReiser MichaReiser merged commit fdb9f4e into main Jan 17, 2025
20 checks passed
@MichaReiser MichaReiser deleted the micha/knot-toml branch January 17, 2025 09:02
dcreager added a commit that referenced this pull request Jan 17, 2025
* main:
  [red-knot] Inline `SubclassOfType::as_instance_type_of_metaclass()` (#15556)
  [`flake8-comprehensions`] strip parentheses around generators in `unnecessary-generator-set` (`C401`) (#15553)
  [`pylint`] Implement `redefined-slots-in-subclass` (`W0244`) (#9640)
  [`flake8-bugbear`] Do not raise error if keyword argument is present and target-python version is less or equals than 3.9 (`B903`) (#15549)
  [red-knot] `type[T]` is disjoint from `type[S]` if the metaclass of `T` is disjoint from the metaclass of `S` (#15547)
  [red-knot] Pure instance variables declared in class body (#15515)
  Update snapshots of #15507 with new annotated snipetts rendering (#15546)
  [`pylint`] Do not report methods with only one `EM101`-compatible `raise` (`PLR6301`) (#15507)
  Fix unstable f-string formatting for expressions containing a trailing comma (#15545)
  Support `knot.toml` files in project discovery (#15505)
  Add support for configuring knot in `pyproject.toml` files (#15493)
  Fix bracket spacing for single-element tuples in f-string expressions (#15537)
  [`flake8-simplify`] Do not emit diagnostics for expressions inside string type annotations (`SIM222`, `SIM223`) (#15405)
  [`flake8-pytest-style`] Do not emit diagnostics for empty `for` loops (`PT012`, `PT031`) (#15542)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants