Python 3 issue

Russel Winder <[email protected]>
Newsgroups gmane.comp.programming.tools.scons.devel
Message-ID <[email protected]>
Python 3 changed the way imports worked, absolute imports became the
norm. However relative imports were retain via extra syntax. This has,
I believe been backported to Python 2.7.

The summary of the situation is that to enable tools as packages as
well as tools as modules, you have to use relative imports of generate
and exists in __init__.py. This used to work fine. A very minor change
of syntax means it all still works on Python 2. However on Python 3
something weird happens. This is a SCons thing, because if you do the
equivalent it pure Python is works fine with either 2 or 3.

So given the attached project:

> python /home/users/russel/Repositories/Mercurial/Forks/SCons/src/script/scons.py
scons: Reading SConscript files ...
__init__ loaded.
generate called.
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
546 lavaine:~/Progs/OddsByLanguage/SCons/RelativeImports 
|> python3 /home/users/russel/Repositories/Mercurial/Forks/SCons/src/script/scons.py
scons: Reading SConscript files ...
SystemError: Parent module 'relative' not loaded, cannot perform relative import:
  File "/home/users/russel/Progs/OddsByLanguage/SCons/RelativeImports/SConstruct", line 1:
    env = Environment(tools=['relative'])
  File "/home/users/russel/Repositories/Mercurial/Forks/SCons/src/engine/SCons/Environment.py", line 982:
    apply_tools(self, tools, toolpath)
  File "/home/users/russel/Repositories/Mercurial/Forks/SCons/src/engine/SCons/Environment.py", line 107:
    env.Tool(tool)
  File "/home/users/russel/Repositories/Mercurial/Forks/SCons/src/engine/SCons/Environment.py", line 1788:
    tool = SCons.Tool.Tool(tool, toolpath, **kw)
  File "/home/users/russel/Repositories/Mercurial/Forks/SCons/src/engine/SCons/Tool/__init__.py", line 115:
    module = self._tool_module()
  File "/home/users/russel/Repositories/Mercurial/Forks/SCons/src/engine/SCons/Tool/__init__.py", line 228:
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 697:
    
  File "<frozen importlib._bootstrap>", line 222:
    
  File "/home/users/russel/Progs/OddsByLanguage/SCons/RelativeImports/site_scons/site_tools/relative/__init__.py", line 3:
    from .thingy import generate, exists



-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:[email protected]
41 Buckmaster Road    m: +44 7770 465 077   xmpp: [email protected]
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

_______________________________________________
Scons-dev mailing list
[email protected]
https://pairlist2.pair.net/mailman/listinfo/scons-dev
problem_project.zip (application/zip, 1.3 KB) - not displayed
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEETwDs1X+Beyaiaer41L3V0s7Np7gFAllNIigACgkQ1L3V0s7N
p7i4GQ//ar78ZKs/mW72t1+aRw30Y+FN+ILycs73TkWaIRbSJmWgjb/kM2pw+B3Z
mzej26nhXKM9zV4ShqWE21JUQe7rosGl3o7eCFP0iJlKXCHvr+sPvN1zIop3RoXm
EbqZ9zt/Ddb/a885SO9uuW2Hf2xUJf59BrfxCK/NtxAPzIE8kq+uFaRoqw9nglO5
JkvNnUlw1T64RlSA3TjM2CBbBZywdQfmZQKq6jXDm4ljIASlBNBTEqpurGohCmgD
jWpQwNuHqy6xOIpRYw0hRg15A4N9oYkfQ+JQ9dgjd187jrZfjtJknKKNRKgIznvP
BXD2HnURVCC1DagXOCP4j37AiCCJZkEUj3u6VkKc1j/uOYR86VbkU6trMxxu+U6G
eILB/VXvQ5eZAK0lRzl3EWmRi76c/12pyWDwCJJpbDKY7TMJWCd+31D5exycdVLr
Wi13Ew4nftElRw/Ro4KN8tf+kGyezQntqAukTg5KFmvmxYCc3WhjFSDjfq8lCRcX
v60kEkoAj8u01lAc+1E0TzWiotFJnii5nbpQ5ylC+Xs9zbxHvmB/PR+G8ihhIl4B
A22nPhOzLVo/DFVZ4InkKIpihbmpdcbGTLhwabDpmFgVkEM9t6DE6M5IJM6nyixS
jf7EJp9KquDC5GWLKEYaY58c/hhtvUhdyfeAKhS3XQhGsQyfq8s=
=HXah
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.