@@ -5,6 +5,7 @@ use anyhow::{anyhow, Context};
5
5
use clap:: Parser ;
6
6
use colored:: Colorize ;
7
7
use crossbeam:: channel as crossbeam_channel;
8
+ use python_version:: PythonVersion ;
8
9
use red_knot_python_semantic:: SitePackages ;
9
10
use red_knot_server:: run_server;
10
11
use red_knot_workspace:: db:: RootDatabase ;
@@ -15,12 +16,11 @@ use red_knot_workspace::workspace::WorkspaceMetadata;
15
16
use ruff_db:: diagnostic:: Diagnostic ;
16
17
use ruff_db:: system:: { OsSystem , System , SystemPath , SystemPathBuf } ;
17
18
use salsa:: plumbing:: ZalsaDatabase ;
18
- use target_version:: TargetVersion ;
19
19
20
20
use crate :: logging:: { setup_tracing, Verbosity } ;
21
21
22
22
mod logging;
23
- mod target_version ;
23
+ mod python_version ;
24
24
mod verbosity;
25
25
26
26
#[ derive( Debug , Parser ) ]
@@ -34,63 +34,48 @@ struct Args {
34
34
#[ command( subcommand) ]
35
35
pub ( crate ) command : Option < Command > ,
36
36
37
- #[ arg(
38
- long,
39
- help = "Changes the current working directory." ,
40
- long_help = "Changes the current working directory before any specified operations. This affects the workspace and configuration discovery." ,
41
- value_name = "PATH"
42
- ) ]
43
- current_directory : Option < SystemPathBuf > ,
44
-
45
- #[ arg(
46
- long,
47
- help = "Path to the virtual environment the project uses" ,
48
- long_help = "\
49
- Path to the virtual environment the project uses. \
50
- If provided, red-knot will use the `site-packages` directory of this virtual environment \
51
- to resolve type information for the project's third-party dependencies.",
52
- value_name = "PATH"
53
- ) ]
37
+ /// Run the command within the given project directory.
38
+ ///
39
+ /// All `pyproject.toml` files will be discovered by walking up the directory tree from the given project directory,
40
+ /// as will the project's virtual environment (`.venv`) unless the `venv-path` option is set.
41
+ ///
42
+ /// Other command-line arguments (such as relative paths) will be resolved relative to the current working directory.
43
+ #[ arg( long, value_name = "PROJECT" ) ]
44
+ project : Option < SystemPathBuf > ,
45
+
46
+ /// Path to the virtual environment the project uses.
47
+ ///
48
+ /// If provided, red-knot will use the `site-packages` directory of this virtual environment
49
+ /// to resolve type information for the project's third-party dependencies.
50
+ #[ arg( long, value_name = "PATH" ) ]
54
51
venv_path : Option < SystemPathBuf > ,
55
52
56
- #[ arg(
57
- long,
58
- value_name = "DIRECTORY" ,
59
- help = "Custom directory to use for stdlib typeshed stubs"
60
- ) ]
61
- custom_typeshed_dir : Option < SystemPathBuf > ,
62
-
63
- #[ arg(
64
- long,
65
- value_name = "PATH" ,
66
- help = "Additional path to use as a module-resolution source (can be passed multiple times)"
67
- ) ]
53
+ /// Custom directory to use for stdlib typeshed stubs.
54
+ #[ arg( long, value_name = "PATH" , alias = "custom-typeshed-dir" ) ]
55
+ typeshed : Option < SystemPathBuf > ,
56
+
57
+ /// Additional path to use as a module-resolution source (can be passed multiple times).
58
+ #[ arg( long, value_name = "PATH" ) ]
68
59
extra_search_path : Option < Vec < SystemPathBuf > > ,
69
60
70
- #[ arg(
71
- long,
72
- help = "Python version to assume when resolving types" ,
73
- value_name = "VERSION"
74
- ) ]
75
- target_version : Option < TargetVersion > ,
61
+ /// Python version to assume when resolving types.
62
+ #[ arg( long, value_name = "VERSION" , alias = "target-version" ) ]
63
+ python_version : Option < PythonVersion > ,
76
64
77
65
#[ clap( flatten) ]
78
66
verbosity : Verbosity ,
79
67
80
- #[ arg(
81
- long,
82
- help = "Run in watch mode by re-running whenever files change" ,
83
- short = 'W'
84
- ) ]
68
+ /// Run in watch mode by re-running whenever files change.
69
+ #[ arg( long, short = 'W' ) ]
85
70
watch : bool ,
86
71
}
87
72
88
73
impl Args {
89
74
fn to_configuration ( & self , cli_cwd : & SystemPath ) -> Configuration {
90
75
let mut configuration = Configuration :: default ( ) ;
91
76
92
- if let Some ( target_version ) = self . target_version {
93
- configuration. target_version = Some ( target_version . into ( ) ) ;
77
+ if let Some ( python_version ) = self . python_version {
78
+ configuration. python_version = Some ( python_version . into ( ) ) ;
94
79
}
95
80
96
81
if let Some ( venv_path) = & self . venv_path {
@@ -99,9 +84,8 @@ impl Args {
99
84
} ) ;
100
85
}
101
86
102
- if let Some ( custom_typeshed_dir) = & self . custom_typeshed_dir {
103
- configuration. search_paths . custom_typeshed =
104
- Some ( SystemPath :: absolute ( custom_typeshed_dir, cli_cwd) ) ;
87
+ if let Some ( typeshed) = & self . typeshed {
88
+ configuration. search_paths . typeshed = Some ( SystemPath :: absolute ( typeshed, cli_cwd) ) ;
105
89
}
106
90
107
91
if let Some ( extra_search_paths) = & self . extra_search_path {
@@ -167,15 +151,13 @@ fn run() -> anyhow::Result<ExitStatus> {
167
151
} ;
168
152
169
153
let cwd = args
170
- . current_directory
154
+ . project
171
155
. as_ref ( )
172
156
. map ( |cwd| {
173
157
if cwd. as_std_path ( ) . is_dir ( ) {
174
158
Ok ( SystemPath :: absolute ( cwd, & cli_base_path) )
175
159
} else {
176
- Err ( anyhow ! (
177
- "Provided current-directory path `{cwd}` is not a directory"
178
- ) )
160
+ Err ( anyhow ! ( "Provided project path `{cwd}` is not a directory" ) )
179
161
}
180
162
} )
181
163
. transpose ( ) ?
0 commit comments