mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-04 23:50:57 +00:00
Rename custom-typeshed-dir
, target-version
and current-directory
CLI options (#14930)
## Summary This PR renames the `--custom-typeshed-dir`, `target-version`, and `--current-directory` cli options to `--typeshed`, `--python-version`, and `--project` as discussed in the CLI proposal document. I added aliases for `--target-version` (for Ruff compat) and `--custom-typeshed-dir` (for Alex) ## Test Plan Long help ``` An extremely fast Python type checker. Usage: red_knot [OPTIONS] [COMMAND] Commands: server Start the language server help Print this message or the help of the given subcommand(s) Options: --project <PROJECT> Run the command within the given project directory. All `pyproject.toml` files will be discovered by walking up the directory tree from the project root, as will the project's virtual environment (`.venv`). Other command-line arguments (such as relative paths) will be resolved relative to the current working directory."#, --venv-path <PATH> Path to the virtual environment the project uses. If provided, red-knot will use the `site-packages` directory of this virtual environment to resolve type information for the project's third-party dependencies. --typeshed-path <PATH> Custom directory to use for stdlib typeshed stubs --extra-search-path <PATH> Additional path to use as a module-resolution source (can be passed multiple times) --python-version <VERSION> Python version to assume when resolving types [possible values: 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13] -v, --verbose... Use verbose output (or `-vv` and `-vvv` for more verbose output) -W, --watch Run in watch mode by re-running whenever files change -h, --help Print help (see a summary with '-h') -V, --version Print version ``` Short help ``` An extremely fast Python type checker. Usage: red_knot [OPTIONS] [COMMAND] Commands: server Start the language server help Print this message or the help of the given subcommand(s) Options: --project <PROJECT> Run the command within the given project directory --venv-path <PATH> Path to the virtual environment the project uses --typeshed-path <PATH> Custom directory to use for stdlib typeshed stubs --extra-search-path <PATH> Additional path to use as a module-resolution source (can be passed multiple times) --python-version <VERSION> Python version to assume when resolving types [possible values: 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13] -v, --verbose... Use verbose output (or `-vv` and `-vvv` for more verbose output) -W, --watch Run in watch mode by re-running whenever files change -h, --help Print help (see more with '--help') -V, --version Print version ``` --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
d7ce548893
commit
c1837e4189
33 changed files with 280 additions and 297 deletions
68
crates/red_knot/src/python_version.rs
Normal file
68
crates/red_knot/src/python_version.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
/// Enumeration of all supported Python versions
|
||||
///
|
||||
/// TODO: unify with the `PythonVersion` enum in the linter/formatter crates?
|
||||
#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, PartialOrd, Ord, Default, clap::ValueEnum)]
|
||||
pub enum PythonVersion {
|
||||
#[value(name = "3.7")]
|
||||
Py37,
|
||||
#[value(name = "3.8")]
|
||||
Py38,
|
||||
#[default]
|
||||
#[value(name = "3.9")]
|
||||
Py39,
|
||||
#[value(name = "3.10")]
|
||||
Py310,
|
||||
#[value(name = "3.11")]
|
||||
Py311,
|
||||
#[value(name = "3.12")]
|
||||
Py312,
|
||||
#[value(name = "3.13")]
|
||||
Py313,
|
||||
}
|
||||
|
||||
impl PythonVersion {
|
||||
const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Py37 => "3.7",
|
||||
Self::Py38 => "3.8",
|
||||
Self::Py39 => "3.9",
|
||||
Self::Py310 => "3.10",
|
||||
Self::Py311 => "3.11",
|
||||
Self::Py312 => "3.12",
|
||||
Self::Py313 => "3.13",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PythonVersion {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PythonVersion> for red_knot_python_semantic::PythonVersion {
|
||||
fn from(value: PythonVersion) -> Self {
|
||||
match value {
|
||||
PythonVersion::Py37 => Self::PY37,
|
||||
PythonVersion::Py38 => Self::PY38,
|
||||
PythonVersion::Py39 => Self::PY39,
|
||||
PythonVersion::Py310 => Self::PY310,
|
||||
PythonVersion::Py311 => Self::PY311,
|
||||
PythonVersion::Py312 => Self::PY312,
|
||||
PythonVersion::Py313 => Self::PY313,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::python_version::PythonVersion;
|
||||
|
||||
#[test]
|
||||
fn same_default_as_python_version() {
|
||||
assert_eq!(
|
||||
red_knot_python_semantic::PythonVersion::from(PythonVersion::default()),
|
||||
red_knot_python_semantic::PythonVersion::default()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue