Skip to content

Commit 9b3431a

Browse files
committed
Push windows python env discovery fixes
1 parent 1dbe68f commit 9b3431a

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/renderer/components/App.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ const App = ({helmetUIVersion, versions, searchEMMEPython}) => {
133133
if (found) {
134134
if (confirm(`Python ${versions.emme_python} löytyi sijainnista:\n\n${pythonPath}\n\nHaluatko käyttää tätä sijaintia?`)) {
135135
globalSettingsStore.current.set('emme_python_path', pythonPath);
136+
globalSettingsStore.current.set('emme_python_envs', [pythonPath])
136137
}
137138
} else {
138139
alert(`Emme ${versions.emme_system} ja Python ${versions.emme_python} eivät löytyneet oletetusta sijainnista.\n\nMääritä Pythonin sijainti Asetukset-dialogissa.`);

src/renderer/components/Settings/Settings.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const Settings = ({
7272
const [found, pythonPaths] = listEMMEPythonPaths();
7373
if (found) {
7474
alert(`Python-ympäristöjä löytyi. Valitse listasta haluamasi EMME Python-ympäristö ja ota se käyttöön`);
75-
console.log(Array.isArray(pythonPaths));
75+
console.log(pythonPaths);
7676
setEMMEPythonEnvs(pythonPaths);
7777
} else {
7878
alert(`Python-asennukset ${versions.emme_major_versions.toString()} eivät löytyneet oletetusta sijainnista.\n\nLisää Python-asennus manuaalisesti.`);

src/renderer/search_emme_pythonpath.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,30 @@ const searchEMMEPython = () => {
4242
}
4343
};
4444

45-
const listEMMEPythonPaths = () => {
46-
// Set Windows' python exe path postfix (e.g. Python27\python.exe)
47-
const p = getVersion(versions.emme_python);
48-
const pythonPathPostfix = `Python${p.major}${p.minor}\\python.exe`;
49-
// Search from environment variable "EMMEPATH"
50-
const envEmmePath = process.env.EMMEPATH || '';
51-
const envEmmePythonPath = path.join(envEmmePath, pythonPathPostfix);
52-
if (envEmmePath && fs.existsSync(envEmmePythonPath)) {
45+
const checkEmmePythonEnv = () => {
46+
// Set Windows' python exe path postfix (e.g. Python27\python.exe)
47+
const p = getVersion(versions.emme_python);
48+
const pythonPathPostfix = `Python${p.major}${p.minor}\\python.exe`;
49+
// Search from environment variable "EMMEPATH"
50+
const envEmmePath = process.env.EMMEPATH || '';
51+
const envEmmePythonPath = path.join(envEmmePath, pythonPathPostfix);
52+
if (envEmmePath && fs.existsSync(envEmmePythonPath)) {
5353
return [true, envEmmePythonPath];
54-
}
54+
} else {
55+
return [false, null];
56+
}
57+
}
5558

56-
// Not found based on EMMEPATH, try guessing some common locations on Windows
59+
const listEMMEPythonPaths = () => {
5760
const pythonVersion = getVersion(versions.emme_python);
5861

5962
const commonEmmePaths = []
63+
const pythonInstallations = []
64+
65+
// Check if Windows python exe exists in environment variables
66+
const [hasPythonEnvInstallation, pythonEnvInstallation] = checkEmmePythonEnv();
67+
if(hasPythonEnvInstallation) { pythonInstallations.push(pythonEnvInstallation) };
68+
6069
versions.emme_major_versions.forEach(majorVersion => { commonEmmePaths.push(`INRO\\Emme\\Emme ${majorVersion}`) })
6170

6271
const drives = ['C:', 'D:', 'E:', 'F:', 'G:', 'H:', 'I:', 'J:', '/'];
@@ -75,7 +84,6 @@ const listEMMEPythonPaths = () => {
7584
// Combine each (d)rive to all (p)aths, and merge results via reduce
7685
return accumulator.concat(paths.map((p) => `${d}${p}`));
7786
}, []);
78-
const pythonInstallations = []
7987
allPathCombinations.forEach((pathCombination) => {
8088
const foundPythonEnv = hasPythonEnv(pathCombination);
8189
if (foundPythonEnv !== null) {
@@ -133,7 +141,6 @@ function hasPythonEnv(basePath) {
133141
}
134142
})
135143
}
136-
console.log(exePaths);
137144
return exePaths;
138145
}
139146

0 commit comments

Comments
 (0)