Skip to content

Commit

Permalink
feat(template): Added scikit as an option for build system (#161)
Browse files Browse the repository at this point in the history
* Activate option in TUI to maturin
* Adding documentation about scikit
* Adding scikit as a build-system:
* Creating a scikit-pyproject.toml
* Editing post_gen_project.py
* Creating a smoke test (build-system.sh)
* Editing cookicutter.json
* Added scikit in Readme.md
  • Loading branch information
ayeankit authored Aug 1, 2023
1 parent 67a40af commit 3dc8562
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ for a Python package.
[PDM](https://pdm.fming.dev/) or
[Hatch](https://hatch.pypa.io)
[Maturin](https://pypi.org/project/maturin/0.8.2/)
[scikit-build-core](https://scikit-build-core.readthedocs.io/en/latest/)
based on your preference.
- The structure of the project can use the *src layout* or *flat
layout*. The “src layout” moving the code that is intended to be
Expand Down
9 changes: 9 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,15 @@ packages. SciCookie support the following:
developers a simple solution to combine the strengths of Python and Rust within
a unified project.

- [**scikit-build-core**](https://scikit-build-core.readthedocs.io/en/latest/): It's build system designed for Python
packaging tool, serving as an enhanced build system generator for CPython
C extensions greatly improves package management within the scientific Python
ecosystem. It offers superior support for diverse compilers, build systems,
cross-compilation, and efficient dependency locating with their associated
build requirements. With its capabilities, it facilitates cross-platform
builds using CMake and effortless integration with C/C++ libraries, making
it a valuable asset for research software engineers.

The idea behind the options in SciCookie is that you can choose from some of the
most popular system compilers to suit your needs and preferences for developing
Python packages. If you think we should add more options, you can submit your
Expand Down
3 changes: 2 additions & 1 deletion src/scicookie/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"setuptools",
"pdm",
"hatch",
"maturin"
"maturin",
"scikit-build-core"
],
"use_bandit": "yes",
"use_black": "no",
Expand Down
17 changes: 16 additions & 1 deletion src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
BUILD_SYSTEM = "hatch"
{% elif cookiecutter.build_system == "maturin" -%}
BUILD_SYSTEM = "maturin"
{% elif cookiecutter.build_system == "scikit-build-core" -%}
BUILD_SYSTEM = "scikit-build-core"
{%- else %}
BUILD_SYSTEM = None
{%- endif %}
Expand Down Expand Up @@ -199,7 +201,20 @@ def clean_up_build_system():
shutil.move(
build_system_dir / "Cargo.toml",
PROJECT_DIRECTORY / 'Cargo.toml'
)
)
elif BUILD_SYSTEM == "scikit-build-core":
shutil.move(
build_system_dir / "scikit-build-core-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
shutil.move(
build_system_dir / "CMakeLists.txt",
PROJECT_DIRECTORY / 'CMakeLists.txt'
)
shutil.move(
build_system_dir / "skcdemo.cpp",
PROJECT_DIRECTORY / 'skcdemo.cpp'
)
else:
shutil.move(
build_system_dir / "base-pyproject.toml",
Expand Down
1 change: 1 addition & 0 deletions src/scicookie/profiles/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ build_system:
- pdm
- hatch
- maturin
- scikit-build-core
enabled: false

command_line_interface:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15...3.26)

project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES CXX)

find_package(pybind11 CONFIG REQUIRED)

pybind11_add_module(skcdemo MODULE skcdemo.cpp)

install(TARGETS skcdemo DESTINATION .)
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
[build-system]
requires = ["scikit-build-core", "pybind11"]
build-backend = "scikit_build_core.build"

[project]
name = "{{ cookiecutter.project_slug }}"
authors = [
{ name = "{{ cookiecutter.author_full_name }}", email = "{{ cookiecutter.author_email }}" },
]
description = "{{ cookiecutter.project_short_description }}"
{% if cookiecutter.project_layout == "src" -%}
packages = [
{include = "{{ cookiecutter.package_slug }}", from="src"},
]
{% else -%}
packages = [
{include = "{{ cookiecutter.package_slug }}"},
]
{% endif -%}
readme = "README.md"
classifiers = [
"Development Status :: 1 - Planning",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
{%- if cookiecutter.project_license == "MIT" %}
"License :: OSI Approved :: MIT License",
{%- elif cookiecutter.project_license == "BSD 3 Clause" %}
"License :: OSI Approved :: BSD License",
{%- elif cookiecutter.project_license == "Apache Software License 2.0" %}
"License :: OSI Approved :: Apache Software License",
{%- elif cookiecutter.project_license == "GNU General Public License v3" %}
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
{%- endif %}
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
"Typing :: Typed",
]
version = "{{ cookiecutter.project_version }}"
requires-python = ">=3.8.1"
dependencies = [
{# keep this line here #}
{%- if cookiecutter.use_pytest == "yes" -%}
"pytest >= 7.3.2",
{% if cookiecutter.use_coverage == "yes" -%}
"pytest-cov >= 4.1.0",
{% endif %}
{%- endif -%}{#- end of use_pytest -#}
{%- if cookiecutter.use_hypothesis == "yes" -%}
"hypothesis >= 6.0",
{% endif %}
{%- if cookiecutter.use_coverage == "yes" -%}
"coverage >= 7.2.7",
{% endif %}
{%- if cookiecutter.use_blue == "yes" -%}
"blue >= 0.9.1",
{% endif %}
{%- if cookiecutter.use_black == "yes" -%}
"black >= 23.3.0",
{% endif %}
{%- if cookiecutter.use_isort == "yes" -%}
"isort >= 5.12.0",
{% endif %}
{%- if cookiecutter.use_pre_commit -%}
"pre-commit >= 3.3.2",
{% endif %}
{%- if cookiecutter.use_flake8 == "yes" -%}
"flake8 >= 4.0.1, < 7",
{% endif %}
{%- if cookiecutter.use_ruff == "yes" -%}
"ruff >= 0.0.272",
{% endif %}
{%- if cookiecutter.use_mypy == "yes" -%}
"mypy >= 1.3.0",
{% endif %}
{%- if cookiecutter.use_bandit == "yes" -%}
"bandit >= 1.7.5",
{% endif %}
{%- if cookiecutter.use_pydocstyle == "yes" -%}
"pydocstyle >= 6.3.0",
{% endif %}
{%- if cookiecutter.use_vulture == "yes" -%}
"vulture >= 2.7",
{% endif %}
{%- if cookiecutter.use_mccabe == "yes" -%}
"mccabe >= 0.6.1",
{% endif %}
{%- if cookiecutter.use_containers in ['Docker', 'Podman'] -%}
# if you want to use docker-compose from your system, remove compose-go here
"compose-go >= 2.18.1",
{% endif %}
"ipython < 8",
"ipykernel >=6.0.0",
{%- if cookiecutter.documentation_engine == 'mkdocs' %}
"Jinja2 >= 3.1.2",
"mkdocs >= 1.4.3",
"mkdocs-exclude >= 1.0.2",
"mkdocs-jupyter >= 0.24.1",
"mkdocs-literate-nav >= 0.6.0",
"mkdocs-macros-plugin >= 0.7.0, < 1",
"mkdocs-material >= 9.1.15",
"mkdocstrings >= 0.21.2",
"mkdocstrings-python >= 1.1.2",
{% elif cookiecutter.documentation_engine == 'sphinx' -%}
"Sphinx >= 6.2.1",
"sphinx-rtd-theme >= 1.2.2",
"importlib-metadata >= 6.5.1",
"myst-parser >= 0.19.2",
"nbsphinx >= 0.9.2",
"pandoc >= 2.3",
{% elif cookiecutter.documentation_engine == 'jupyter-book' -%}
"jupyter-book >= 0.15.1",
"myst-parser >= 0.18.1",
{% endif %}
]

[project.urls]
Homepage = "{{ cookiecutter.project_url }}"
"Bug Tracker" = "{{ cookiecutter.project_url }}/issues"
Discussions = "{{ cookiecutter.project_url }}/discussions"
Changelog = "{{ cookiecutter.project_url }}/releases"

{% include "build-system/base-pyproject.toml" %}
{#- keep this line at the end of the file -#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <pybind11/pybind11.h>

namespace py = pybind11;

PYBIND11_MODULE(skcdemo, m) {
m.def("hello", [](){
py::print("Hello, scikit-build-core!");
});
}
3 changes: 3 additions & 0 deletions src/scicookie/{{cookiecutter.project_slug}}/conda/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ dependencies:
{%- elif cookiecutter.build_system == "maturin" %}
- maturin
- rust
{%- elif cookiecutter.build_system == "scikit-build-core" %}
- scikit-build-core
- cmake
{%- endif %}
- nodejs # used by semantic-release
- shellcheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ In addition, you should know that to build our package we use
{%- elif cookiecutter.build_system == "maturin" -%}
In addition, you should know that to build our package we use
[Maturin](https://pypi.org/project/maturin/0.8.2/):It's a Python packaging tool and build system for creating Python bindings from Rust projects. It enables seamless integration of Rust code into Python applications, offering efficient builds, cross-platform support, and compatibility with different Python versions. Maturin automates the process of generating Python modules that directly call Rust functions, leveraging Rust's performance and low-level capabilities in Python. With its easy-to-use interface and integration with setuptools and Cargo, Maturin provides a straightforward solution for developers seeking to combine the strengths of Python and Rust in a single project.
{%- elif cookiecutter.build_system == "scikit-build-core" -%}
In addition, you should know that to build our package we use
[scikit-build-core](https://scikit-build-core.readthedocs.io/en/latest/): It's a Python packaging tool and build system an improved build system generator for CPython C extensions. It provides better support for additional compilers, build systems, cross compilation, and locating dependencies and their associated build requirements.This tool improves package management in the scientific Python ecosystem, enabling cross-platform builds with CMake, and seamless integration with C/C++ libraries for research software engineers.
{%- endif %}

Contributions are welcome, and they are greatly appreciated! Every little bit
Expand Down
4 changes: 3 additions & 1 deletion tests/smoke/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ elif command -v pdm &> /dev/null; then
elif command -v hatch &> /dev/null; then
COMMAND_PREFIX="hatch run"
elif command -v maturin &> /dev/null; then
pip install .
pip install -e .
elif [ "$(pip list|grep -c scikit_build_core)" -ne "0" ]; then
pip install -e .
else
# use setuptools
pip install --editable .
Expand Down
1 change: 1 addition & 0 deletions tests/smoke/build-system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ SMOKE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
. ${SMOKE_DIR}/base.sh "build_system=pdm"
. ${SMOKE_DIR}/base.sh "build_system=hatch"
. ${SMOKE_DIR}/base.sh "build_system=maturin"
. ${SMOKE_DIR}/base.sh "build_system=scikit-build-core"

0 comments on commit 3dc8562

Please sign in to comment.