145 >>> fromlocal2('bar2', 1) |
145 >>> fromlocal2('bar2', 1) |
146 False |
146 False |
147 >>> fromlocal2('bar', 2) |
147 >>> fromlocal2('bar', 2) |
148 ('foo.bar', 'foo.bar.__init__', True) |
148 ('foo.bar', 'foo.bar.__init__', True) |
149 """ |
149 """ |
|
150 if not isinstance(modulename, str): |
|
151 modulename = modulename.decode('ascii') |
150 prefix = '.'.join(modulename.split('.')[:-1]) |
152 prefix = '.'.join(modulename.split('.')[:-1]) |
151 if prefix: |
153 if prefix: |
152 prefix += '.' |
154 prefix += '.' |
153 def fromlocal(name, level=0): |
155 def fromlocal(name, level=0): |
154 # name is false value when relative imports are used. |
156 # name is false value when relative imports are used. |
404 applies to import statements outside of any blocks. |
406 applies to import statements outside of any blocks. |
405 * Relative imports from the standard library are not allowed. |
407 * Relative imports from the standard library are not allowed. |
406 * Certain modules must be aliased to alternate names to avoid aliasing |
408 * Certain modules must be aliased to alternate names to avoid aliasing |
407 and readability problems. See `requirealias`. |
409 and readability problems. See `requirealias`. |
408 """ |
410 """ |
|
411 if not isinstance(module, str): |
|
412 module = module.decode('ascii') |
409 topmodule = module.split('.')[0] |
413 topmodule = module.split('.')[0] |
410 fromlocal = fromlocalfunc(module, localmods) |
414 fromlocal = fromlocalfunc(module, localmods) |
411 |
415 |
412 # Whether a local/non-stdlib import has been performed. |
416 # Whether a local/non-stdlib import has been performed. |
413 seenlocal = None |
417 seenlocal = None |
722 for source_path in argv[1:]: |
726 for source_path in argv[1:]: |
723 modname = dotted_name_of_path(source_path) |
727 modname = dotted_name_of_path(source_path) |
724 localmodpaths[modname] = source_path |
728 localmodpaths[modname] = source_path |
725 localmods = populateextmods(localmodpaths) |
729 localmods = populateextmods(localmodpaths) |
726 for localmodname, source_path in sorted(localmodpaths.items()): |
730 for localmodname, source_path in sorted(localmodpaths.items()): |
|
731 if not isinstance(localmodname, bytes): |
|
732 # This is only safe because all hg's files are ascii |
|
733 localmodname = localmodname.encode('ascii') |
727 for src, modname, name, line in sources(source_path, localmodname): |
734 for src, modname, name, line in sources(source_path, localmodname): |
728 try: |
735 try: |
729 used_imports[modname] = sorted( |
736 used_imports[modname] = sorted( |
730 imported_modules(src, modname, name, localmods, |
737 imported_modules(src, modname, name, localmods, |
731 ignore_nested=True)) |
738 ignore_nested=True)) |