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

is_native doesn't handle the TypeError case from os.path.dirname. #587

Closed
ahaberlach opened this issue Mar 28, 2023 · 1 comment
Closed

Comments

@ahaberlach
Copy link
Contributor

Describe the bug

"is_native" check seems to be failing to catch TypeError which is returned by os.path.dirname(None)

I was running into this while profiling some native code, and it may be a python 3.8 or older system issue.

"~/.virtualenv/production/lib/python3.8/site-packages/scalene/scalene_analysis.py" 137L, 5125C                                                                          23,13         Top
  File "/home/ubuntu/.virtualenv/production/lib/python3.8/site-packages/scalene/scalene_profiler.py", line 932, in output_profile
    json_output = Scalene.__json.output_profiles(
  File "/home/ubuntu/.virtualenv/production/lib/python3.8/site-packages/scalene/scalene_json.py", line 393, in output_profiles
    imports = ScaleneAnalysis.get_native_imported_modules(code_str)
  File "/home/ubuntu/.virtualenv/production/lib/python3.8/site-packages/scalene/scalene_analysis.py", line 93, in get_native_imported_modules
    if ScaleneAnalysis.is_native(node.module):
  File "/home/ubuntu/.virtualenv/production/lib/python3.8/site-packages/scalene/scalene_analysis.py", line 23, in is_native
    package_dir = os.path.dirname(package.__file__)
  File "/usr/lib/python3.8/posixpath.py", line 152, in dirname
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

I fixed/worked around by adding the check for TypeError to scalene_analysis.py. I've got a PR on the way.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Please include a minimum working example if at all possible.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

If you have not yet tried with the repository version (python3 -m pip install git+https://github.com/plasma-umass/scalene), please try that before reporting.

Additional context
Add any other context about the problem here.

emeryberger pushed a commit that referenced this issue Mar 30, 2023
This should address #587 which has more information, but basically the check for native fails on at least my system because package.__file__ exists, but is None, so os.path.dirname() returns a TypeError.
@emeryberger
Copy link
Member

I believe this is fixed. Please let me know either way!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants