|
1 | 1 | 'use strict'; |
2 | 2 | // tslint:disable: no-any one-line no-suspicious-comment prefer-template prefer-const no-unnecessary-callback-wrapper no-function-expression no-string-literal no-control-regex no-shadowed-variable |
3 | | -// TODO: Cleanup this place |
4 | | -// Add options for execPythonFile |
5 | 3 |
|
6 | 4 | import * as child_process from 'child_process'; |
7 | 5 | import * as fs from 'fs'; |
8 | | -import * as fsExtra from 'fs-extra'; |
9 | 6 | import * as os from 'os'; |
10 | 7 | import * as path from 'path'; |
11 | | -import { Position, Range, TextDocument, Uri } from 'vscode'; |
12 | | -import * as settings from './configSettings'; |
13 | | -import { parseEnvFile } from './envFileParser'; |
| 8 | +import { Position, Range, TextDocument } from 'vscode'; |
14 | 9 |
|
15 | 10 | export const IS_WINDOWS = /^win/.test(process.platform); |
16 | 11 | export const Is_64Bit = os.arch() === 'x64'; |
17 | 12 | export const PATH_VARIABLE_NAME = IS_WINDOWS ? 'Path' : 'PATH'; |
18 | 13 |
|
19 | | -const PathValidity: Map<string, boolean> = new Map<string, boolean>(); |
20 | | -export function validatePath(filePath: string): Promise<string> { |
21 | | - if (filePath.length === 0) { |
22 | | - return Promise.resolve(''); |
23 | | - } |
24 | | - if (PathValidity.has(filePath)) { |
25 | | - return Promise.resolve(PathValidity.get(filePath) ? filePath : ''); |
26 | | - } |
27 | | - return new Promise<string>(resolve => { |
28 | | - fs.exists(filePath, exists => { |
29 | | - PathValidity.set(filePath, exists); |
30 | | - return resolve(exists ? filePath : ''); |
31 | | - }); |
32 | | - }); |
33 | | -} |
34 | 14 | export function fsExistsAsync(filePath: string): Promise<boolean> { |
35 | 15 | return new Promise<boolean>(resolve => { |
36 | 16 | fs.exists(filePath, exists => { |
37 | | - PathValidity.set(filePath, exists); |
38 | 17 | return resolve(exists); |
39 | 18 | }); |
40 | 19 | }); |
@@ -110,45 +89,6 @@ export function getSubDirectories(rootDir: string): Promise<string[]> { |
110 | 89 | }); |
111 | 90 | } |
112 | 91 |
|
113 | | -export async function getCustomEnvVars(resource?: Uri): Promise<{} | undefined | null> { |
114 | | - const envFile = settings.PythonSettings.getInstance(resource).envFile; |
115 | | - if (typeof envFile !== 'string' || envFile.length === 0) { |
116 | | - return null; |
117 | | - } |
118 | | - const exists = await fsExtra.pathExists(envFile); |
119 | | - if (!exists) { |
120 | | - return null; |
121 | | - } |
122 | | - try { |
123 | | - const vars = parseEnvFile(envFile); |
124 | | - if (vars && typeof vars === 'object' && Object.keys(vars).length > 0) { |
125 | | - return vars; |
126 | | - } |
127 | | - } catch (ex) { |
128 | | - console.error('Failed to parse env file', ex); |
129 | | - } |
130 | | - return null; |
131 | | -} |
132 | | -export function getCustomEnvVarsSync(resource?: Uri): {} | undefined | null { |
133 | | - const envFile = settings.PythonSettings.getInstance(resource).envFile; |
134 | | - if (typeof envFile !== 'string' || envFile.length === 0) { |
135 | | - return null; |
136 | | - } |
137 | | - const exists = fsExtra.pathExistsSync(envFile); |
138 | | - if (!exists) { |
139 | | - return null; |
140 | | - } |
141 | | - try { |
142 | | - const vars = parseEnvFile(envFile); |
143 | | - if (vars && typeof vars === 'object' && Object.keys(vars).length > 0) { |
144 | | - return vars; |
145 | | - } |
146 | | - } catch (ex) { |
147 | | - console.error('Failed to parse env file', ex); |
148 | | - } |
149 | | - return null; |
150 | | -} |
151 | | - |
152 | 92 | export function getWindowsLineEndingCount(document: TextDocument, offset: Number) { |
153 | 93 | const eolPattern = new RegExp('\r\n', 'g'); |
154 | 94 | const readBlock = 1024; |
|
0 commit comments