https://github.com/d-krupke/skbuild-conan

An extension for scikit-build to add C++-dependencies as easily as Python dependencies via conan.

https://github.com/d-krupke/skbuild-conan

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 2 committers (50.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.9%) to scientific vocabulary

Keywords

conan pybind11 scikit-build
Last synced: 5 months ago · JSON representation

Repository

An extension for scikit-build to add C++-dependencies as easily as Python dependencies via conan.

Basic Info
  • Host: GitHub
  • Owner: d-krupke
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 125 KB
Statistics
  • Stars: 6
  • Watchers: 2
  • Forks: 5
  • Open Issues: 4
  • Releases: 0
Topics
conan pybind11 scikit-build
Created almost 3 years ago · Last pushed 8 months ago
Metadata Files
Readme License

README.md

skbuild-conan: A conan extension for scikit-build

PyPI License

PyBind11 and scitkit-build enable us to easily write native C++-modules for Python. However, you get problems if your C++-code has dependencies. This extension tries to make defining C++-dependencies as easy as defining the Python-dependencies. This way you can easily add any C++-library that has a conan recipe to your Python-project.

This project originates from our need to use complex C++-libraries in Python projects and missing any nice option to include C++-dependencies. For a few projects, we wrote individual code to fetch the dependencies or just added instructions on how to install them (which of course can scare pure Python users).

This project is currently just a nice interface to hacks we accumulated. We try to make it as universal and robust as possible as we rely on this for multiple projects, but we are working fast-paced and will quickly abandon this tool once there is something better.

We (TU Braunschweig, Algorithms Group) are not affiliated with scikit-build or conan.

Installation

For skbuild-conan to work, you need to have a full Python and C++ development environment. This means that you need to have a compiler installed and the Python development files. The Python development files are usually called python3-dev or python3-devel and the compiler is usually called gcc or clang. On most Linux distributions, these are installed by default.

You can simply add "skbuild_conan", to requires=[...] in pyproject.toml. E.g. The pyproject.toml could look like this

toml [build-system] requires = [ "conan>=2.0.0", "setuptools", "scikit-build>=0.17.3", "skbuild-conan", "cmake>=3.23", "ninja", ] build-backend = "setuptools.build_meta"

If you want to use for example setup.py build, you need to install skbuild_conan to your environment. You can do so by pip install skbuild_conan.

Usage

The usage is very similar to scitkit-build (and setuptools). We just added a few additional arguments to setup().

See how to use scikit-build first, as this is just a small extension to it.

The added options are

  • conanfile: Path to the folder with the conanfile.[py|txt]. By default the root is assumed. The conanfile can be used to define the dependencies. Alternatively, you can also use conan_requirements to define the conan dependencies without a conanfile. This option is exclusive. If you define conan_requirements, this option is ignored.
  • conan_recipes: List of paths to further conan recipes. The conan package index is far from perfect, so often you need to build your own recipes. You don't always want to upload those, so this argument gives you the option to integrate local recipes. Just the path to the folder containing the conanfile.py.
  • conan_requirements: Instead of providing a conanfile, you can simply state the dependencies here. E.g. ["fmt/[>=10.0.0]"] to add fmt in version >=10.0.0.
  • conan_profile_settings: Overwrite conan profile settings. Sometimes necessary because of ABI-problems, etc.
  • wrapped_setup: The setup-method that is going to be wrapped. This would allow you to extend already extended setup functions. By default, it is the setup of skbuild, which extends the setup of setuptools.
  • conan_output_folder: The folder where conan will write the generated files. No real reason to change it unless the default creates conflicts with some other tool.
  • cmake_args: This is actually an argument of skbuild but we will extend it. It hands cmake custom arguments. We use it to tell cmake about the conan modules.
  • conan_profile: The name of the conan profile to use. By default, it is skbuild_conan_py. This profile is created automatically and should work for most cases. If you need to change it, you can do so by editing ~/.conan2/profiles/skbuild_conan_py.
  • conan_env: Environment variables that are used for the conan calls. By default it will override CC and CXX with empty strings. This is necessary to work around problems with anaconda, but it should not cause any problems with other setups. You could define CONAN_HOME to ./conan/cache to use a local cache and not install anything to the user space.

An example usage could be as follows

```python from skbuildconan import setup from setuptools import findpackages

setup( # https://scikit-build.readthedocs.io/en/latest/usage.html#setup-options name="simpleskbuildconanexample", version="0.1.1", packages=findpackages("src"), # Include all packages in ./src. packagedir={"": "src"}, # The root for our python package is in ./src. pythonrequires=">=3.7", # lowest python version supported. installrequires=[], # Python Dependencies conanrequirements=["fmt/[>=10.0.0]"], # C++ Dependencies cmakeminimumrequired_version="3.23", ) ```

See ./examples/simpleskbuildconan_example for a full example.

Examples

If you do not have any C++-dependencies, you can just use scikit-build which also provides a set of examples.

Simple Example with fmt

The example in ./examples/simpleskbuildconan_example provides a minimal example of how to use fmt in Python using PyBind11 and skbuildconan. fmt is a nice library for formatting strings and is used by many other libraries. Python, of course, comes with extensive inbuilt string formatting, thus, this example is not very useful. However, it is a good starting point to understand how to use skbuildconan with a simple external library.

Complex Example with CGAL: Using CGAL in Python

Sometimes, your dependencies are significantly more complex. For example, you may want to do some geometry processing and use CGAL. CGAL is a very complex library with many dependencies, but also the most powerful library for geometric operations and often the only choice for many problems. CGAL has a conan recipe, but it took a while until it received updates for conan2, such that we wrote our own recipe. In the meantime, the official recipe was updated, but for the sake of the example, we will use our own recipe. In case you are faced with the problem of an outdated conan recipe (or none at all), you can use the same trick.

See ./examples/cgalskbuildconan_example for an example of how to use CGAL via a custom conan recipe in Python using PyBind11 and skbuild_conan.

Note that there is also the cgalpy project by my friends at TAU (which I visited for a few months in 2022/2023), which is a nearly complete and efficient wrapper of CGAL. It may need some more documentation, but Efi put a lot of thought into efficiency and configurability.

Common problems

Feel free to copy these comments. Attribution is appreciated but not necessary.

ABI problems: Undefined symbole ...__cxx1112basic_stringIcSt11char_...

This problem should be automatically fixed. Please open an issue if you still encounter it.

See https://docs.conan.io/1/howtos/managegccabi.html for more details.

glibcxx problems:

If you get an error such as

ImportError: /home/krupke/anaconda3/envs/mo310/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /home/krupke/anaconda3/envs/mo310/lib/python3.10/site-packages/samplns/cds/_cds_bindings.cpython-310-x86_64-linux-gnu.so)

you are probably using conda (good!) but need to update glibcxx. Install the latest version by

sh conda install -c conda-forge libstdcxx-ng

In some cases, this still is not enough, especially if you are using a very up to date rolling-release distribution, such as Arch Linux, or if you installed libstdcxx-ng some time ago. This could lead to the system having a slightly newer version of glibcxx than conda. First try to upgrade libstdcxx-ng with

sh conda upgrade -c conda-forge --all

If this does not help, you can try to install g++ (caveat: Linux only, Mac OS needs clang) into your conda environment and use it to compile the package.

sh conda install -c conda-forge gxx_linux-64 # This should enforce a modern g++ version. conda install -c conda-forge cxx-compiler # This should make sure that the compiler is used.

Note that just the second command first may install an outdated g++ version (at least I observed that it installed gcc11 instead of gcc13, messing up my whole environment as this is too old). When compiling from source, you probably should delete the _skbuild-folder and do a proper uninstall of the previous installation first.

conan problems

If you encounter problems with conan, you can try to delete the conan profile and let it be recreated.

sh rm ~/.conan2/profiles/skbuild_conan_py

Maybe you can also just take a look at the file and see if conan detected your compiler correctly. A proper profile on Linux should for example look like this (different for other systems):

[settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=13 os=Linux

If the problem persists, you can try to delete the conan cache.

sh rm -rf ~/.conan2

fatal error: Python.h: No such file or directory

This is a rare problem with your Python installation. Make sure that you have the development files installed.

sudo apt-get install python3-dev # Ubuntu sudo yum install python3-devel # CentOS, RHEL sudo dnf install python3-devel # Fedora sudo zypper in python3-devel # OpenSUSE sudo apk add python3-dev # Alpine sudo apk add python3-dev # Cygwin

In case you have multiple Python versions installed, you may need to specify the Python version.

If you still encounter problems, please open an issue.

MetadataPathFinder.invalidate_caches() missing 1 required positional argument: 'cls'

A very odd bug that we encountered with a distribution of Python 3.12 was the following:

``` ... TypeError: MetadataPathFinder.invalidate_caches() missing 1 required positional argument: 'cls'

ERROR: MetadataPathFinder.invalidate_caches() missing 1 required positional argument: 'cls' ```

The reason for this was surprisingly a bug in the Python distribution of importlib itself. Someone forgot to add the @classmethod to the MetadataPathFinder. Updating the Python distribution, in this case in conda via conda update python solved the problem.

Contribution

We are happy about any contribution and also about reported issues. Sometimes it can take some time before we are able to take care of something, as we need to prioritize quite often.

Changelog

  • 1.3.0 The Debug/Release will propagate to the conan profile. (thanks to @xandox)
  • 1.2.0 Workaround for Windows and MSVC found by Ramin Kosfeld (TU Braunschweig).
  • 1.1.1 Fixing problem if the conan default profile has been renamed via environment variable.
  • 1.1.0 conan is now called directly. This is kind of hacky, but circumvents problems with conan not being in the path if only installed for build.
  • 1.0.0 Custom conan profile and workaround for anaconda problem.
  • 0.2.0 Improved logging.
  • 0.1.4 Fixing problem with paths that contain spaces. Switching back to manual versioning.
  • 0.1.3 Fixing bug if no settings are given.
  • 0.1.2 Moved workaround into setup to make it more explicit.
  • 0.1.1 First tested and apparently working version.

Owner

  • Name: Dominik Krupke
  • Login: d-krupke
  • Kind: user
  • Location: Germany
  • Company: TU Braunschweig

Postdoc at TU Braunschweig, IBR, Algorithms Group.

GitHub Events

Total
  • Create event: 1
  • Release event: 1
  • Issues event: 1
  • Watch event: 2
  • Issue comment event: 6
  • Push event: 6
  • Pull request event: 1
  • Fork event: 3
Last Year
  • Create event: 1
  • Release event: 1
  • Issues event: 1
  • Watch event: 2
  • Issue comment event: 6
  • Push event: 6
  • Pull request event: 1
  • Fork event: 3

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 56
  • Total Committers: 2
  • Avg Commits per committer: 28.0
  • Development Distribution Score (DDS): 0.25
Past Year
  • Commits: 5
  • Committers: 1
  • Avg Commits per committer: 5.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Dominik Krupke k****e@i****e 42
Dominik Krupke k****d@g****m 14
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: over 1 year ago

All Time
  • Total issues: 7
  • Total pull requests: 0
  • Average time to close issues: 13 days
  • Average time to close pull requests: N/A
  • Total issue authors: 2
  • Total pull request authors: 0
  • Average comments per issue: 0.86
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 2
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 2
  • Pull request authors: 0
  • Average comments per issue: 0.5
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • d-krupke (5)
  • xandox (1)
  • phillip-keldenich (1)
Pull Request Authors
Top Labels
Issue Labels
bug (3) enhancement (1) good first issue (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 1,106 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 7
  • Total maintainers: 1
pypi.org: skbuild-conan

An extension for scikit-build to add C++-dependencies as easily as Python dependencies via conan.

  • Homepage: https://github.com/d-krupke/skbuild-conan
  • Documentation: https://skbuild-conan.readthedocs.io/
  • License: MIT License Copyright (c) 2023 Dominik Krupke Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Latest release: 1.3.0
    published about 1 year ago
  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 1,106 Last month
Rankings
Dependent packages count: 7.2%
Average: 28.5%
Forks count: 30.4%
Dependent repos count: 37.0%
Stargazers count: 39.3%
Maintainers (1)
Last synced: 5 months ago

Dependencies

.github/workflows/pytest.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/pytest_cgal.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/pytest_cgal_custom_recipe.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/pytest_cgal_windows.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • ilammy/msvc-dev-cmd v1 composite
.github/workflows/pytest_windows.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • ilammy/msvc-dev-cmd v1 composite
.github/workflows/release.yml actions
  • actions/checkout master composite
  • actions/setup-python v4 composite
  • pypa/gh-action-pypi-publish release/v1 composite
examples/cgal_skbuild_conan_example/pyproject.toml pypi
examples/cgal_skbuild_conan_example/setup.py pypi
examples/cgal_skbuild_conanio_example/pyproject.toml pypi
examples/cgal_skbuild_conanio_example/setup.py pypi
examples/simple_skbuild_conan_example/pyproject.toml pypi
examples/simple_skbuild_conan_example/setup.py pypi
pyproject.toml pypi
  • cmake >=3.23
  • conan >=2.0.0
  • ninja *
  • scikit-build >=0.17.3
  • setuptools *