-
Notifications
You must be signed in to change notification settings - Fork 36
Fix path comparison #445
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
base: master
Are you sure you want to change the base?
Fix path comparison #445
Conversation
@zabil @sriv @chadlwilson someone in the position to review it? 😄 |
Not a full review. But won't this cause an issue on non windows system where the filenames and paths are case sensitive? |
Fair point, I was not aware of this fact. I will have another look! |
This was my first thought after skimming through this, but didn't have time/energy to think it through and write those tests myself. It usually ends in pain to try and use magic to treat case sensitive file systems as if they are non-sensitive, and vice versa. And there are weirder cases for in-between, case-preserving file systems.
Yeah, I found it difficult to follow which problem is being attempted being fixed here without tests of any kind. |
Maybe the issue is not even in this repo but in the actual VS Code plugin? I may try to explain the issue again. In my project I started to use the "share steps" feature more often. I have a shared folder with many steps. If you have a Python file without a class, the steps are found perfectly fine. If I have a Python class with a class, so we must have the instance to map the method parameters, the issue comes up. VS code seems to handle paths differently compared to Git for Windows. The issue is visible in VS code only.
If the paths are different, the instance is not set properly. Therefore I tried to find a solution so that the paths are aligned. It should not matter if the C driver is written in capital or lower case. But in my case, the var |
Signed-off-by: sschulz92 <[email protected]>
Signed-off-by: sschulz92 <[email protected]>
Signed-off-by: sschulz92 <[email protected]>
Signed-off-by: sschulz92 <[email protected]>
Signed-off-by: sschulz92 <[email protected]>
…not Windows Signed-off-by: sschulz92 <[email protected]>
Signed-off-by: sschulz92 <[email protected]>
@zabil @chadlwilson I've added two tests to cover the two different cases. Does the issue makes more sense to you now? 😄 |
getgauge/registry.py
Outdated
p1 = Path(p1).resolve() | ||
p2 = Path(p2).resolve() | ||
if sys.platform.startswith("win"): | ||
# As Windows is case-insensitive, we can use 'normcase' to compare paths! | ||
return os.path.normcase(str(p1)) == os.path.normcase(str(p2)) | ||
# Mac (and others) allows to use case-sensitive files/folders! | ||
return p1 == p2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be the right thing to do, but these operations probably require filesystem operations (since not using PurePath
, and no way to normalize symlinks/junction points without FS access).
This will likely make things slower. If we can achieve the goal correctly & securely, without resolving actual file system paths we should try to do that.
Also, do we need to mix os.path
and pathlib
usage?
- are you intentionally trying to add normalization of
..
and symlinks viaresolve()
? - if not, why not just use normcase for all platforms? Docs say it's a no-op on case-sensitive filesystems, so it'd be cleaner to use the library to avoid platform specific logic.
There is already some sort of path normalisation logic at both gauge-python/getgauge/impl_loader.py Line 78 in 5ad2747
and gauge-python/getgauge/impl_loader.py Line 102 in 5ad2747
(...and other places) This is getting rather confusing to me. It feels like we should have one place/consistent approach to how/when we normalise paths, as there are already a lot of hacks around the place :-( Do you know what the origin of the inconsistent |
Totally agree, it is very difficult already. From my perspective it does not need to be that difficult as we want to "simply" load steps from different file locations. Regarding your question: no, I am not aware of the origin. I started to use this feature recently but I guess the issue might exist even longer (no prove for that!). Since the plugin is written in TypeScript I cannot help much as I have too less knowledge about VS code and its behavior. |
Signed-off-by: sschulz92 <[email protected]>
…e to import Signed-off-by: sschulz92 <[email protected]>
Should be fixed now if you merge or rebase from master. |
Signed-off-by: sschulz92 <[email protected]>
You are soo fast in responding.. wow 😄 |
Signed-off-by: sschulz92 <[email protected]>
Right now I'm not working, so have a bit more time to spend on OSS (although Gauge is not my focus) and I've been shepherding some projects through Gradle upgrades (including Gauge functional tests), which is why this broke, and also why I should fix it promptly :) The root problem here is that the gauge func/integration and LSP tests aren't modelled as reusable GitHub actions, so the requirements to run them are not self contained in their own repo and are thus distributed around all the plugin projects which need changing individually for certain changes. |
@chadlwilson the failed check passed on the forked branch, so not sure about that. In general, what I did:
That's mainly it, what do you think about it? I added a few debug logs, not sure if we really want them. While debugging they were quite helpfull to see the differences between current released version and my snapshot one. On my machine, this version of the Python runner works like a charm. |
I identified an issue using relative imports. After several iterations I found out, that the method
get_all_methods_in()
was comparing file paths, which were equal except theC:
upfront. One path was usingC
the other onec
and therefore no step was found.At runtime I could see the following error:
The mentioned class is required to be instantiated. Therefore we had 2 positional arguments: self + step_var! Since self should have been gone at this point already, the issue appeared.
Overall I think the issue is, that we mix up different path variables. If you would use paths from
pathlib
everywhere, the issue should have been resolved in first place. To resolve my issue, thestr().lower()
approach is easier though.After installing a custom python version on my machine, the test scenario is running fine again!