Skip to content

Commit

Permalink
feat(template): adding meson-python as a build-system option (#139)
Browse files Browse the repository at this point in the history
* Activate option in TUI to meson-python.
* Adding meson-python as a build-system:
  * Creating a mesonpy-pyproject.toml
  * Editing post_gen_project.py
  * Adding mesonpy to build-system.sh
  * Adding meson.build as additional configuration file
  * Editing cookicutter.json
  * Adding meson-python in conda/dev.yaml
  • Loading branch information
YurelyCamacho committed Jul 2, 2023
1 parent 791ca16 commit c05dc79
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
- coc.sh
- governance.sh
- roadmap.sh
- build-system.sh

defaults:
run:
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ for a Python package.
- Support to pre-commit
- CI with github actions
- Release workflow with semantic release and github actions
- Flexible build system selection: Choose between popular build systems like
[Poetry](https://python-poetry.org/) or [Flit](https://flit.pypa.io) based
on your preference.
- Flexible build system selection: Choose between popular build
systems like [Poetry](https://python-poetry.org/),
[Flit](https://flit.pypa.io) or
[meson-python](https://meson-python.readthedocs.io/en/latest/index.html)
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
importable into a subdirectory. This subdirectory is typically named
Expand Down
9 changes: 9 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ packages. SciCookie support the following:
few commands, you can use Flit to quickly create source distributions and
wheel packages and submit them to PyPI.

- [**meson-python**](https://meson-python.readthedocs.io/en/latest/index.html):
It's a Python build backend built on top of the *Meson* build-system.
It enables you to use Meson for your Python packages. With
meson-python, you can easily define project dependencies, specify
build options, generate configuration files and build scripts, among
other things. Meson-python is primarily focused on improving speed and
ease of use compared to other build systems. It is designed to be fast
and scalable, making it suitable for both small and large projects.

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 @@ -45,7 +45,8 @@
],
"build_system": [
"poetry",
"flit"
"flit",
"mesonpy"
],
"use_bandit": "yes",
"use_black": "no",
Expand Down
11 changes: 11 additions & 0 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
BUILD_SYSTEM = "poetry"
{% elif cookiecutter.build_system == "flit" -%}
BUILD_SYSTEM = "flit"
{% elif cookiecutter.build_system == "mesonpy" -%}
BUILD_SYSTEM = "mesonpy"
{%- else %}
BUILD_SYSTEM = None
{%- endif %}
Expand Down Expand Up @@ -155,6 +157,15 @@ def clean_up_build_system():
build_system_dir / "flit-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
elif BUILD_SYSTEM == "mesonpy":
shutil.move(
build_system_dir / "mesonpy-pyproject.toml",
PROJECT_DIRECTORY / 'pyproject.toml'
)
shutil.move(
build_system_dir / "meson.build",
PROJECT_DIRECTORY / 'meson.build'
)
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 @@ -83,6 +83,7 @@ build_system:
choices:
- poetry
- flit
- mesonpy
enabled: false

command_line_interface:
Expand Down
4 changes: 3 additions & 1 deletion src/scicookie/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ docs-preview: docs-build
build:
{%- if cookiecutter.build_system == 'poetry' %}
poetry build
{%- elif cookiecutter.build_system == 'poetry' %}
{%- elif cookiecutter.build_system == 'flit' %}
flit build
{%- elif cookiecutter.build_system == 'mesonpy' %}
meson build
{%- endif %}

.PHONY:release-ci
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ dependencies = [
"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 %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
project(
'{{ cookiecutter.project_slug }}',
'cpp',
version: '{{ cookiecutter.project_version }}', # semantic-release
license: '{{ cookiecutter.project_license }}',
meson_version: '>= 1.1.0',
)
name = '{{ cookiecutter.project_slug }}'

py_mod = import('python')
py = py_mod.find_installation(pure: false)

py.extension_module(
'{{ cookiecutter.package_slug }}.py',
install: true,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
[build-system]
build-backend = "mesonpy"
requires = ["meson", "meson-python"]


[project]
name = "{{ cookiecutter.project_slug }}"
description = "{{ cookiecutter.project_short_description }}"
authors = [
{ name = "{{ cookiecutter.author_full_name }}", email = "{{ cookiecutter.author_email }}" },
]
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",
]
dynamic = ["version"]
requires-python = ">=3.8"
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 -#}
4 changes: 3 additions & 1 deletion src/scicookie/{{cookiecutter.project_slug}}/conda/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ dependencies:
- python <3.11
{%- if cookiecutter.build_system == 'poetry' %}
- poetry
{%- else %}
{%- elif cookiecutter.build_system == 'flit' %}
- flit
{%- elif cookiecutter.build_system == 'mesonpy' %}
- meson-python
{%- endif %}
- nodejs # used by semantic-release
- shellcheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ plugins:
enable_inventory: true
handlers:
python:
{% if cookiecutter.project_layout == "src" -%}
paths: [../src]
{% else %}
paths: [..]
{%- endif %}
import:
- https://docs.python.org/3/objects.inv
options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ packages to PyPI. Flit handles the packaging, distribution, and installation of
Python packages, making it easier for us to share our code with others. It also
includes features such as dependency management, versioning, and metadata
management.
{%- elif cookiecutter.build_system == "mesonpy" -%}
In addition, you should know that to build our package we use
[meson-python](https://meson-python.readthedocs.io/en/latest/index.html),
it's a tool for automating and simplifying the construction of software
projects written in the Python programming language. It is based on the
*Meson* build system, which allows you to efficiently configure and manage
the build process of a project. It allows you to easily define project
dependencies, specify build options, generate configuration files and
build scripts, among other tasks related to building software.

{%- endif %}

Expand Down
3 changes: 3 additions & 0 deletions tests/smoke/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CONDA_PREFIX="${CONDA_PATH}/envs/${ENV_NAME}"
export PATH=$(echo $PATH| sed -E "s/[^:]+\/mambaforge\/[^:]+//g")
export PATH=$(echo $PATH| sed -E "s/[^:]+\/conda\/[^:]+//g")
export PATH=$(echo $PATH| sed -E "s/[^:]+\/miniconda\/[^:]+//g")
export PATH=$(echo $PATH| sed -E "s/[^:]+\/miniconda3\/[^:]+//g")
export PATH=$(echo $PATH| sed -E "s/[^:]+\/micromamba\/[^:]+//g")
export PATH=$(echo $PATH| sed -E "s/[^:]+\/anaconda3\/[^:]+//g")
export PATH="${CONDA_PREFIX}:${CONDA_PREFIX}/bin:$PATH"
Expand All @@ -44,6 +45,8 @@ if command -v poetry &> /dev/null; then
poetry install
elif command -v flit &> /dev/null; then
flit install
elif command -v meson &> /dev/null; then
pip install -e .
fi

ipython kernel install --name "python3" --user
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 @@ -4,3 +4,4 @@ SMOKE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

. ${SMOKE_DIR}/base.sh "build_system=poetry"
. ${SMOKE_DIR}/base.sh "build_system=flit"
. ${SMOKE_DIR}/base.sh "build_system=mesonpy"

0 comments on commit c05dc79

Please sign in to comment.