user171780
user171780

Reputation: 3115

How to create the installation files for this package?

I am working on the CSXCAD python module. The current procedure for installing it is to run:

python setup.py build_ext -I ~/opt/openEMS/include -L ~/opt/openEMS/lib -R ~/opt/openEMS/lib
python setup.py install

I want to create the pyproject.toml and whatever else is needed for it to be able to be installed simply with pip install .. I created the following files:

pyproject.toml

[build-system]
requires = ["setuptools","cython","numpy"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
py-modules = ["CSXCAD"]

[project]
name = "CSXCAD"
version = "0.0.1"
authors = [
  { name="Example Author", email="[email protected]" },
]
description = "A small example package"
readme = "README.md"
requires-python = ">=3.8"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
]

[tool.setuptools.cmdclass]
build_py = "_custom_build.build_py"

_custom_build.py

from setuptools import Extension
from setuptools.command.build_py import build_py as _build_py
from pathlib import Path

class build_py(_build_py):
    def run(self):
        self.run_command("build_ext")
        return super().run()

    def initialize_options(self):
        super().initialize_options()
        if self.distribution.ext_modules == None:
            self.distribution.ext_modules = []

        self.distribution.ext_modules.append(
            Extension(
                "*", 
                [Path(__file__).parent/"CSXCAD/*.pyx"],
                language = "c++",
                libraries = ['CSXCAD'],
            ),
        )

It fails like this:

$ pip install .
Processing /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: CSXCAD
  Building wheel for CSXCAD (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for CSXCAD (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [35 lines of output]
      running bdist_wheel
      running build
      running build_py
      running build_ext
      /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSPrimitives.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)
      /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSProperties.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)
      /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSRectGrid.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)
      /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSTransform.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)
      /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSXCAD.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)
      /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/ParameterObjects.pxd
        tree = Parsing.p_module(s, pxd, full_module_name)
      Compiling /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSPrimitives.pyx because it depends on /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Includes/libc/string.pxd.
      Compiling /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSProperties.pyx because it depends on /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Includes/libc/string.pxd.
      Compiling /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSRectGrid.pyx because it depends on /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Includes/libc/string.pxd.
      Compiling /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSTransform.pyx because it depends on /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Includes/libc/string.pxd.
      Compiling /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSXCAD.pyx because it depends on /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Includes/libc/string.pxd.
      Compiling /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/ParameterObjects.pyx because it depends on /tmp/pip-build-env-mx4miiwt/overlay/lib64/python3.12/site-packages/Cython/Includes/libc/string.pxd.
      [1/6] Cythonizing /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSPrimitives.pyx
      [2/6] Cythonizing /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSProperties.pyx
      [3/6] Cythonizing /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSRectGrid.pyx
      [4/6] Cythonizing /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSTransform.pyx
      [5/6] Cythonizing /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSXCAD.pyx
      [6/6] Cythonizing /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/ParameterObjects.pyx
      building '*' extension
      g++ -fno-strict-overflow -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -fexceptions -fcf-protection -fexceptions -fcf-protection -fexceptions -fcf-protection -fPIC -I/home/crazyscientist/opt/openEMS/openEMS_venv/include -I/usr/include/python3.12 -c /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSPrimitives.cpp -o build/temp.linux-x86_64-cpython-312/home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSPrimitives.o
      /home/crazyscientist/opt/openEMS/openEMS-Project/CSXCAD/python/CSXCAD/CSPrimitives.cpp:1257:10: fatal error: CSXCAD/ParameterObjects.h: No such file or directory
       1257 | #include "CSXCAD/ParameterObjects.h"
            |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/g++' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for CSXCAD
Failed to build CSXCAD
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (CSXCAD)

and I guess it is because the -I ~/opt/openEMS/include -L ~/opt/openEMS/lib -R ~/opt/openEMS/lib options are not used, but I don't know where to put them.

Upvotes: 0

Views: 54

Answers (0)

Related Questions