8000 Leverage ms-python.python extension to resolve python interpreter path automatically by hackenbergstefan · Pull Request #39 · afri-bit/vsconan · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Leverage ms-python.python extension to resolve python interpreter path automatically #39

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

Merged
merged 3 commits into from
Aug 2, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.2.0 - unreleased

### Added

* [#39](https://github.com/afri-bit/vsconan/pull/39) Support detection of python interpreter by ms-python.python extension

## 1.1.0 - 2024-07-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ The default configuration file can be seen as following. You can extend the list
* `VSConan: Open Workspace Configuration (JSON)`
Open the workspace configuration file in the editor

Further information of currrent supported features is available [here](doc/FEATURES.md).
Further information of current supported features is available [here](doc/FEATURES.md).

## Release Notes
Detailed release notes are available [here](CHANGELOG.md).
Expand Down
1 change: 1 addition & 0 deletions doc/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
* export-pkg
* Add editable package
* Remove editable package
* Automatic selection of Python interpreter using the ms-python.python extension

## General
* Define multiple conan profiles inside `settings.json` that you can use for the extension.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@
"ts-jest": "29.1.2"
},
"dependencies": {
"@vscode/python-extension": "^1.0.5",
"child_process": "^1.0.2"
}
}
}
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function activate(context: vscode.ExtensionContext) {
initContextState(context);

// Create Configuration Manager object to store and get some configuration
let settingsPropertyManager = new SettingsPropertyManager(context);
let settingsPropertyManager = new SettingsPropertyManager(context, channelVSConan);

let conanApiManager: ConanAPIManager = new ConanAPIManager();

Expand Down
185 changes: 92 additions & 93 deletions src/extension/manager/vsconanWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ export class VSConanWorkspaceManager extends ExtensionManager {

private updateStatusBar() {
let selectedProfile: string | undefined = this.settingsPropertyManager.getSelectedConanProfile();
let selectedProfileObject: ConanProfileConfiguration | undefined = this.settingsPropertyManager.getConanProfileObject(selectedProfile!);

if (selectedProfileObject && selectedProfileObject.isValid()) {
this.statusBarConanVersion.text = `$(extensions) VSConan | conan${selectedProfileObject.conanVersion} - ${selectedProfile}`;
this.statusBarConanVersion.color = "";
}
else {
this.statusBarConanVersion.text = `$(extensions) VSConan | -`;
this.statusBarConanVersion.color = "#FF3333";
}
this.settingsPropertyManager.getConanProfileObject(selectedProfile!).then(selectedProfileObject => {
if (selectedProfileObject && selectedProfileObject.isValid()) {
this.statusBarConanVersion.text = `$(extensions) VSConan | conan${selectedProfileObject.conanVersion} - ${selectedProfile}`;
this.statusBarConanVersion.color = "";
this.statusBarConanVersion.tooltip = new vscode.MarkdownString(`### Python Interpreter\n\`${selectedProfileObject.conanPythonInterpreter}\`\n### Conan Executable\n\`${selectedProfileObject.conanExecutable}\``);
}
else {
this.statusBarConanVersion.text = `$(extensions) VSConan | -`;
this.statusBarConanVersion.color = "#FF3333";
}
});
}

/**
Expand All @@ -108,30 +109,31 @@ export class VSConanWorkspaceManager extends ExtensionManager {

let profileList: Array<string> = this.settingsPropertyManager.getListOfConanProfiles();

let quickPickItems = [];
(async () => {
let quickPickItems = [];
for (let i = 0; i < profileList.length; i++) {
let profileObject: ConanProfileConfiguration | undefined = await this.settingsPropertyManager.getConanProfileObject(profileList[i]);

for (let i = 0; i < profileList.length; i++) {
quickPickItems.push({
label: profileList[i],
description: `Conan Version ${profileObject?.conanVersion}`,
detail: profileObject?.conanExecutionMode,
index: i,
conanVersion: profileObject?.conanVersion,
});
}
return quickPickItems;
})().then(quickPickItems => {
quickPickItems.map(label => ({ label }));
quickPick.items = quickPickItems;

let profileObject: ConanProfileConfiguration | undefined = this.settingsPropertyManager.getConanProfileObject(profileList[i]);
const wsChoice = vscode.window.showQuickPick(quickPickItems);

quickPickItems.push({
label: profileList[i],
description: `Conan Version ${profileObject?.conanVersion}`,
detail: profileObject?.conanExecutionMode,
index: i,
conanVersion: profileObject?.conanVersion,
wsChoice.then(result => {
if (result) {
this.settingsPropertyManager.updateConanProfile(result?.label);
}
});
}

quickPickItems.map(label => ({ label }));
quickPick.items = quickPickItems;

const wsChoice = vscode.window.showQuickPick(quickPickItems);

wsChoice.then(result => {
if (result) {
this.settingsPropertyManager.updateConanProfile(result?.label);
}
});
}

Expand Down Expand Up @@ -182,94 +184,91 @@ export class VSConanWorkspaceManager extends ExtensionManager {
* Function to execute the selected Conan command
* Since the flow of conan commands is similar, the flow of execution will be grouped within this function
* Which command needs to be executed is determined using ENUM ConanCommand
*
*
* @param cmdType Enumeration type to determine which command to be executed
*/
private executeConanCommand(cmdType: ConanCommand): void {
private async executeConanCommand(cmdType: ConanCommand) {
// The flow of following commands is the same by selecting the workspace first
// Check the configuration and executed pre selected command based on this function argument
let ws = utils.workspace.selectWorkspace();

ws.then(wsPath => {
let wsPath = await utils.workspace.selectWorkspace();

let configPath = path.join(wsPath!, constants.VSCONAN_FOLDER, constants.CONFIG_FILE);
let configPath = path.join(wsPath!, constants.VSCONAN_FOLDER, constants.CONFIG_FILE);

if (fs.existsSync(configPath)) {
let configWorkspace = new ConfigWorkspace();
let configText = fs.readFileSync(configPath, 'utf8');
configWorkspace = JSON.parse(configText);
if (fs.existsSync(configPath)) {
let configWorkspace = new ConfigWorkspace();
let configText = fs.readFileSync(configPath, 'utf8');
configWorkspace = JSON.parse(configText);

let conanCommand = "";
let commandBuilder: CommandBuilder | undefined;
let conanVersion: string | null = "";
let conanCommand = "";
let commandBuilder: CommandBuilder | undefined;
let conanVersion: string | null = "";

// Get current profile
let currentConanProfile = this.settingsPropertyManager.getSelectedConanProfile();
// Get current profile
let currentConanProfile = this.settingsPropertyManager.getSelectedConanProfile();

if (currentConanProfile && this.settingsPropertyManager.isProfileValid(currentConanProfile!)) {
conanVersion = this.settingsPropertyManager.getConanVersionOfProfile(currentConanProfile!);
commandBuilder = CommandBuilderFactory.getCommandBuilder(conanVersion!);
if (currentConanProfile && await this.settingsPropertyManager.isProfileValid(currentConanProfile!)) {
conanVersion = await this.settingsPropertyManager.getConanVersionOfProfile(currentConanProfile!);
commandBuilder = CommandBuilderFactory.getCommandBuilder(conanVersion!);

let conanProfileObject: ConanProfileConfiguration | undefined = this.settingsPropertyManager.getConanProfileObject(currentConanProfile!);
let conanProfileObject: ConanProfileConfiguration | undefined = await this.settingsPropertyManager.getConanProfileObject(currentConanProfile!);

if (conanProfileObject?.conanExecutionMode === "pythonInterpreter" && conanProfileObject.conanPythonInterpreter) {
conanCommand = `${conanProfileObject.conanPythonInterpreter} -m conans.conan`;
}
else if (conanProfileObject?.conanExecutionMode === "conanExecutable" && conanProfileObject.conanExecutable) {
conanCommand = conanProfileObject.conanExecutable;
}
else {
vscode.window.showErrorMessage("Empty Conan Command");
return;
}
if (conanProfileObject?.conanExecutionMode === "pythonInterpreter" && conanProfileObject.conanPythonInterpreter) {
conanCommand = `${conanProfileObject.conanPythonInterpreter} -m conans.conan`;
}
else if (conanProfileObject?.conanExecutionMode === "conanExecutable" && conanProfileObject.conanExecutable) {
conanCommand = `${conanProfileObject.conanExecutable}`;
}
else {
vscode.window.showErrorMessage("");
vscode.window.showErrorMessage("Empty Conan Command");
return;
}
}
else {
vscode.window.showErrorMessage("");
return;
}

switch (+cmdType) {
case ConanCommand.create: {
this.executeCommandConanCreate(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.create);
break;
}
case ConanCommand.install: {
this.executeCommandConanInstall(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.install);
break;
}
case ConanCommand.build: {
this.executeCommandConanBuild(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.build);
break;
}
case ConanCommand.source: {
this.executeCommandConanSource(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.source);
switch (+cmdType) {
case ConanCommand.create: {
this.executeCommandConanCreate(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.create);
break;
}
case ConanCommand.install: {
this.executeCommandConanInstall(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.install);
break;
}
case ConanCommand.build: {
this.executeCommandConanBuild(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.build);
break;
}
case ConanCommand.source: {
this.executeCommandConanSource(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.source);
break;
}
case ConanCommand.package: {
if (conanVersion === "2") {
vscode.window.showErrorMessage("This command doesn't work on Conan 2");
break;
}
case ConanCommand.package: {
if (conanVersion === "2") {
vscode.window.showErrorMessage("This command doesn't work on Conan 2");
break;
}

this.executeCommandConanPackage(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.pkg);
break;
}
case ConanCommand.packageExport: {
this.executeCommandConanPackageExport(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.pkgExport);
break;
}
this.executeCommandConanPackage(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.pkg);
break;
}
case ConanCommand.packageExport: {
this.executeCommandConanPackageExport(wsPath!, conanCommand, commandBuilder!, configWorkspace.commandContainer.pkgExport);
break;
}
}
else {
vscode.window.showWarningMessage(`Unable to find configuration file in the workspace '${wsPath}'`);
}
});
}
else {
vscode.window.showWarningMessage(`Unable to find configuration file in the workspace '${wsPath}'`);
}
}

/**
* Helper method to get the index of selected command.
* This method basically will pop up quick pick window to select configuration where the user has to choose.
* @param configList List of configuration
* @param configList List of configuration
* @returns Index of selected configuration | undefined on error or no selection
*/
private getCommandConfigIndex(configList: Array<ConfigCommand>): Promise<number | undefined> {
Expand Down Expand Up @@ -612,4 +611,4 @@ export class VSConanWorkspaceManager extends ExtensionManager {
vscode.window.showErrorMessage((err as Error).message);
}
}
}
}
8 changes: 4 additions & 4 deletions src/extension/settings/settingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export class SettingsManager {
}
}

private changeConanProfile() {
private async changeConanProfile() {
let selectedProfile: string | undefined = vscode.workspace.getConfiguration("vsconan.conan.profile").get("default");

if (this.settingsPropertyManager.isProfileAvailable(selectedProfile!) &&
this.settingsPropertyManager.isProfileValid(selectedProfile!)) {
let profileObject = this.settingsPropertyManager.getConanProfileObject(selectedProfile!);
await this.settingsPropertyManager.isProfileValid(selectedProfile!)) {
let profileObject = await this.settingsPropertyManager.getConanProfileObject(selectedProfile!);

let conanExecutionMode: ConanExecutionMode = ConanExecutionMode.conan;

Expand Down Expand Up @@ -106,4 +106,4 @@ export class SettingsManager {
this.conanWorkspaceManager.refresh();
}
}
}
}
Loading
0