File tree 3 files changed +58
-4
lines changed 3 files changed +58
-4
lines changed Original file line number Diff line number Diff line change @@ -308,6 +308,61 @@ fn config_file_annotation_showing_where_python_version_set_typing_error() -> any
308
308
Ok ( ( ) )
309
309
}
310
310
311
+ #[ test]
312
+ fn pyvenv_cfg_file_annotation_showing_where_python_version_set ( ) -> anyhow:: Result < ( ) > {
313
+ let case = TestCase :: with_files ( [
314
+ (
315
+ "pyproject.toml" ,
316
+ r#"
317
+ [tool.ty.environment]
318
+ python = ".venv"
319
+ "# ,
320
+ ) ,
321
+ (
322
+ ".venv/pyvenv.cfg" ,
323
+ r#"
324
+ home = /usr
325
+ version = 3.8
326
+ "# ,
327
+ ) ,
328
+ if cfg ! ( target_os = "windows" ) {
329
+ ( ".venv/Lib/site-packages/foo.py" , "" )
330
+ } else {
331
+ ( ".venv/lib/python3.8/site-packages/foo.py" , "" )
332
+ } ,
333
+ ( "test.py" , "aiter" ) ,
334
+ ] ) ?;
335
+
336
+ assert_cmd_snapshot ! ( case. command( ) , @r"
337
+ success: false
338
+ exit_code: 1
339
+ ----- stdout -----
340
+ error[unresolved-reference]: Name `aiter` used when not defined
341
+ --> test.py:1:1
342
+ |
343
+ 1 | aiter
344
+ | ^^^^^
345
+ |
346
+ info: `aiter` was added as a builtin in Python 3.10
347
+ info: Python 3.8 was assumed when resolving types because of your virtual environment
348
+ --> .venv/pyvenv.cfg:3:11
349
+ |
350
+ 2 | home = /usr
351
+ 3 | version = 3.8
352
+ | ^^^ Python version inferred from virtual environment metadata file
353
+ |
354
+ info: No Python version was specified on the command line or in a configuration file
355
+ info: rule `unresolved-reference` is enabled by default
356
+
357
+ Found 1 diagnostic
358
+
359
+ ----- stderr -----
360
+ WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
361
+ " ) ;
362
+
363
+ Ok ( ( ) )
364
+ }
365
+
311
366
#[ test]
312
367
fn config_file_annotation_showing_where_python_version_set_syntax_error ( ) -> anyhow:: Result < ( ) > {
313
368
let case = TestCase :: with_files ( [
Original file line number Diff line number Diff line change @@ -251,8 +251,7 @@ impl SearchPaths {
251
251
// than the one resolved in the program settings because it indicates
252
252
// that the `target-version` is incorrectly configured or that the
253
253
// venv is out of date.
254
- PythonEnvironment :: new ( sys_prefix. clone ( ) , * origin, system) ?
255
- . into_settings ( system) ?
254
+ PythonEnvironment :: new ( sys_prefix, * origin, system) ?. into_settings ( system) ?
256
255
}
257
256
258
257
PythonPath :: Resolve ( target, origin) => {
Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ impl PythonEnvironment {
133
133
system : & dyn System ,
134
134
) -> SitePackagesDiscoveryResult < SitePackagesPaths > {
135
135
match self {
136
- Self :: Virtual ( venv ) => venv . site_packages_directories ( system) ,
136
+ Self :: Virtual ( env ) => env . site_packages_directories ( system) ,
137
137
Self :: System ( env) => env. site_packages_directories ( system) ,
138
138
}
139
139
}
@@ -290,7 +290,7 @@ impl VirtualEnvironment {
290
290
}
291
291
292
292
while !cursor. is_eof ( ) {
293
- if cursor. eat_char ( '\n' ) || cursor . eat_char2 ( '\r' , '\n' ) {
293
+ if cursor. eat_char ( '\n' ) {
294
294
break ;
295
295
}
296
296
cursor. bump ( ) ;
You can’t perform that action at this time.
0 commit comments