234 |
234 |
235 Check absolute/relative import of extension specific modules |
235 Check absolute/relative import of extension specific modules |
236 |
236 |
237 $ mkdir $TESTTMP/extroot |
237 $ mkdir $TESTTMP/extroot |
238 $ cat > $TESTTMP/extroot/bar.py <<EOF |
238 $ cat > $TESTTMP/extroot/bar.py <<EOF |
239 > s = 'this is extroot.bar' |
239 > s = b'this is extroot.bar' |
240 > EOF |
240 > EOF |
241 $ mkdir $TESTTMP/extroot/sub1 |
241 $ mkdir $TESTTMP/extroot/sub1 |
242 $ cat > $TESTTMP/extroot/sub1/__init__.py <<EOF |
242 $ cat > $TESTTMP/extroot/sub1/__init__.py <<EOF |
243 > s = 'this is extroot.sub1.__init__' |
243 > s = b'this is extroot.sub1.__init__' |
244 > EOF |
244 > EOF |
245 $ cat > $TESTTMP/extroot/sub1/baz.py <<EOF |
245 $ cat > $TESTTMP/extroot/sub1/baz.py <<EOF |
246 > s = 'this is extroot.sub1.baz' |
246 > s = b'this is extroot.sub1.baz' |
247 > EOF |
247 > EOF |
248 $ cat > $TESTTMP/extroot/__init__.py <<EOF |
248 $ cat > $TESTTMP/extroot/__init__.py <<EOF |
249 > s = 'this is extroot.__init__' |
249 > from __future__ import absolute_import |
250 > import foo |
250 > s = b'this is extroot.__init__' |
|
251 > from . import foo |
251 > def extsetup(ui): |
252 > def extsetup(ui): |
252 > ui.write('(extroot) ', foo.func(), '\n') |
253 > ui.write(b'(extroot) ', foo.func(), b'\n') |
253 > ui.flush() |
254 > ui.flush() |
254 > EOF |
255 > EOF |
255 |
256 |
256 $ cat > $TESTTMP/extroot/foo.py <<EOF |
257 $ cat > $TESTTMP/extroot/foo.py <<EOF |
257 > # test absolute import |
258 > # test absolute import |
258 > buf = [] |
259 > buf = [] |
259 > def func(): |
260 > def func(): |
260 > # "not locals" case |
261 > # "not locals" case |
261 > import extroot.bar |
262 > import extroot.bar |
262 > buf.append('import extroot.bar in func(): %s' % extroot.bar.s) |
263 > buf.append(b'import extroot.bar in func(): %s' % extroot.bar.s) |
263 > return '\n(extroot) '.join(buf) |
264 > return b'\n(extroot) '.join(buf) |
264 > # "fromlist == ('*',)" case |
265 > # b"fromlist == ('*',)" case |
265 > from extroot.bar import * |
266 > from extroot.bar import * |
266 > buf.append('from extroot.bar import *: %s' % s) |
267 > buf.append(b'from extroot.bar import *: %s' % s) |
267 > # "not fromlist" and "if '.' in name" case |
268 > # "not fromlist" and "if '.' in name" case |
268 > import extroot.sub1.baz |
269 > import extroot.sub1.baz |
269 > buf.append('import extroot.sub1.baz: %s' % extroot.sub1.baz.s) |
270 > buf.append(b'import extroot.sub1.baz: %s' % extroot.sub1.baz.s) |
270 > # "not fromlist" and NOT "if '.' in name" case |
271 > # "not fromlist" and NOT "if '.' in name" case |
271 > import extroot |
272 > import extroot |
272 > buf.append('import extroot: %s' % extroot.s) |
273 > buf.append(b'import extroot: %s' % extroot.s) |
273 > # NOT "not fromlist" and NOT "level != -1" case |
274 > # NOT "not fromlist" and NOT "level != -1" case |
274 > from extroot.bar import s |
275 > from extroot.bar import s |
275 > buf.append('from extroot.bar import s: %s' % s) |
276 > buf.append(b'from extroot.bar import s: %s' % s) |
276 > EOF |
277 > EOF |
277 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.extroot=$TESTTMP/extroot root) |
278 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.extroot=$TESTTMP/extroot root) |
278 (extroot) from extroot.bar import *: this is extroot.bar |
279 (extroot) from extroot.bar import *: this is extroot.bar |
279 (extroot) import extroot.sub1.baz: this is extroot.sub1.baz |
280 (extroot) import extroot.sub1.baz: this is extroot.sub1.baz |
280 (extroot) import extroot: this is extroot.__init__ |
281 (extroot) import extroot: this is extroot.__init__ |
473 > # real "module" object) might hide problem of succeeding import. |
474 > # real "module" object) might hide problem of succeeding import. |
474 > |
475 > |
475 > @command(b'showabsolute', [], norepo=True) |
476 > @command(b'showabsolute', [], norepo=True) |
476 > def showabsolute(ui, *args, **opts): |
477 > def showabsolute(ui, *args, **opts): |
477 > from absextroot import absolute |
478 > from absextroot import absolute |
478 > ui.write(b'ABS: %s\n' % '\nABS: '.join(absolute.getresult())) |
479 > ui.write(b'ABS: %s\n' % b'\nABS: '.join(absolute.getresult())) |
479 > |
480 > |
480 > @command(b'showrelative', [], norepo=True) |
481 > @command(b'showrelative', [], norepo=True) |
481 > def showrelative(ui, *args, **opts): |
482 > def showrelative(ui, *args, **opts): |
482 > from . import relative |
483 > from . import relative |
483 > ui.write(b'REL: %s\n' % '\nREL: '.join(relative.getresult())) |
484 > ui.write(b'REL: %s\n' % b'\nREL: '.join(relative.getresult())) |
484 > |
485 > |
485 > # import modules from external library |
486 > # import modules from external library |
486 > from extlibroot.lsub1.lsub2 import used as lused, unused as lunused |
487 > from extlibroot.lsub1.lsub2 import used as lused, unused as lunused |
487 > from extlibroot.lsub1.lsub2.called import func as lfunc |
488 > from extlibroot.lsub1.lsub2.called import func as lfunc |
488 > from extlibroot.recursedown import absdetail, legacydetail |
489 > from extlibroot.recursedown import absdetail, legacydetail |
493 > result.append(lused.detail) |
494 > result.append(lused.detail) |
494 > result.append(lfunc()) |
495 > result.append(lfunc()) |
495 > result.append(absdetail) |
496 > result.append(absdetail) |
496 > result.append(legacydetail) |
497 > result.append(legacydetail) |
497 > result.append(proxied.detail) |
498 > result.append(proxied.detail) |
498 > ui.write(b'LIB: %s\n' % '\nLIB: '.join(result)) |
499 > ui.write(b'LIB: %s\n' % b'\nLIB: '.join(result)) |
499 > EOF |
500 > EOF |
500 |
501 |
501 Examine module importing. |
502 Examine module importing. |
502 |
503 |
503 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.absextroot=$TESTTMP/absextroot showabsolute) |
504 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}; hg --config extensions.absextroot=$TESTTMP/absextroot showabsolute) |