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-1226: added filter for python3 in dialog #947

Merged
merged 4 commits into from
May 16, 2024
Merged

Conversation

alirana01
Copy link
Collaborator

@alirana01 alirana01 commented May 13, 2024

Description

Python selection dialog was not showing python3 due to missing filter

Fixes # (IEP-1226)

Type of change

Please delete options that are not relevant.

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

How has this been tested?

Use esp-idf manager view to add esp-idf and see if in the dialog the python3 filter is visible now

Test Configuration:

  • ESP-IDF Version: any
  • OS (Windows,Linux and macOS): all

Checklist

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

Summary by CodeRabbit

  • New Features

    • Added support for parsing and handling Windows-specific file attributes, including reparse tags.
    • Enhanced file operations to determine file existence and directory status on Windows.
  • Improvements

    • Updated the isExecutable method to better handle file existence checks based on the platform.
    • Improved Python file selection in the BrowseButtonSelectionAdapter class for better cross-platform compatibility.

@alirana01 alirana01 self-assigned this May 13, 2024
Copy link

coderabbitai bot commented May 13, 2024

Walkthrough

The recent updates enhance the com.espressif.idf.core module by integrating Windows-specific file parsing and reparse tag functionalities. Dependencies on com.sun.jna and com.sun.jna.platform libraries have been added. New methods and classes have been introduced to handle reparse tags, file existence, and directory checks on Windows, improving the module's cross-platform capabilities.

Changes

File Path Change Summary
bundles/com.espressif.idf.core/META-INF/MANIFEST.MF Added com.sun.jna and com.sun.jna.platform to required bundles.
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/FileParseTag.java Introduced functionality for parsing Windows file attributes and reparse tags.
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java Added method isReparseTag(File file) to check for reparse tags on Windows.
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/WinNativeFileTagOperations.java Added methods for working with Windows reparse tags, checking file existence, and directories.
bundles/com.espressif.idf.core/src/com/espressif/idf/core/SystemExecutableFinder.java Updated isExecutable method to handle file existence checks based on the platform.
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java Updated BrowseButtonSelectionAdapter to support Python file selection on all platforms.

🐰
In the realm of code, where bytes do dance,
New methods arise, enhancing our stance.
Windows files now reveal their tags,
With JNA's help, no more lags.
Dependencies grow, functionality blooms,
In the world of bits, no more gloom.
🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 38f5e19 and 5aea173.
Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java (2 hunks)
Files not reviewed due to errors (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java (no review received)

@AndriiFilippov
Copy link
Collaborator

@alirana01 hi !

Tested under:
OS - Windows 10
ESP-IDF: v5.2.1

Is it possible to combine both filters into 1 filter without any manual manipulations ?
image

Because still, to display python3.exe I have to switch filter manually. The same works for PATH. I have to open "Browse" first -> then switch filter to python3.exe -> then close "Browse" -> and just then my path to python3 will be recognize by validator.

@alirana01
Copy link
Collaborator Author

@alirana01 hi !

Tested under: OS - Windows 10 ESP-IDF: v5.2.1

Is it possible to combine both filters into 1 filter without any manual manipulations ? ![image](https://private-user-

I have pushed the changes but beware that now all python*.exe will be shown as the FileDialog can only use simple wildcards and does not support full regex

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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 5aea173 and 63bf527.
Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java

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.

Actionable comments posted: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 63bf527 and a110b7e.
Files selected for processing (4)
  • bundles/com.espressif.idf.core/META-INF/MANIFEST.MF (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/FileParseTag.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java
Additional comments not posted (4)
bundles/com.espressif.idf.core/META-INF/MANIFEST.MF (1)

30-31: New dependencies added: com.sun.jna and com.sun.jna.platform.

Ensure these dependencies are necessary for the new functionality and are correctly added.

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/FileParseTag.java (3)

18-41: Ensure the WIN32_FIND_DATA structure is correctly defined.

Verify that the structure fields match the expected Windows API structure.


43-51: Ensure the Kernel32 interface methods are correctly defined.

Verify that the methods FindFirstFile and FindClose match the expected Windows API methods.


82-85: LGTM! The method isReparseTagMicrosoft correctly checks the reparse tag.

Comment on lines 53 to 80
public static int getReparseTag(String filePath)
{
WIN32_FIND_DATA findFileData = new WIN32_FIND_DATA();
WinNT.HANDLE hFind = Kernel32.INSTANCE.FindFirstFile(filePath, findFileData);

if (WinBase.INVALID_HANDLE_VALUE.equals(hFind))
{
Logger.log("FindFirstFile failed: " + Native.getLastError()); //$NON-NLS-1$
}

try
{
if ((findFileData.dwFileAttributes.intValue() & WinNT.FILE_ATTRIBUTE_REPARSE_POINT) != 0)
{
int reparseTag = findFileData.dwReserved0.intValue();
Logger.log("The file has a reparse point. Reparse Tag: 0x" + Integer.toHexString(reparseTag)); //$NON-NLS-1$
return reparseTag;
}
else
{
Logger.log("The file does not have a reparse point."); //$NON-NLS-1$
}
} finally
{
Kernel32.INSTANCE.FindClose(hFind);
}
return -1;
}
Copy link

Choose a reason for hiding this comment

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

Ensure proper error handling in getReparseTag.

Add error handling for the case when FindFirstFile fails.

-  if (WinBase.INVALID_HANDLE_VALUE.equals(hFind))
+  if (WinBase.INVALID_HANDLE_VALUE.equals(hFind) || hFind == null)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
public static int getReparseTag(String filePath)
{
WIN32_FIND_DATA findFileData = new WIN32_FIND_DATA();
WinNT.HANDLE hFind = Kernel32.INSTANCE.FindFirstFile(filePath, findFileData);
if (WinBase.INVALID_HANDLE_VALUE.equals(hFind))
{
Logger.log("FindFirstFile failed: " + Native.getLastError()); //$NON-NLS-1$
}
try
{
if ((findFileData.dwFileAttributes.intValue() & WinNT.FILE_ATTRIBUTE_REPARSE_POINT) != 0)
{
int reparseTag = findFileData.dwReserved0.intValue();
Logger.log("The file has a reparse point. Reparse Tag: 0x" + Integer.toHexString(reparseTag)); //$NON-NLS-1$
return reparseTag;
}
else
{
Logger.log("The file does not have a reparse point."); //$NON-NLS-1$
}
} finally
{
Kernel32.INSTANCE.FindClose(hFind);
}
return -1;
}
public static int getReparseTag(String filePath)
{
WIN32_FIND_DATA findFileData = new WIN32_FIND_DATA();
WinNT.HANDLE hFind = Kernel32.INSTANCE.FindFirstFile(filePath, findFileData);
if (WinBase.INVALID_HANDLE_VALUE.equals(hFind) || hFind == null)
{
Logger.log("FindFirstFile failed: " + Native.getLastError()); //$NON-NLS-1$
}
try
{
if ((findFileData.dwFileAttributes.intValue() & WinNT.FILE_ATTRIBUTE_REPARSE_POINT) != 0)
{
int reparseTag = findFileData.dwReserved0.intValue();
Logger.log("The file has a reparse point. Reparse Tag: 0x" + Integer.toHexString(reparseTag)); //$NON-NLS-1$
return reparseTag;
}
else
{
Logger.log("The file does not have a reparse point."); //$NON-NLS-1$
}
} finally
{
Kernel32.INSTANCE.FindClose(hFind);
}
return -1;
}

Comment on lines 739 to 749
public static boolean isReparseTag(File file)
{
if (!Platform.getOS().equals(Platform.OS_WIN32))
return false;
int reparseTag = FileParseTag.getReparseTag(file.getAbsolutePath());
if (reparseTag != -1)
{
return FileParseTag.isReparseTagMicrosoft(reparseTag);
}
return false;
}
Copy link

Choose a reason for hiding this comment

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

Ensure platform-specific code is correctly handled in isReparseTag.

Add a comment explaining why the method is specific to Windows.

// This method is specific to Windows as it uses Windows API to check reparse tags.

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 @kolipakakondal @sigmaaa kindly review as well these changes will affect more areas as well since there is now some change in SystemExecutableFinder as well

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.

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a110b7e and f872398.
Files selected for processing (3)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/SystemExecutableFinder.java (2 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/WinNativeFileTagOperations.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java
Additional comments not posted (8)
bundles/com.espressif.idf.core/src/com/espressif/idf/core/SystemExecutableFinder.java (2)

15-17: New imports for IDFUtil and WinNativeFileTagOperations are appropriate for the added functionality.


Line range hint 124-130: The remaining part of the isExecutable method correctly checks if the file exists and is not a directory.

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/WinNativeFileTagOperations.java (6)

28-53: The WIN32_FIND_DATA class is correctly defined with appropriate fields and constructors for JNA structure.


55-63: The Kernel32 interface is correctly defined and necessary for native file operations.


65-92: The getReparseTag method is correctly implemented with proper error handling and logging.


94-97: The isReparseTagMicrosoft method is correctly implemented and straightforward.


99-116: The fileExists method is correctly implemented with proper error handling and logging.


118-136: The isDirectory method is correctly implemented with proper error handling and logging.

Comment on lines +114 to +123

if (isPlatformWindows() && !file.exists())
{
if (WinNativeFileTagOperations.fileExists(file))
{
return IDFUtil.isReparseTag(file);
}
}


Copy link

@coderabbitai coderabbitai bot May 15, 2024

Choose a reason for hiding this comment

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

Simplify the nested conditions in the isExecutable method for better readability.

- if (isPlatformWindows() && !file.exists())
- {
-     if (WinNativeFileTagOperations.fileExists(file))
-     {
-         return IDFUtil.isReparseTag(file);
-     }
- }
+ if (isPlatformWindows() && !file.exists() && WinNativeFileTagOperations.fileExists(file)) {
+     return IDFUtil.isReparseTag(file);
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (isPlatformWindows() && !file.exists())
{
if (WinNativeFileTagOperations.fileExists(file))
{
return IDFUtil.isReparseTag(file);
}
}
if (isPlatformWindows() && !file.exists() && WinNativeFileTagOperations.fileExists(file)) {
return IDFUtil.isReparseTag(file);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

coderabbit makes a good point here

Copy link

Choose a reason for hiding this comment

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

@sigmaaa, thank you for your agreement. The suggested change indeed simplifies the nested conditions, making the code more readable. If there are no further concerns, this change can be implemented as suggested.

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

Comment on lines +114 to +123

if (isPlatformWindows() && !file.exists())
{
if (WinNativeFileTagOperations.fileExists(file))
{
return IDFUtil.isReparseTag(file);
}
}


Copy link
Collaborator

Choose a reason for hiding this comment

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

coderabbit makes a good point here

@AndriiFilippov
Copy link
Collaborator

@alirana01 hi !

Tested under:
OS - Windows 10
ESP-IDF: v5.2.1
Python: 3.11 / 3.12 / python3

Filter works good now, able to see both python.exe / python3.exe without any manual filter switching 👍
On Windows 10 everything works like it was ✔️

LGTM 👍

@kolipakakondal kolipakakondal merged commit 482a19a into master May 16, 2024
4 of 6 checks passed
@kolipakakondal kolipakakondal deleted the IEP-1226 branch May 16, 2024 06:15
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