Closed bluebird75 closed 5 years ago
Does it work better if you use forward / on the command line (starting from the top)?
Not really. Even if I do that and I convert the backslash to forward slash in type_info.json .
Hm... What if you add an empty __init__.py
file to the toto folder? (I'm
quite sure that this works at Dropbox.)
I tracked down the problem up to here : https://github.com/dropbox/pyannotate/blob/a01510d2960cb8fb0096f6c017391ea9b9e98689/pyannotate_tools/fixes/fix_annotate_json.py#L205
self.__class__.top_dir
is 'D:\work\pyann\pyannotate\toto' and it['path'] is 'toto\toto.py' . So joining them together won't work, the directory toto is duplicated in the path.
Looks like crawl_up() was not designed to handle such cases. It miscalculates the top directory in this case : https://github.com/dropbox/pyannotate/blob/a01510d2960cb8fb0096f6c017391ea9b9e98689/pyannotate_tools/fixes/fix_annotate_json.py#L43
Confirmed -- also that if I add an empty __init__.py
to the toto
folder the problem goes away.
I replicated this by going to the pyannotate project root directory, running python example/driver.py
, and then trying pyannotate example/gcd.py
.
But I'm not sure what to do about it. It's been too long since I knew this code in and out, and while I know what crawl_up() is supposed to do, I'm no longer sure why that is needed here. If I replace its body with return os.getcwd(), arg
the code works, and no tests fail! But I've got a feeling that would break something else (at least in the way we use it at Dropbox) -- I just don't recall what.
The code could use more tests in general, and in particular to capture precisely this kind of behavior.
I would expect that this is needed if you are working with multiple in development packages and you are adjusting sys.path to pick all these packages (maybe even with pip). In this case, relating getcwd() current execution dir is no longer the right thing to do.
I have encountered the same issue and have a small patch based on observations from @gvanrossum that works for me, maybe someone else will benefit from this. For a proper testing there will be more work involved, and I think that a command line option to guide the matching of sources to the json would be good. It could also be embedded in the json collection, so that we find the supposed topdir and embed what we find at collection time into the json that would help the annotator match up.
FWIW I also ran into this, and I just commented out crawl_up()
in my local copy for now. For some reason it caused the paths in the items
comparison to be one subdirectory off.
Before the change, I had a good type_info.json file, but nothing was being applied. After the change, everything was applied as far as I can tell.
I am also experiencing the exact same thing. It only works by mofiying the paths in the JSON from:
[
{
"path": "C:/Users/Me/Documents/GitHub/sabnzbd3/SABnzbd.py",
"line": 102,
"func_name": "GUIHandler",
"type_comments": [
"() -> None"
],
"samples": 1
},
]
to
[
{
"path": "SABnzbd.py",
"line": 102,
"func_name": "GUIHandler",
"type_comments": [
"() -> None"
],
"samples": 1
},
]
After this it did exactly what I hoped it would do. Thanks very much for this tool ❤️
Unfortunately I have no time available to work on this. If someone could prepare a patch, including a bunch of tests that show how it works in various common and edge cases, I would very much appreciate it.
Yes I will do it
On Fri, Mar 22, 2019, 11:14 Guido van Rossum notifications@github.com wrote:
Unfortunately I have no time available to work on this. If someone could prepare a patch, including a bunch of tests that show how it works in various common and edge cases, I would very much appreciate it.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dropbox/pyannotate/issues/75#issuecomment-475659594, or mute the thread https://github.com/notifications/unsubscribe-auth/APqoaWuMEu0TbiozBy9zwhrlJ2K9MufOks5vZPNGgaJpZM4Vfa9i .
I was thinking it could be as simple as adding a flag like --crawl-up
or --no-crawl-up
? As mentioned I could simply delete the crawl_up() call and things work (for me), but that might break some unknown things witin Dropbox?
The following will fail :
strange, there are type annotations in type_info.json with the correct path
edit the type_info.json to remove the "toto\"
try again
it worked...
It looks like pyannotate is trimming directories from type_info.json too agressively.