Repository: python-pillow/Pillow

Issue:
Pillow 5.4.0 cannot be installed on Termux
### What did you do?
> pip3 install --upgrade Pillow

### What did you expect to happen?
Pillow is upgraded to version 5.4.0

### What actually happened?
> running build_ext
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
>   File "/data/data/com.termux/files/usr/tmp/pip-install-XXXXXXXX/pillow/setup.py", line 800, in <module>
>     zip_safe=not (debug_build() or PLATFORM_MINGW), )
>   File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/setuptools/__init__.py", line 143, in setup
>     return distutils.core.setup(**attrs)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/core.py", line 148, in setup
>     dist.run_commands()
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/dist.py", line 966, in run_commands
>     self.run_command(cmd)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
>     cmd_obj.run()
>   File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/setuptools/command/install.py", line 61, in run
>     return orig.install.run(self)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/command/install.py", line 545, in run
>     self.run_command('build')
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
>     self.distribution.run_command(command)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
>     cmd_obj.run()
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/command/build.py", line 135, in run
>     self.run_command(cmd_name)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
>     self.distribution.run_command(command)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
>     cmd_obj.run()
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/command/build_ext.py", line 339, in run
>     self.build_extensions()
>   File "/data/data/com.termux/files/usr/tmp/pip-install-XXXXXXXX/pillow/setup.py", line 416, in build_extensions
>     for dirname in _find_library_dirs_ldconfig():
> TypeError: 'NoneType' object is not iterable

### What are your OS, Python and Pillow versions?

* OS:  Termux
* Python: 3.7.2
* Pillow: 5.4.0

I think the error happens in the function __find_library_dirs_ldconfig_, where the executable "/sbin/ldconfig" is called. This executable  does not exist on Termux, making the function return None.

```python
[...]
        args = ['/sbin/ldconfig', '-p']
[...]
    null = open(os.devnull, 'wb')
    try:
        with null:
            p = subprocess.Popen(args,
                                 stderr=null,
                                 stdout=subprocess.PIPE,
                                 env=env)
    except OSError:  # E.g. command not found
        return None
[...]
```
Previous versions can be installed without a problem (as long as the necessary dev packages are installed).
Pillow 5.4.0 cannot be installed on Termux
### What did you do?
> pip3 install --upgrade Pillow

### What did you expect to happen?
Pillow is upgraded to version 5.4.0

### What actually happened?
> running build_ext
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
>   File "/data/data/com.termux/files/usr/tmp/pip-install-XXXXXXXX/pillow/setup.py", line 800, in <module>
>     zip_safe=not (debug_build() or PLATFORM_MINGW), )
>   File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/setuptools/__init__.py", line 143, in setup
>     return distutils.core.setup(**attrs)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/core.py", line 148, in setup
>     dist.run_commands()
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/dist.py", line 966, in run_commands
>     self.run_command(cmd)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
>     cmd_obj.run()
>   File "/data/data/com.termux/files/usr/lib/python3.7/site-packages/setuptools/command/install.py", line 61, in run
>     return orig.install.run(self)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/command/install.py", line 545, in run
>     self.run_command('build')
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
>     self.distribution.run_command(command)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
>     cmd_obj.run()
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/command/build.py", line 135, in run
>     self.run_command(cmd_name)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
>     self.distribution.run_command(command)
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
>     cmd_obj.run()
>   File "/data/data/com.termux/files/usr/lib/python3.7/distutils/command/build_ext.py", line 339, in run
>     self.build_extensions()
>   File "/data/data/com.termux/files/usr/tmp/pip-install-XXXXXXXX/pillow/setup.py", line 416, in build_extensions
>     for dirname in _find_library_dirs_ldconfig():
> TypeError: 'NoneType' object is not iterable

### What are your OS, Python and Pillow versions?

* OS:  Termux
* Python: 3.7.2
* Pillow: 5.4.0

I think the error happens in the function __find_library_dirs_ldconfig_, where the executable "/sbin/ldconfig" is called. This executable  does not exist on Termux, making the function return None.

```python
[...]
        args = ['/sbin/ldconfig', '-p']
[...]
    null = open(os.devnull, 'wb')
    try:
        with null:
            p = subprocess.Popen(args,
                                 stderr=null,
                                 stdout=subprocess.PIPE,
                                 env=env)
    except OSError:  # E.g. command not found
        return None
[...]
```
Previous versions can be installed without a problem (as long as the necessary dev packages are installed).


Discussion:
 _find_library_dirs_ldconfig was added in https://github.com/python-pillow/Pillow/pull/3245.

@pslacerda, please could you check it?
@valpogus your development environment should be very funny: Termux on Android on Linux with some hardware virtualization!

@hugovk I'm looking it right now and ping you back soon.
`_find_library_dirs_ldconfig` should return a empty list instead of `None`, so it can go through Termux/`ANDROID_ROOT` code. Or return a generator instead.

I'm worried about  `/include` for Termux (the comments talk about)  that I don't see even before the introduction of `_find_library_dirs_ldconfig`. Maybe I missed something.




 _find_library_dirs_ldconfig was added in https://github.com/python-pillow/Pillow/pull/3245.

@pslacerda, please could you check it?
@valpogus your development environment should be very funny: Termux on Android on Linux with some hardware virtualization!

@hugovk I'm looking it right now and ping you back soon.
`_find_library_dirs_ldconfig` should return a empty list instead of `None`, so it can go through Termux/`ANDROID_ROOT` code. Or return a generator instead.

I'm worried about  `/include` for Termux (the comments talk about)  that I don't see even before the introduction of `_find_library_dirs_ldconfig`. Maybe I missed something.





Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -111,7 +111,7 @@ def _find_library_dirs_ldconfig():
                                  stdout=subprocess.PIPE,
                                  env=env)
     except OSError:  # E.g. command not found
-        return None
+        return []
     [data, _] = p.communicate()
     if isinstance(data, bytes):
         data = data.decode()


Test patch: