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

IEP-1074: Python dropdown removed #856

Merged
merged 3 commits into from
Dec 6, 2023
Merged

IEP-1074: Python dropdown removed #856

merged 3 commits into from
Dec 6, 2023

Conversation

alirana01
Copy link
Collaborator

@alirana01 alirana01 commented Nov 20, 2023

Description

Python dropdown was causing some confusions to the users so it is now removed on Windows and a simple text box that points to the executable path of the python is kept

Fixes # (IEP-1074)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

Tested on windows with install tools.

Test Configuration:

  • ESP-IDF Version: any
  • OS (Windows,Linux and macOS): Test on windows and also verify on Linux and Mac for normal workiing

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Verified on all platforms - Windows,Linux and macOS

Summary by CodeRabbit

  • New Features

    • Introduced a new field for specifying the Python executable location in the Directory Selection Dialog.
    • Implemented validation for the Python executable path.
  • Refactor

    • Removed outdated Python version selection functionality.
  • Documentation

    • Added user-facing messages for invalid Python path validation.

Copy link

coderabbitai bot commented Nov 20, 2023

Walkthrough

The changes reflect a shift in the user interface of the DirectorySelectionDialog, specifically in how users specify the Python executable. The pythonVersionCombo dropdown has been removed, and in its place, a pythonLocationtext field has been introduced for users to enter or select the Python executable path. This update necessitates modifications to the validation and OK button press methods to accommodate the new field. Additionally, new messages have been added to handle invalid Python path scenarios.

Changes

File Path Change Summary
.../idf/ui/update/DirectorySelectionDialog.java Removed references to org.eclipse.core.runtime.Platform and org.eclipse.swt.widgets.Combo. Replaced pythonVersionCombo with pythonLocationtext and updated validate and okPressed methods. Added validatePythonExecutable method.
.../idf/ui/update/Messages.java Introduced new string constant DirectorySelectionDialog_InvalidPythonPath.
.../idf/ui/update/messages.properties Added new message string "DirectorySelectionDialog_InvalidPythonPath" and its translation.

🐇✨
In the code where paths intertwine,
A rabbit hopped, leaving old ways behind.
"No more combos, just text," it decreed,
"For Python's path is all you need!" 🌟🐾


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Collaborator Author

@alirana01 alirana01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self Review

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7ed1e5f and 39c2967.
Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/DirectorySelectionDialog.java (6 hunks)
Additional comments: 7
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/DirectorySelectionDialog.java (7)
  • 6-11: The removal of the org.eclipse.core.runtime.Platform import suggests that platform-specific code or checks might have been removed. Verify that this does not affect other parts of the application that may rely on platform checks.

  • 18-23: The removal of the org.eclipse.swt.widgets.Combo import indicates that the dropdown UI component has been removed. Ensure that no other parts of the application are using this import for different purposes.

  • 39-60: The constructor no longer receives a pythonVersions map, which suggests that the dropdown for selecting Python versions has been removed. Ensure that this change is reflected everywhere in the codebase and that no functionality is broken due to the removal of the Python version selection feature.

  • 149-195: The new implementation for selecting the Python executable path is introduced here. It is important to ensure that the FileDialog is correctly configured to filter for executable files, especially on Windows where the Python executable has a .exe extension. Additionally, verify that the pythonLocationtext field is properly validated to ensure that the path provided is indeed an executable and not a directory or a non-executable file.

  • 196-203: The validate method has been updated to check the new pythonLocationtext field. It is crucial to ensure that the validation logic is robust and correctly identifies valid and invalid paths. Consider edge cases such as symbolic links, environment variables, or relative paths.

  • 231-242: The getPythonPreferenceOrDefault method has been updated to fetch the Python executable path preference. Ensure that this method correctly handles default values and that the preference is stored and retrieved consistently across different platforms.

  • 256-263: The okPressed method now saves the paths for the IDF directory, Python executable, and Git executable. It is important to ensure that these paths are correctly saved to preferences and that there are no issues with path separators or special characters on different operating systems.

Copy link
Collaborator

@kolipakakondal kolipakakondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM

@kolipakakondal
Copy link
Collaborator

Hi @AndriiFilippov Please verify

Copy link
Collaborator

@sigmaaa sigmaaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AndriiFilippov
Copy link
Collaborator

@alirana01 hi !

Should be some validation here?

image

@alirana01
Copy link
Collaborator Author

@alirana01 hi !

Should be some validation here?

image

Yes will add this

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 39c2967 and 47de176.
Files selected for processing (3)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/DirectorySelectionDialog.java (7 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/Messages.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/messages.properties (1 hunks)
Files skipped from review due to trivial changes (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/Messages.java
Additional comments: 5
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/DirectorySelectionDialog.java (3)
  • 238-249: The getPythonPreferenceOrDefault method is a good addition for fetching the Python path preference. However, it's important to ensure that the default value provided is a sensible one, as the method will return this value if the preference is not set. If the default value is not a valid path, it could lead to issues when the path is used later on.

  • 263-270: The okPressed method now captures the text from pythonLocationtext and gitLocationtext before calling super.okPressed(). This is a good practice to ensure that the values are stored before the dialog is closed. However, it's important to ensure that the values are validated before proceeding, as the okPressed method is the final step before the dialog is dismissed.

  • 290-292: The getPreferences method is used to fetch the preferences node. It's important to ensure that the node "preference" exists and is the correct place to store these preferences. If the node does not exist or is incorrect, it could lead to preferences not being saved or retrieved correctly.

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/messages.properties (2)
  • 9-9: The addition of the message string "DirectorySelectionDialog_InvalidPythonPath" aligns with the changes made in the pull request to handle Python path validation.

  • 11-11: The message key "DirectorySelectionDialog_ChoosePyVersion" might be obsolete due to the removal of the Python version dropdown. Verify if this key is still in use elsewhere or if it should be removed.

Comment on lines 196 to 213
protected void validate()
{
idfDirPath = text.getText();
if (pythonVersionCombo != null)
{
String version = pythonVersionCombo.getText();
pythonExecutablePath = pythonVersions.getOrDefault(version, null);
}
else
pythonExecutablePath = pythonLocationtext.getText();

gitPath = gitLocationtext.getText();

boolean isValidPythonPath = validatePythonExecutable(pythonExecutablePath);

if (!isValidPythonPath)
{
pythonExecutablePath = pythonLocationtext.getText();
setErrorMessage(Messages.DirectorySelectionDialog_InvalidPythonPath);
getButton(IDialogConstants.OK_ID).setEnabled(false);
}
gitPath = gitLocationtext.getText();

if (StringUtil.isEmpty(pythonExecutablePath) || StringUtil.isEmpty(gitPath) || StringUtil.isEmpty(idfDirPath))
else if (StringUtil.isEmpty(pythonExecutablePath) || StringUtil.isEmpty(gitPath) || StringUtil.isEmpty(idfDirPath))
{
setErrorMessage(Messages.DirectorySelectionDialog_CantbeEmpty);
getButton(IDialogConstants.OK_ID).setEnabled(false);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validate method has been updated to include validation for the new Python executable path. However, the validation logic only checks if the path is not empty and if it is a valid executable. It might be beneficial to also check if the path actually points to a Python executable, as the current validation could pass for any executable file.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 47de176 and 4f1f03d.
Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/DirectorySelectionDialog.java (7 hunks)
Additional comments: 5
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/DirectorySelectionDialog.java (5)
  • 7-8: The addition of BufferedReader and InputStreamReader imports is appropriate for the new functionality to validate the Python executable.

  • 11-11: The removal of the org.eclipse.core.runtime.Platform import seems justified as it is not used in the provided code.

  • 44-53: The changes in member variables from pythonVersionCombo to pythonLocationtext reflect the shift from a dropdown to a text input for the Python path, which is consistent with the PR description.

  • 198-215: The validate method has been updated to include a call to validatePythonExecutable, which is a good practice to encapsulate the validation logic. However, the previous comment about enhancing the validation logic to ensure the path points to a Python executable is still valid.

  • 265-272: The okPressed method correctly assigns the Python executable path from pythonLocationtext, aligning with the changes made to the dialog.

Comment on lines +296 to +310
private boolean validatePythonExecutable(String path)
{
try
{
Process process = new ProcessBuilder(path, "--version").start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String output = reader.readLine();
int exitCode = process.waitFor();
return exitCode == 0 && output.startsWith("Python");
}
catch (Exception e)
{
return false;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validatePythonExecutable method is a good addition for validating the Python executable path. It checks if the executable can run and if it outputs a string starting with "Python". However, it might be beneficial to handle the case where the process outputs the version information to the error stream instead of the input stream.

private boolean validatePythonExecutable(String path) {
    try {
        Process process = new ProcessBuilder(path, "--version").start();
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        String output = reader.readLine();
        String errorOutput = errorReader.readLine();
        int exitCode = process.waitFor();
        return exitCode == 0 && (output != null && output.startsWith("Python") || errorOutput != null && errorOutput.startsWith("Python"));
    } catch (Exception e) {
        return false;
    }
}

@kolipakakondal kolipakakondal added this to the v2.12.0 milestone Nov 27, 2023
@AndriiFilippov
Copy link
Collaborator

@alirana01 hi !

Tested under:
OS - Windows 10
ESP-IDF: v5.1.2
Python: 3.7 / 3.8 / 3.11

able to install tools with different Python versions, build + flash + monitor 👍
LGTM 👍

@kolipakakondal kolipakakondal merged commit cce5b99 into master Dec 6, 2023
3 of 6 checks passed
@kolipakakondal kolipakakondal deleted the IEP-1074 branch December 6, 2023 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants