Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions dev/autoprofile-poc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

def create_poc(dry_run=False):
root = ub.Path.appdir('line_profiler/test/poc/')
repo = (root / 'repo')
repo = root / 'repo'
modpaths = {}
modpaths['script'] = (root / 'repo/script.py')
modpaths['foo'] = (root / 'repo/foo')
modpaths['foo.__init__'] = (root / 'repo/foo/__init__.py')
modpaths['foo.bar'] = (root / 'repo/foo/bar.py')
modpaths['foo.baz'] = (root / 'repo/foo/baz')
modpaths['foo.baz.__init__'] = (root / 'repo/foo/baz/__init__.py')
modpaths['foo.baz.spam'] = (root / 'repo/foo/baz/spam.py')
modpaths['foo.baz.eggs'] = (root / 'repo/foo/baz/eggs.py')
modpaths['script'] = root / 'repo/script.py'
modpaths['foo'] = root / 'repo/foo'
modpaths['foo.__init__'] = root / 'repo/foo/__init__.py'
modpaths['foo.bar'] = root / 'repo/foo/bar.py'
modpaths['foo.baz'] = root / 'repo/foo/baz'
modpaths['foo.baz.__init__'] = root / 'repo/foo/baz/__init__.py'
modpaths['foo.baz.spam'] = root / 'repo/foo/baz/spam.py'
modpaths['foo.baz.eggs'] = root / 'repo/foo/baz/eggs.py'

if not dry_run:
root.delete().ensuredir()
Expand All @@ -45,7 +45,7 @@ def create_poc(dry_run=False):

"""different import variations to handle"""
script_text = ub.codeblock(
'''
"""
import foo # mod
import foo.bar # py
from foo import bar # py
Expand All @@ -69,7 +69,8 @@ def main():
main()
test()
# asdf()
''')
"""
)
ub.writeto(modpaths['script'], script_text)

return root, repo, modpaths
Expand Down Expand Up @@ -115,11 +116,13 @@ def main():
import sys
import os
import builtins

__file__ = script_file
__name__ = '__main__'
script_directory = os.path.realpath(os.path.dirname(script_file))
sys.path.insert(0, script_directory)
import line_profiler

prof = line_profiler.LineProfiler()
builtins.__dict__['profile'] = prof
ns = locals()
Expand All @@ -130,5 +133,6 @@ def main():
print('=' * 10)
prof.print_stats(output_unit=1e-6, stripzeros=True, stream=sys.stdout)


if __name__ == '__main__':
main()
27 changes: 22 additions & 5 deletions dev/maintain/port_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
~/code/mkinit/dev/maintain/port_ubelt_code.py
~/code/line_profiler/dev/maintain/port_utilities.py
"""

import ubelt as ub
import liberator
import re
Expand Down Expand Up @@ -45,15 +46,18 @@ def generate_util_static():
:py:mod:`xdoctest` via dev/maintain/port_utilities.py in the
line_profiler repo.
"""
''')
'''
)

# Remove doctest references to ubelt
new_lines = []
for line in text.split('\n'):
if line.strip().startswith('>>> from ubelt'):
continue
if line.strip().startswith('>>> import ubelt as ub'):
line = re.sub('>>> .*', '>>> # xdoctest: +SKIP("ubelt dependency")', line)
line = re.sub(
'>>> .*', '>>> # xdoctest: +SKIP("ubelt dependency")', line
)
new_lines.append(line)

text = '\n'.join(new_lines)
Expand All @@ -67,13 +71,26 @@ def main():

import parso
import line_profiler
target_fpath = ub.Path(line_profiler.__file__).parent / 'autoprofile' / 'util_static.py'

target_fpath = (
ub.Path(line_profiler.__file__).parent
/ 'autoprofile'
/ 'util_static.py'
)

new_module = parso.parse(text)
if target_fpath.exists():
old_module = parso.parse(target_fpath.read_text())
new_names = [child.name.value for child in new_module.children if child.type in {'funcdef', 'classdef'}]
old_names = [child.name.value for child in old_module.children if child.type in {'funcdef', 'classdef'}]
new_names = [
child.name.value
for child in new_module.children
if child.type in {'funcdef', 'classdef'}
]
old_names = [
child.name.value
for child in old_module.children
if child.type in {'funcdef', 'classdef'}
]
print(set(old_names) - set(new_names))
print(set(new_names) - set(old_names))

Expand Down
Loading
Loading