[PATCH] D68779: [LNT][NFC] Fix global import in function

Przemyslaw Wirkus via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 07:06:09 PST 2019


PrzemekWirkus added inline comments.


================
Comment at: lnt/lnttool/admin.py:8-13
+    yaml = __import__('yaml', globals(), locals())
+    sys = __import__('sys', globals(), locals())
+    requests = __import__('requests', globals(), locals())
+    json = __import__('json', globals(), locals())
+    os = __import__('os', globals(), locals())
+    httplib = __import__('httplib', globals(), locals())
----------------
thopre wrote:
> PrzemekWirkus wrote:
> > PrzemekWirkus wrote:
> > > thopre wrote:
> > > > PrzemekWirkus wrote:
> > > > > PrzemekWirkus wrote:
> > > > > > Thomas, 
> > > > > > why are you not using importlib.import_module instead of __import__ ?
> > > > > > Any other reason except for the Python 2 backward compatibility ?
> > > > > s/import/__import__/
> > > > The version available in Python 2.7 does not seem to return a value, how to bind the loaded modules to the global variables then?
> > > Python 2.7.15+ (default, Oct  7 2019, 17:39:04)
> > > [GCC 7.4.0] on linux2
> > > Type "help", "copyright", "credits" or "license" for more information.
> > > >>> import importlib
> > > >>> x = importlib.import_module('json')
> > > >>> print x
> > > <module 'json' from '/usr/lib/python2.7/json/__init__.pyc'>
> > > 
> > > # Silly global assign:
> > > >>> global json
> > > >>> json = x
> > > >>> dir(json)
> > > ['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_default_decoder', '_default_encoder', 'decoder', 'dump', 'dumps', 'encoder', 'load', 'loads', 'scanner']
> > > 
> > > https://docs.python.org/2/library/importlib.html#importlib.import_module
> > > 
> > > "...
> > > The specified module will be inserted into sys.modules and returned."
> > > 
> > This is just nitpicking from my side! :)
> Ah, I missed the "and returned". Thanks for pointing that out. It seems that importlib is only available in Python 3.1 onwards. Are you aware of any Linux distribution (past or present, e.g. RHELs) that ship with Python 3.0?
No one uses Python <3.4.3

```bash
$ docker run --rm ubuntu:14.04 python3 --version
Python 3.4.3
```

```bash
$ docker run --rm -it centos:6
$ yum update
$ yum install centos-release-scl
$ rpm -qa | grep python3
rh-python35-python-setuptools-18.0.1-2.el6.noarch
rh-python35-python-3.5.1-13.el6.x86_64
rh-python35-python-devel-3.5.1-13.el6.x86_64
rh-python35-2.0-2.el6.x86_64
rh-python35-runtime-2.0-2.el6.x86_64
rh-python35-python-pip-7.1.0-2.el6.noarch
rh-python35-python-libs-3.5.1-13.el6.x86_64
rh-python35-python-virtualenv-13.1.2-2.el6.noarch
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68779/new/

https://reviews.llvm.org/D68779





More information about the llvm-commits mailing list