gauge-sh / tach

A Python tool to enforce dependencies, using modular architecture 🌎 Open source 🐍 Installable via pip πŸ”§ Able to be adopted incrementally - ⚑ Implemented with no runtime impact ♾️ Interoperable with your existing systems πŸ¦€ Written in rust
https://gauge.sh
MIT License
1.15k stars 36 forks source link

Tach fails in Windows when building exclusion paths, because it does not handle backslash #326

Closed aawilson closed 1 month ago

aawilson commented 2 months ago

Running tach with an exclusions in Windows (Powershell, presumably also in cmd.exe) produces an error like the following:

Failed to build regex pattern for excluded path:
C:\users\aawilson\projects\someproject\.*__pycache__
regex parse error:
    C:\users\aawilson\projects\someproject\.*__pycache__
      ^^
error: unrecognized escape sequence

I don't know enough about the usage of the built regex to know if it will be sufficient to escape the backslashes here, since the tach.toml may specify them with solidus it is probably necessary to normalize path separators at various points.

emdoyle commented 2 months ago

Thanks for raising this! Will take a look and address this in the next release.

EDIT: This will take a bit longer to land, since I need to set up Windows in CI to test, and it looks like there are some other issues to sort out -- https://github.com/gauge-sh/tach/actions/runs/11004553025

In the meantime, could you try adding an extra backslash to 'escape' them and let me know if that works?

aawilson commented 1 month ago

It doesn't, the actual pattern in the .toml is .*__pycache__ and has nothing to escape, the rest is coming from whatever you're using in Rust to get the cwd.

emdoyle commented 1 month ago

@aawilson I don't have a Windows machine easily accessible to test, but version 0.12.0 should resolve this issue on Windows. Could you let me know if upgrading fixes the issue?

aawilson commented 1 month ago

Sorry for the slow response, I was on vacation. This appears to have resolved the issue, thanks a million for quick action here. (note that this is for tach check/sync, I haven't used the tool enough to know if maybe there are still quirks to get past in the other tools)

aawilson commented 1 month ago

I did play around with more of the functionality and there may be a cousin to this issue still lurking. I'm able to run "tach report" on a path within my project in my WSL container, but not from PowerShell, receiving this error:

Report failed: Filesystem error: No matching source root found for filepath: "\\\\?\\C:\\users\\aawilson\\projects\\someproject\\some\\path"
emdoyle commented 1 month ago

I did play around with more of the functionality and there may be a cousin to this issue still lurking. I'm able to run "tach report" on a path within my project in my WSL container, but not from PowerShell, receiving this error:

Report failed: Filesystem error: No matching source root found for filepath: "\\\\?\\C:\\users\\aawilson\\projects\\someproject\\some\\path"

Thanks for reporting! I'll take a look at this soon. If you get a sec, would you mind reposting this as a separate issue?