198 $ echo "s = 'libroot/ambig.py'" > $TESTTMP/libroot/ambig.py |
205 $ echo "s = 'libroot/ambig.py'" > $TESTTMP/libroot/ambig.py |
199 $ mkdir $TESTTMP/libroot/mod |
206 $ mkdir $TESTTMP/libroot/mod |
200 $ touch $TESTTMP/libroot/mod/__init__.py |
207 $ touch $TESTTMP/libroot/mod/__init__.py |
201 $ echo "s = 'libroot/mod/ambig.py'" > $TESTTMP/libroot/mod/ambig.py |
208 $ echo "s = 'libroot/mod/ambig.py'" > $TESTTMP/libroot/mod/ambig.py |
202 |
209 |
203 $ cat > $TESTTMP/libroot/mod/ambigabs.py <<EOF |
210 $ cat > $TESTTMP/libroot/mod/ambigabs.py <<NO_CHECK_EOF |
204 > from __future__ import absolute_import, print_function |
211 > from __future__ import absolute_import, print_function |
205 > import ambig # should load "libroot/ambig.py" |
212 > import ambig # should load "libroot/ambig.py" |
206 > s = ambig.s |
213 > s = ambig.s |
207 > EOF |
214 > NO_CHECK_EOF |
208 $ cat > loadabs.py <<EOF |
215 $ cat > loadabs.py <<NO_CHECK_EOF |
209 > import mod.ambigabs as ambigabs |
216 > import mod.ambigabs as ambigabs |
210 > def extsetup(): |
217 > def extsetup(): |
211 > print('ambigabs.s=%s' % ambigabs.s, flush=True) |
218 > print('ambigabs.s=%s' % ambigabs.s, flush=True) |
212 > EOF |
219 > NO_CHECK_EOF |
213 $ $PYTHON $TESTTMP/unflush.py loadabs.py |
220 $ $PYTHON $TESTTMP/unflush.py loadabs.py |
214 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}/libroot; hg --config extensions.loadabs=loadabs.py root) |
221 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}/libroot; hg --config extensions.loadabs=loadabs.py root) |
215 ambigabs.s=libroot/ambig.py |
222 ambigabs.s=libroot/ambig.py |
216 $TESTTMP/a |
223 $TESTTMP/a |
217 |
224 |
218 #if no-py3k |
225 #if no-py3k |
219 $ cat > $TESTTMP/libroot/mod/ambigrel.py <<EOF |
226 $ cat > $TESTTMP/libroot/mod/ambigrel.py <<NO_CHECK_EOF |
220 > from __future__ import print_function |
227 > from __future__ import print_function |
221 > import ambig # should load "libroot/mod/ambig.py" |
228 > import ambig # should load "libroot/mod/ambig.py" |
222 > s = ambig.s |
229 > s = ambig.s |
223 > EOF |
230 > NO_CHECK_EOF |
224 $ cat > loadrel.py <<EOF |
231 $ cat > loadrel.py <<NO_CHECK_EOF |
225 > import mod.ambigrel as ambigrel |
232 > import mod.ambigrel as ambigrel |
226 > def extsetup(): |
233 > def extsetup(): |
227 > print('ambigrel.s=%s' % ambigrel.s, flush=True) |
234 > print('ambigrel.s=%s' % ambigrel.s, flush=True) |
228 > EOF |
235 > NO_CHECK_EOF |
229 $ $PYTHON $TESTTMP/unflush.py loadrel.py |
236 $ $PYTHON $TESTTMP/unflush.py loadrel.py |
230 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}/libroot; hg --config extensions.loadrel=loadrel.py root) |
237 $ (PYTHONPATH=${PYTHONPATH}${PATHSEP}${TESTTMP}/libroot; hg --config extensions.loadrel=loadrel.py root) |
231 ambigrel.s=libroot/mod/ambig.py |
238 ambigrel.s=libroot/mod/ambig.py |
232 $TESTTMP/a |
239 $TESTTMP/a |
233 #endif |
240 #endif |
234 |
241 |
235 Check absolute/relative import of extension specific modules |
242 Check absolute/relative import of extension specific modules |
236 |
243 |
237 $ mkdir $TESTTMP/extroot |
244 $ mkdir $TESTTMP/extroot |
238 $ cat > $TESTTMP/extroot/bar.py <<EOF |
245 $ cat > $TESTTMP/extroot/bar.py <<NO_CHECK_EOF |
239 > s = b'this is extroot.bar' |
246 > s = b'this is extroot.bar' |
240 > EOF |
247 > NO_CHECK_EOF |
241 $ mkdir $TESTTMP/extroot/sub1 |
248 $ mkdir $TESTTMP/extroot/sub1 |
242 $ cat > $TESTTMP/extroot/sub1/__init__.py <<EOF |
249 $ cat > $TESTTMP/extroot/sub1/__init__.py <<NO_CHECK_EOF |
243 > s = b'this is extroot.sub1.__init__' |
250 > s = b'this is extroot.sub1.__init__' |
244 > EOF |
251 > NO_CHECK_EOF |
245 $ cat > $TESTTMP/extroot/sub1/baz.py <<EOF |
252 $ cat > $TESTTMP/extroot/sub1/baz.py <<NO_CHECK_EOF |
246 > s = b'this is extroot.sub1.baz' |
253 > s = b'this is extroot.sub1.baz' |
247 > EOF |
254 > NO_CHECK_EOF |
248 $ cat > $TESTTMP/extroot/__init__.py <<EOF |
255 $ cat > $TESTTMP/extroot/__init__.py <<NO_CHECK_EOF |
249 > from __future__ import absolute_import |
256 > from __future__ import absolute_import |
250 > s = b'this is extroot.__init__' |
257 > s = b'this is extroot.__init__' |
251 > from . import foo |
258 > from . import foo |
252 > def extsetup(ui): |
259 > def extsetup(ui): |
253 > ui.write(b'(extroot) ', foo.func(), b'\n') |
260 > ui.write(b'(extroot) ', foo.func(), b'\n') |
254 > ui.flush() |
261 > ui.flush() |
255 > EOF |
262 > NO_CHECK_EOF |
256 |
263 |
257 $ cat > $TESTTMP/extroot/foo.py <<EOF |
264 $ cat > $TESTTMP/extroot/foo.py <<NO_CHECK_EOF |
258 > # test absolute import |
265 > # test absolute import |
259 > buf = [] |
266 > buf = [] |
260 > def func(): |
267 > def func(): |
261 > # "not locals" case |
268 > # "not locals" case |
262 > import extroot.bar |
269 > import extroot.bar |
336 $ mkdir -p $TESTTMP/extlibroot/lsub1/lsub2 |
343 $ mkdir -p $TESTTMP/extlibroot/lsub1/lsub2 |
337 $ touch $TESTTMP/extlibroot/__init__.py |
344 $ touch $TESTTMP/extlibroot/__init__.py |
338 $ touch $TESTTMP/extlibroot/lsub1/__init__.py |
345 $ touch $TESTTMP/extlibroot/lsub1/__init__.py |
339 $ touch $TESTTMP/extlibroot/lsub1/lsub2/__init__.py |
346 $ touch $TESTTMP/extlibroot/lsub1/lsub2/__init__.py |
340 |
347 |
341 $ cat > $TESTTMP/extlibroot/lsub1/lsub2/called.py <<EOF |
348 $ cat > $TESTTMP/extlibroot/lsub1/lsub2/called.py <<NO_CHECK_EOF |
342 > def func(): |
349 > def func(): |
343 > return b"this is extlibroot.lsub1.lsub2.called.func()" |
350 > return b"this is extlibroot.lsub1.lsub2.called.func()" |
344 > EOF |
351 > NO_CHECK_EOF |
345 $ cat > $TESTTMP/extlibroot/lsub1/lsub2/unused.py <<EOF |
352 $ cat > $TESTTMP/extlibroot/lsub1/lsub2/unused.py <<NO_CHECK_EOF |
346 > raise Exception("extlibroot.lsub1.lsub2.unused is loaded unintentionally") |
353 > raise Exception("extlibroot.lsub1.lsub2.unused is loaded unintentionally") |
347 > EOF |
354 > NO_CHECK_EOF |
348 $ cat > $TESTTMP/extlibroot/lsub1/lsub2/used.py <<EOF |
355 $ cat > $TESTTMP/extlibroot/lsub1/lsub2/used.py <<NO_CHECK_EOF |
349 > detail = b"this is extlibroot.lsub1.lsub2.used" |
356 > detail = b"this is extlibroot.lsub1.lsub2.used" |
350 > EOF |
357 > NO_CHECK_EOF |
351 |
358 |
352 Setup sub-package of "external library", which causes instantiation of |
359 Setup sub-package of "external library", which causes instantiation of |
353 demandmod in "recurse down the module chain" code path. Relative |
360 demandmod in "recurse down the module chain" code path. Relative |
354 importing with "absolute_import" feature isn't tested, because "level |
361 importing with "absolute_import" feature isn't tested, because "level |
355 >=1 " doesn't cause instantiation of demandmod. |
362 >=1 " doesn't cause instantiation of demandmod. |
356 |
363 |
357 $ mkdir -p $TESTTMP/extlibroot/recursedown/abs |
364 $ mkdir -p $TESTTMP/extlibroot/recursedown/abs |
358 $ cat > $TESTTMP/extlibroot/recursedown/abs/used.py <<EOF |
365 $ cat > $TESTTMP/extlibroot/recursedown/abs/used.py <<NO_CHECK_EOF |
359 > detail = b"this is extlibroot.recursedown.abs.used" |
366 > detail = b"this is extlibroot.recursedown.abs.used" |
360 > EOF |
367 > NO_CHECK_EOF |
361 $ cat > $TESTTMP/extlibroot/recursedown/abs/__init__.py <<EOF |
368 $ cat > $TESTTMP/extlibroot/recursedown/abs/__init__.py <<NO_CHECK_EOF |
362 > from __future__ import absolute_import |
369 > from __future__ import absolute_import |
363 > from extlibroot.recursedown.abs.used import detail |
370 > from extlibroot.recursedown.abs.used import detail |
364 > EOF |
371 > NO_CHECK_EOF |
365 |
372 |
366 $ mkdir -p $TESTTMP/extlibroot/recursedown/legacy |
373 $ mkdir -p $TESTTMP/extlibroot/recursedown/legacy |
367 $ cat > $TESTTMP/extlibroot/recursedown/legacy/used.py <<EOF |
374 $ cat > $TESTTMP/extlibroot/recursedown/legacy/used.py <<NO_CHECK_EOF |
368 > detail = b"this is extlibroot.recursedown.legacy.used" |
375 > detail = b"this is extlibroot.recursedown.legacy.used" |
369 > EOF |
376 > NO_CHECK_EOF |
370 $ cat > $TESTTMP/extlibroot/recursedown/legacy/__init__.py <<EOF |
377 $ cat > $TESTTMP/extlibroot/recursedown/legacy/__init__.py <<NO_CHECK_EOF |
371 > # legacy style (level == -1) import |
378 > # legacy style (level == -1) import |
372 > from extlibroot.recursedown.legacy.used import detail |
379 > from extlibroot.recursedown.legacy.used import detail |
373 > EOF |
380 > NO_CHECK_EOF |
374 |
381 |
375 $ cat > $TESTTMP/extlibroot/recursedown/__init__.py <<EOF |
382 $ cat > $TESTTMP/extlibroot/recursedown/__init__.py <<NO_CHECK_EOF |
376 > from __future__ import absolute_import |
383 > from __future__ import absolute_import |
377 > from extlibroot.recursedown.abs import detail as absdetail |
384 > from extlibroot.recursedown.abs import detail as absdetail |
378 > from .legacy import detail as legacydetail |
385 > from .legacy import detail as legacydetail |
379 > EOF |
386 > NO_CHECK_EOF |
380 |
387 |
381 Setup package that re-exports an attribute of its submodule as the same |
388 Setup package that re-exports an attribute of its submodule as the same |
382 name. This leaves 'shadowing.used' pointing to 'used.detail', but still |
389 name. This leaves 'shadowing.used' pointing to 'used.detail', but still |
383 the submodule 'used' should be somehow accessible. (issue5617) |
390 the submodule 'used' should be somehow accessible. (issue5617) |
384 |
391 |
385 $ mkdir -p $TESTTMP/extlibroot/shadowing |
392 $ mkdir -p $TESTTMP/extlibroot/shadowing |
386 $ cat > $TESTTMP/extlibroot/shadowing/used.py <<EOF |
393 $ cat > $TESTTMP/extlibroot/shadowing/used.py <<NO_CHECK_EOF |
387 > detail = b"this is extlibroot.shadowing.used" |
394 > detail = b"this is extlibroot.shadowing.used" |
388 > EOF |
395 > NO_CHECK_EOF |
389 $ cat > $TESTTMP/extlibroot/shadowing/proxied.py <<EOF |
396 $ cat > $TESTTMP/extlibroot/shadowing/proxied.py <<NO_CHECK_EOF |
390 > from __future__ import absolute_import |
397 > from __future__ import absolute_import |
391 > from extlibroot.shadowing.used import detail |
398 > from extlibroot.shadowing.used import detail |
392 > EOF |
399 > NO_CHECK_EOF |
393 $ cat > $TESTTMP/extlibroot/shadowing/__init__.py <<EOF |
400 $ cat > $TESTTMP/extlibroot/shadowing/__init__.py <<NO_CHECK_EOF |
394 > from __future__ import absolute_import |
401 > from __future__ import absolute_import |
395 > from .used import detail as used |
402 > from .used import detail as used |
396 > EOF |
403 > NO_CHECK_EOF |
397 |
404 |
398 Setup extension local modules to be imported with "absolute_import" |
405 Setup extension local modules to be imported with "absolute_import" |
399 feature. |
406 feature. |
400 |
407 |
401 $ mkdir -p $TESTTMP/absextroot/xsub1/xsub2 |
408 $ mkdir -p $TESTTMP/absextroot/xsub1/xsub2 |
402 $ touch $TESTTMP/absextroot/xsub1/__init__.py |
409 $ touch $TESTTMP/absextroot/xsub1/__init__.py |
403 $ touch $TESTTMP/absextroot/xsub1/xsub2/__init__.py |
410 $ touch $TESTTMP/absextroot/xsub1/xsub2/__init__.py |
404 |
411 |
405 $ cat > $TESTTMP/absextroot/xsub1/xsub2/called.py <<EOF |
412 $ cat > $TESTTMP/absextroot/xsub1/xsub2/called.py <<NO_CHECK_EOF |
406 > def func(): |
413 > def func(): |
407 > return b"this is absextroot.xsub1.xsub2.called.func()" |
414 > return b"this is absextroot.xsub1.xsub2.called.func()" |
408 > EOF |
415 > NO_CHECK_EOF |
409 $ cat > $TESTTMP/absextroot/xsub1/xsub2/unused.py <<EOF |
416 $ cat > $TESTTMP/absextroot/xsub1/xsub2/unused.py <<NO_CHECK_EOF |
410 > raise Exception("absextroot.xsub1.xsub2.unused is loaded unintentionally") |
417 > raise Exception("absextroot.xsub1.xsub2.unused is loaded unintentionally") |
411 > EOF |
418 > NO_CHECK_EOF |
412 $ cat > $TESTTMP/absextroot/xsub1/xsub2/used.py <<EOF |
419 $ cat > $TESTTMP/absextroot/xsub1/xsub2/used.py <<NO_CHECK_EOF |
413 > detail = b"this is absextroot.xsub1.xsub2.used" |
420 > detail = b"this is absextroot.xsub1.xsub2.used" |
414 > EOF |
421 > NO_CHECK_EOF |
415 |
422 |
416 Setup extension local modules to examine whether demand importing |
423 Setup extension local modules to examine whether demand importing |
417 works as expected in "level > 1" case. |
424 works as expected in "level > 1" case. |
418 |
425 |
419 $ cat > $TESTTMP/absextroot/relimportee.py <<EOF |
426 $ cat > $TESTTMP/absextroot/relimportee.py <<NO_CHECK_EOF |
420 > detail = b"this is absextroot.relimportee" |
427 > detail = b"this is absextroot.relimportee" |
421 > EOF |
428 > NO_CHECK_EOF |
422 $ cat > $TESTTMP/absextroot/xsub1/xsub2/relimporter.py <<EOF |
429 $ cat > $TESTTMP/absextroot/xsub1/xsub2/relimporter.py <<NO_CHECK_EOF |
423 > from __future__ import absolute_import |
430 > from __future__ import absolute_import |
424 > from mercurial import pycompat |
431 > from mercurial import pycompat |
425 > from ... import relimportee |
432 > from ... import relimportee |
426 > detail = b"this relimporter imports %r" % ( |
433 > detail = b"this relimporter imports %r" % ( |
427 > pycompat.bytestr(relimportee.detail)) |
434 > pycompat.bytestr(relimportee.detail)) |
428 > EOF |
435 > NO_CHECK_EOF |
429 |
436 |
430 Setup modules, which actually import extension local modules at |
437 Setup modules, which actually import extension local modules at |
431 runtime. |
438 runtime. |
432 |
439 |
433 $ cat > $TESTTMP/absextroot/absolute.py << EOF |
440 $ cat > $TESTTMP/absextroot/absolute.py << NO_CHECK_EOF |
434 > from __future__ import absolute_import |
441 > from __future__ import absolute_import |
435 > |
442 > |
436 > # import extension local modules absolutely (level = 0) |
443 > # import extension local modules absolutely (level = 0) |
437 > from absextroot.xsub1.xsub2 import used, unused |
444 > from absextroot.xsub1.xsub2 import used, unused |
438 > from absextroot.xsub1.xsub2.called import func |
445 > from absextroot.xsub1.xsub2.called import func |