@@ -2,6 +2,7 @@ import { isTestExecution } from '../../../common/constants';
2
2
import { exec , pathExists } from '../externalDependencies' ;
3
3
import { traceVerbose } from '../../../logging' ;
4
4
import { cache } from '../../../common/utils/decorators' ;
5
+ import { getOSType , OSType } from '../../../common/utils/platform' ;
5
6
6
7
/** Wraps the "Hatch" utility, and exposes its functionality.
7
8
*/
@@ -22,7 +23,9 @@ export class Hatch {
22
23
* first argument of spawn() - i.e. it can be a full path, or just a binary name.
23
24
* @param cwd - The working directory to use as cwd when running hatch.
24
25
*/
25
- constructor ( public readonly command : string , private cwd : string ) { }
26
+ constructor ( public readonly command : string , private cwd : string ) {
27
+ this . fixCwd ( ) ;
28
+ }
26
29
27
30
/**
28
31
* Returns a Hatch instance corresponding to the binary which can be used to run commands for the cwd.
@@ -90,4 +93,24 @@ export class Hatch {
90
93
) ;
91
94
return envPaths . flatMap ( ( r ) => ( r ? [ r ] : [ ] ) ) ;
92
95
}
96
+
97
+ /**
98
+ * Due to an upstream hatch issue on Windows https://github.com/pypa/hatch/issues/1350,
99
+ * 'hatch env find default' does not handle case-insensitive paths as cwd, which are valid on Windows.
100
+ * So we need to pass the case-exact path as cwd.
101
+ * It has been observed that only the drive letter in `cwd` is lowercased here. Unfortunately,
102
+ * there's no good way to get case of the drive letter correctly without using Win32 APIs:
103
+ * https://stackoverflow.com/questions/33086985/how-to-obtain-case-exact-path-of-a-file-in-node-js-on-windows
104
+ * So we do it manually.
105
+ */
106
+ private fixCwd ( ) : void {
107
+ if ( getOSType ( ) === OSType . Windows ) {
108
+ if ( / ^ [ a - z ] : / . test ( this . cwd ) ) {
109
+ // Replace first character by the upper case version of the character.
110
+ const a = this . cwd . split ( ':' ) ;
111
+ a [ 0 ] = a [ 0 ] . toUpperCase ( ) ;
112
+ this . cwd = a . join ( ':' ) ;
113
+ }
114
+ }
115
+ }
93
116
}
0 commit comments