Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bugs of windows os for python and npm ecosystems #146

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/providers/javascript_npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ export var npmInteractions = {
})
},
createPackageLock: function createPackageLock(npm, manifestDir) {
// in windows os, --prefix flag doesn't work, it behaves really weird , instead of installing the package.json fromm the prefix folder,
// it's installing package.json (placed in current working directory of process) into prefix directory, so
let originalDir = process.cwd()
if(os.platform() === 'win32') {
process.chdir(manifestDir)
}
execSync(`${handleSpacesInPath(npm)} i --package-lock-only --prefix ${handleSpacesInPath(manifestDir)}`, err => {
if (err) {
throw new Error('failed to create npmOutput list')
}
})
if(os.platform() === 'win32') {
process.chdir(originalDir)
}
}
}
export default { isSupported, provideComponent, provideStack, npmInteractions }
Expand Down
30 changes: 24 additions & 6 deletions src/providers/python_controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {execSync} from "node:child_process";
import fs from "node:fs";
import path from 'node:path';
import {EOL} from "os";
import os, {EOL} from "os";
import {environmentVariableIsPopulated,getCustom, handleSpacesInPath} from "../tools.js";


Expand Down Expand Up @@ -55,19 +55,29 @@ export default class Python_controller {
{
if(!this.realEnvironment) {
this.pythonEnvDir = path.join(path.sep,"tmp","exhort_env_js")
execSync(`${handleSpacesInPath(this.pathToPythonBin)} -m venv ${this.pythonEnvDir} `, err => {
execSync(`${handleSpacesInPath(this.pathToPythonBin)} -m venv ${handleSpacesInPath(this.pythonEnvDir)} `, err => {
if (err) {
throw new Error('failed creating virtual python environment - ' + err.message)
}
})
if(this.pathToPythonBin.includes("python3"))
{
this.pathToPipBin = path.join(this.pythonEnvDir,"bin","pip3");
this.pathToPythonBin = path.join(this.pythonEnvDir,"bin","python3")
this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("pip3"))
this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("python3"))
if(os.platform() === 'win32') {
let driveLetter = path.parse(process.cwd()).root
this.pathToPythonBin = `${driveLetter}${this.pathToPythonBin.substring(1)}`
this.pathToPipBin = `${driveLetter}${this.pathToPipBin.substring(1)}`
}
}
else {
this.pathToPipBin = path.join(this.pythonEnvDir,"bin","pip");
this.pathToPythonBin = path.join(this.pythonEnvDir,"bin","python")
this.pathToPipBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("pip"));
this.pathToPythonBin = path.join(path.sep,this.pythonEnvDir,os.platform() === 'win32' ? "Scripts" : "bin",this.#decideIfWindowsOrLinuxPath("python"))
if(os.platform() === 'win32') {
let driveLetter = path.parse(process.cwd()).root
this.pathToPythonBin = `${driveLetter}${this.pathToPythonBin.substring(1)}`
this.pathToPipBin = `${driveLetter}${this.pathToPipBin.substring(1)}`
}
}
// upgrade pip version to latest
execSync(`${handleSpacesInPath(this.pathToPythonBin)} -m pip install --upgrade pip `, err => {
Expand All @@ -87,6 +97,14 @@ export default class Python_controller {
}
}

#decideIfWindowsOrLinuxPath(fileName) {
if (os.platform() === "win32") {
return fileName + ".exe"
}
else {
return fileName
}
}
/**
*
* @param {boolean} includeTransitive - whether to return include in returned object transitive dependencies or not
Expand Down
Loading