Error installing package when __version__ is instrumented
Closed this issue · 4 comments
Trying to run DynaPyt on the FastAPI project, with TraceAll analysis using the experiment.sh
script. I get the following error when the script installs fastapi after instrumentation:
Key line is ValueError: Error getting the version from source 'regex': unable to parse the version from the file: fastapi/__init__.py
. It seems like pip parses fastapi/__init__.py
to find the package's version number, and is unable to find the version number here.
The file fastapi/__init__.py
looks like this after instrumentation:
Moving the __version__
declaration to outside of the try-catch block, and replacing the _write_
hook with "0.96.0"
, makes the error go away when re-running the script (just moving it to outside the try-catch block or just replacing the _write_
hook with "0.96.0"
is not sufficient; you need to do both):
Making the change above makes installation and tests run correctly. Is this worth changing the instrumentation code so that variables with the name __version__
are never instrumented?
Ran into the same issue with beautifulsoup. Perhaps other variables such as __author_
, __copyright__
, __license__
, and __all__
should also be considered?
It seems like the _write_
hook has an exception such that variables called __version__
in __init__.py
files are not instrumented. However, no such exception applies for the _str_
hook or the try-catch hook
I think this commit should not have this problem anymore.
Feel free to reopen the issue if it is not resolved or if you find another way it can fail.
Thank you for the patch @AryazE! I tested this on beautifulsoup with TraceAll. Instrumenting and installing the package works, but when running tests I got this error:
The instrumented source code which caused the issue (line 752 is the end of the file):
Seems like the rest of the tokens for __all__
were not copied over. I'm going to try and write a PR but don't feel a need to wait