pydeps icon indicating copy to clipboard operation
pydeps copied to clipboard

Draft: Enable parsing of extension-less files

Open JosiahOne opened this issue 3 years ago • 3 comments

It's somewhat common for python scripts to be stored on disk as if they were executables (i.e. with no extension).

However, the current is_pysource function and properties explicitly check for a few known python extensions which causing pydeps to fail on such scripts (due to a assert target.is_pysource call in DummyModule.

This PR proposes adding a condition to assume any extension-less file is in fact a python script. I've added a test case to verify the change.

JosiahOne avatar Aug 24 '22 21:08 JosiahOne

Codecov Report

Merging #154 (f159a1e) into master (72003a3) will decrease coverage by 0.08%. The diff coverage is 40.00%.

@@            Coverage Diff             @@
##           master     #154      +/-   ##
==========================================
- Coverage   73.65%   73.57%   -0.09%     
==========================================
  Files          17       17              
  Lines        1435     1438       +3     
  Branches      302      304       +2     
==========================================
+ Hits         1057     1058       +1     
  Misses        299      299              
- Partials       79       81       +2     
Impacted Files Coverage Δ
pydeps/dummymodule.py 69.86% <25.00%> (-3.00%) :arrow_down:
pydeps/target.py 95.38% <100.00%> (ø)
pydeps/depgraph.py 75.35% <0.00%> (+0.35%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Aug 25 '22 08:08 codecov-commenter

To try to address code coverage I consolidated what appeared (to me) to be redundant logic. target.py now uses the is_pysource() function from dummymodule.py.

JosiahOne avatar Aug 26 '22 15:08 JosiahOne

Oof, I see my test is incorrect. I'm checking that for an empty set where I don't want to.

I tried to look at fixing that, but there are other issues (almost certainly this was the reason the old assertions existed for checking whether files ended with .py to begin with). ModuleFinder.run_script() is used under-the-hood to resolve imports, but this method seems to only support files ending with .py. Or at the very least, pydeps interaction with this function is failing on files not ending with .py even though the file content is identical. I'll look into this some more.

JosiahOne avatar Aug 29 '22 17:08 JosiahOne