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

Bug: common_base not found on Windows #15

Closed
1 of 2 tasks
hectormz opened this issue May 6, 2020 · 8 comments
Closed
1 of 2 tasks

Bug: common_base not found on Windows #15

hectormz opened this issue May 6, 2020 · 8 comments
Labels
bug Something isn't working

Comments

@hectormz
Copy link

hectormz commented May 6, 2020

First of all, I really like the intent of this package! 👍

Is this a BUG REPORT or FEATURE REQUEST?:

  • bug
  • feature

Description of Bug or Feature

Environment

  • interrogate version: 1.14
  • Operating System(s): Windows 10
  • Python version(s): 3.8

What happened

utils.get_common_base() does not find the common base for files on Windows.

This happens because path levels are split by \\ in Python on Windows. As a result, the common_base is an empty string (""). This has a downstream effect when generating the summary tables.

Specifically, in _get_filename(), since the common_base is an empty string, a filepath:

C:\path\to\project_root\src\file.py

becomes
:\path\to\project_root\src\file.py

instead of:
\src\file.py

Suggestion

Since this is a python 3.5+ project, I think that this could be fixed in a flexible way by handling filepaths with pathlib instead.
For example this in utils.py:

level_slices = zip(*[f.split("/") for f in files])

could be replaced with:

from pathlib import Path
level_slices = zip(*[Path(f).parts for f in files])

(if file names had not already been converted to Path objects)

Using pathlib here would help make this feature work across systems, but I think it could also replace just about all path manipulation interrogate uses os for.

If you'd like I could work contributing to any of these proposed changes.

@econchick
Copy link
Owner

Hey @hectormz ! Thanks so much for such a thorough bug report, it's very helpful. I'd welcome any contribution :) LMK if I can help at all.

@econchick econchick added the bug Something isn't working label May 6, 2020
@hectormz
Copy link
Author

hectormz commented May 6, 2020

@econchick sure thing. I'll make a PR and see what you think!

Another thing that I found was that I had attrs version 19.1.0 installed, which causes an error when using interrogate. The error goes away if using attrs>=19.2.0.

I can include that version requirement in setup.py during this PR unless you'd like a separate one.

@econchick
Copy link
Owner

Ah good catch - yea feel free to through that in the same PR (separate commit if possible though). I appreciate it!

@econchick
Copy link
Owner

So instead of fixing all the paths, I tried to keep the bug fix very narrow. Unfortunately I don't have an easy way to test on a windows machine. Would you mind checking out #18 for me? In the mean time, I'm going to try and get github actions to work w windows, but it's not as easy as I thought...

@econchick
Copy link
Owner

@hectormz aha! I got windows testing to work on github! and found lots of test failures :D I am working through them :)

@hectormz
Copy link
Author

hectormz commented May 9, 2020

So instead of fixing all the paths, I tried to keep the bug fix very narrow. Unfortunately I don't have an easy way to test on a windows machine. Would you mind checking out #18 for me? In the mean time, I'm going to try and get github actions to work w windows, but it's not as easy as I thought...

Yes, let me get to my computer and test this out for you.

@hectormz
Copy link
Author

hectormz commented May 9, 2020

@hectormz aha! I got windows testing to work on github! and found lots of test failures :D I am working through them :)

@econchick awesome! When I was working through this I found it easier to test on a Linux VM then figure out the Windows test failures 😁. I assumed they might be due to the posix-style path patterns in the tests?

@econchick
Copy link
Owner

Addressed by #18 (thanks again @hectormz!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants