I am trying to repackage my old code. I’d appreciate if someone could point out things I am doing the wrong way. This is my first project involving meson-python. The code works, I can install my package in n a conda environment and build conda packages. So, what I am really asking for, is code review.
I went with meson-python because I have other packages that include Fortran code. In the past I managed to build them by monkey-patching distutils. Anyway, here is what I came with:
pyproject.toml
[build-system]
build-backend = "mesonpy"
requires = [
"cython >=0.29",
"meson-python >=0.13",
"numpy >=1.20",
]
[project]
name = "pyudunits"
dynamic = ["version"]
authors = [{name = "George Trojan", email = "george.trojan@gmail.com"}]
maintainers = [{name = "George Trojan", email = "george.trojan@gmail.com"}]
readme = "README.rst"
license = {file = "LICENCE"}
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Atmospheric Science",
"Topic :: Software Development :: Libraries :: Python Modules",
]
description="A simplistic units converter based on udunits2."
requires-python = ">=3.8"
# pip would try to find it
#dependencies = [
# "udunits2"
#]
[project.optional-dependencies]
test = [
"pytest >=7.0",
]
[project.scripts]
lsu = "pyudunits:lsu"
meson.build
project(
'pyudunits',
'c', 'cython',
version: '2.0b0',
meson_version: '>= 1.0',
default_options: [
'buildtype=debugoptimized',
'c_std=c11',
],
)
py3 = import('python').find_installation(pure: false)
incdir_numpy = run_command(py3,
[
'-c',
'import numpy; print(numpy.get_include())'
],
check: true
).stdout().strip()
# Fails with pkg-config and cmake
# libudunits2 = dependency('libudunits2')
cc = meson.get_compiler('c')
# works when building a conda package, fails with pip
libudunits2 = cc.find_library('udunits2', has_headers: 'udunits2.h', required: false)
if libudunits2.found()
inc_dirs = include_directories([incdir_numpy])
else
# Environmental variable. Un-mesonic! Is there a better way?
incdir_conda = run_command(py3,
[
'-c',
'import os; print(os.environ["CONDA_PREFIX"] + "/include")'
],
check: true
).stdout().strip()
inc_dirs = include_directories([incdir_conda, incdir_numpy])
libudunits2 = cc.find_library('udunits2',
header_include_directories: inc_dirs,
has_headers: 'udunits2.h',
required: true
)
endif
py3.extension_module('pyudunits',
'pyudunits.pyx', 'units.c',
include_directories: inc_dirs,
dependencies: libudunits2,
install: true,
)
recipe/meta.yaml
{% set name = "pyudunits" %}
{% set version = "2.0.b0" %}
{% set build_number = 2 %}
package:
name: {{ name|lower }}
version: {{ version }}
source:
path: ..
build:
skip: true # [not linux]
number: {{ build_number }}
script: "{{ PYTHON }} -m pip install . -v"
requirements:
build:
- {{ compiler('c') }}
host:
- python {{ python }}
- meson-python >=0.13
- numpy {{ numpy }}
- cython >=0.29
- udunits2 >=2.2
- pip
run:
- python {{ python }}
- numpy {{ numpy }}
- udunits2 >=2.2
test:
requires:
- pytest
- udunits2
- numpy
source_files:
- tests/test_units.py
commands:
- pytest tests/
about:
# maybe
home: https://github.com/yt87/pyudunits
license: GPL-3.0
license_family: GPL
license_file: LICENCE
summary: Python wrapper for libudunits
extra:
recipe-maintainers:
- yt87