Repository: numpy/numpy

Issue:
1.16.2 build fails with python 3.6 on install stage
Running from numpy source directory.
/usr/lib64/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'define_macros'
  warnings.warn(msg)
Traceback (most recent call last):
  File "setup.py", line 415, in <module>
    setup_package()
  File "setup.py", line 407, in setup_package
    setup(**metadata)
  File "/builddir/build/BUILD/numpy-1.16.2/numpy/distutils/core.py", line 171, in setup
    return old_setup(**new_attr)
  File "/usr/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib64/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib64/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/builddir/build/BUILD/numpy-1.16.2/numpy/distutils/command/install.py", line 62, in run
    r = self.setuptools_run()
  File "/builddir/build/BUILD/numpy-1.16.2/numpy/distutils/command/install.py", line 36, in setuptools_run
    return distutils_install.run(self)
  File "/usr/lib64/python3.6/distutils/command/install.py", line 568, in run
    self.run_command(cmd_name)
  File "/usr/lib64/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib64/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/builddir/build/BUILD/numpy-1.16.2/numpy/distutils/command/install_data.py", line 19, in run
    self.run_command('install_clib')
  File "/usr/lib64/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib64/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/builddir/build/BUILD/numpy-1.16.2/numpy/distutils/command/install_clib.py", line 34, in run
    source = os.path.join(build_dir, name)
  File "/usr/lib64/python3.6/posixpath.py", line 80, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType



Discussion:
The same for 1.16.3
did you do `git clean -xfd` before building?
I have used the source from pip, so no git stuff is inside.
Are the sources different?
After debug  the installer I found, the source of the problem and and hot fix for it.
But this fix will only work on Centos.
In numpy/distutils/command/install_clib.py build_dir will be None. I don't know why.
My fix is that:
[numpy-patch.txt](https://github.com/numpy/numpy/files/3191194/numpy-patch.txt)
Now the installer will work, but the tests fails, because some files where not installed.
This have I fixed with:

> for missing in __multiarray_api.h _numpyconfig.h
> do
>         install build/src.linux-%{_target_cpu}-?.?/numpy/core/include/numpy/${missing} %{buildroot}%{python3_sitearch}/%{pypi_name}/core/include/numpy
> done
> mkdir -p %{buildroot}%{python3_sitearch}/%{pypi_name}/core/lib/npy-pkg-config
> for ini in mlib.ini npymath.ini
> do
>         install  build/src.linux-%{_target_cpu}-?.?/numpy/core/lib/npy-pkg-config/${ini} %{buildroot}%{python3_sitearch}/%{pypi_name}/core/lib/npy-pkg-config/
> done

What command are you running? What version of distutils/setuptools do you have? Those files should be generated when building NumPy. 
I use the versions of distutils/setuptools that comes with Python from CentOS.
Because it are in the core package I can't tell you the version.
For the build:
/usr/bin/python3.6 setup.py build '--executable=/usr/bin/python3.6 -s'
For the install:
/usr/bin/python3.6 setup.py install -O1 --skip-build --root /builddir/build/BUILDROOT/python-numpy-1.16.3-1.el7.x86_64

Resolving patch:
diff --git a/numpy/distutils/command/install_clib.py b/numpy/distutils/command/install_clib.py
--- a/numpy/distutils/command/install_clib.py
+++ b/numpy/distutils/command/install_clib.py
@@ -19,6 +19,9 @@ def finalize_options(self):
 
     def run (self):
         build_clib_cmd = get_cmd("build_clib")
+        if not build_clib_cmd.build_clib:
+            # can happen if the user specified `--skip-build`
+            build_clib_cmd.finalize_options()
         build_dir = build_clib_cmd.build_clib
 
         # We need the compiler to get the library name -> filename association


Test patch: