Suggested change to dolfinx python package (wheel.license-files)

Hello. I have been building dolfinx 0.8.x for some time, and I would like to share that my installation works better when python/pyproject.toml has this:

cp -av "${_base_dir}"/{COPYING*,README.md} "${_base_dir}"/python
from 59bcec35da
diff --git a/python/pyproject.toml b/python/pyproject.toml
index 68fcb70d43..cf0a8d4da4 100644
--- a/python/pyproject.toml
+++ b/python/pyproject.toml
@@ -15,9 +15,9 @@ build-backend = "scikit_build_core.build"
 name = "fenics-dolfinx"
 version = "0.8.0.dev0"
 description = "DOLFINx Python interface"
-readme = "../README.md"
+readme = "README.md"
 requires-python = ">=3.9.0"
-license = { file = "../COPYING.LESSER" }
+license = { file = "COPYING.LESSER" }
 authors = [
       { email = "fenics-steering-council@googlegroups.com" },
       { name = "FEniCS Steering Council" },
@@ -52,7 +52,7 @@ ci = [
 wheel.packages = ["dolfinx"]
 sdist.exclude = ["*.cpp"]
 cmake.build-type = "Release"
-wheel.license-files = ["../COPYING*"]
+wheel.license-files = ["COPYING*"]
 
 [tool.pytest]
 junit_family = "xunit2"

I do not have accounts with GitHub (Microsoft). If you want to use the code above, I don’t need attribution. If it’s not useful, that’s ok : ) . Thanks for FEniCS.

What does that mean?

The fear I have with what you propose is that the typical user will forget to run the cp instruction, and thus the installation will not work.

I’ll get the specific error message, but it happens during the installation with a PKGBUILD (pacman-based distro e.g. Parabola, Artix or Arch). The package is built and installed without pip, but with python build and install. In this type of distribution, that is the standard way.

Right now, I don’t have access to the code (my dog ate my Internet… can’t reach the repo). Trying to remember correctly, it may be hatchling (?) which tries to create the directory containing the target files. In this case, the file is ../COPYING. It fails, because the parent folder ../ already exists, and cannot be created again.

I agree: the user should not need to copy the file. It was mostly to show how I go around it.

It’s normal to have some patches for packaging, we have them for Debian/Ubuntu too. Some of them, like the one you propose, are not really meant to be integrated upstream.

1 Like

For completeness, here is the error message:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib/python3.11/site-packages/installer/__main__.py", line 98, in <module>
    _main(sys.argv[1:], "python -m installer")
  File "/usr/lib/python3.11/site-packages/installer/__main__.py", line 94, in _main
    installer.install(source, destination, {})
  File "/usr/lib/python3.11/site-packages/installer/_core.py", line 109, in install
    record = destination.write_file(
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/installer/destinations.py", line 207, in write_file
    return self.write_to_fs(scheme, path_, stream, is_executable)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/installer/destinations.py", line 171, in write_to_fs
    os.makedirs(parent_folder)
  File "<frozen os>", line 225, in makedirs
FileExistsError: [Errno 17] File exists: '/build-dir/dolfinx/pkg/dolfinx-git/usr/lib/python3.11/site-packages/fenics_dolfinx-0.8.0.dev0.dist-info/licenses/..'

The directories may be a little bit scrambled (they are automatically set by the building environment, and I am trying to reproduce them manually), but hopefully, this shows the logic

  # build
  cd /build-dir/dolfinx/src
  _base=dolfinx
  build_dir="${_base}"/cpp/build
  CONFOPTS=(
    -S "${_base}"/cpp
    -B "${build_dir}"
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DBUILD_SHARED_LIBS=TRUE
  )
  cmake ${CONFOPTS[@]}

  cmake --build "${build_dir}" --target all --parallel

  # package
  pkgdir=/build-dir/dolfinx/pkg/dolfinx-git
  DESTDIR="${pkgdir}" cmake --install "${_base}"/cpp/build

  cd /build-dir/dolfinx/src/${_base}/python
  export CMAKE_PREFIX_PATH="${pkgdir}"/usr CMAKE_BUILD_PARALLEL_LEVEL=6
  python -m build --wheel --no-isolation --skip-dependency-check
  PYTHONPYCACHEPREFIX="${PWD}/.cache/cpython/" \
                     python -m installer --destdir="$pkgdir" dist/*.whl