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

Support running modules #45

Merged
merged 4 commits into from
Aug 4, 2018
Merged

Support running modules #45

merged 4 commits into from
Aug 4, 2018

Conversation

iddan
Copy link
Contributor

@iddan iddan commented Jul 30, 2018

Solves #43. It was a pleasure to get into the codebase. Would suggest adding setting up a venv into the readme under "contributing" or something.

@iddan
Copy link
Contributor Author

iddan commented Aug 1, 2018

@joerick can you please review it?

@joerick
Copy link
Owner

joerick commented Aug 1, 2018

sure thing. thanks for the contribution! i'll get around to it, just busy at work this week. I'll see if i can take a look at the weekend. thanks!

Copy link
Owner

@joerick joerick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! comments inline. There are no tests covering this at the moment, I've actually added a couple to master so could you pull that in before continuing? I've added a test with xfail for the module use-case, you can remove that to test your feature.

@@ -4,6 +4,7 @@
import codecs
from pyinstrument import Profiler
from pyinstrument.profiler import get_recorder_class, get_renderer_class
from importlib.util import find_spec
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find documentation for this on 2.7.... running on Python 2.7 gives me this:

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/joerick/04-Open-source-projects/pyinstrument/pyinstrument/__main__.py", line 7, in <module>
    from importlib.util import find_spec
ImportError: No module named util

Might need a polyfill for Python 2?

else:
renderer = 'text'
if options.module_name is not None:
progname = find_spec(options.module_name).origin
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is right - when I run find_spec('pyinstrument').origin in a shell it gives me the __init__.py file. It should be running the __main__.py file as I understand it.

The cProfile module uses runpy for this - it's probably best to copy that.

@iddan
Copy link
Contributor Author

iddan commented Aug 4, 2018

Changed to runpy and made test succeed

Copy link
Owner

@joerick joerick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks @iddan !

@joerick joerick merged commit 8578459 into joerick:master Aug 4, 2018
@iddan
Copy link
Contributor Author

iddan commented Aug 4, 2018

If you can please post when it is released to PyPI.

@joerick
Copy link
Owner

joerick commented Aug 4, 2018

Sorry for the delay - just addressing a bug I found before releasing... I had to make a minor change to this for programs that use ArgumentParser to work. Most programs assume sys.argv has at least one entry. see 2c05990

@joerick
Copy link
Owner

joerick commented Aug 4, 2018

released as 2.1.1!

@iddan
Copy link
Contributor Author

iddan commented Aug 5, 2018

Maybe update should be state in README?

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

Successfully merging this pull request may close these issues.

None yet

2 participants