-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from ucodery/meson
Add: hatch plus meson-python python package example to guidebook
- Loading branch information
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
An example Python package used to support Python packaging tutorials | ||
|
||
This project demonstrates mixing C and Python code by using the frontend hatch with the backend mesonpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .temperature import celsius_to_fahrenheit, fahrenheit_to_celsius | ||
|
||
__all__ = ["celsius_to_fahrenheit", "fahrenheit_to_celsius"] | ||
__version__ = "0.1.0dev0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
py.extension_module( | ||
'temperature', | ||
'temperature.c', | ||
install: true, | ||
subdir: 'examplePy' | ||
) | ||
|
||
python_sources = [ | ||
'__init__.py' | ||
] | ||
|
||
py.install_sources( | ||
python_sources, | ||
subdir: 'examplePy' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#define PY_SSIZE_T_CLEAN | ||
#include <Python.h> | ||
|
||
static PyObject * | ||
temperature_celsius_to_fahrenheit(PyObject *self, PyObject *args) | ||
{ | ||
long celsius; | ||
long fahrenheit; | ||
PyObject *ret; | ||
|
||
if (!PyArg_ParseTuple(args, "l", &celsius)) | ||
return NULL; | ||
|
||
fahrenheit = (celsius * 9/5) + 32; | ||
|
||
ret = PyLong_FromLong(fahrenheit); | ||
Py_INCREF(ret); | ||
return ret; | ||
} | ||
|
||
static PyObject * | ||
temperature_fahrenheit_to_celsius(PyObject *self, PyObject *args) | ||
{ | ||
long fahrenheit; | ||
long celsius; | ||
PyObject *ret; | ||
|
||
if (!PyArg_ParseTuple(args, "l", &fahrenheit)) | ||
return NULL; | ||
|
||
celsius = (fahrenheit - 32) * 9/5; | ||
|
||
ret = PyLong_FromLong(celsius); | ||
Py_INCREF(ret); | ||
return ret; | ||
} | ||
|
||
static PyMethodDef CoreMethods[] = { | ||
{"celsius_to_fahrenheit", temperature_celsius_to_fahrenheit, METH_VARARGS, "Convert temperature from Celsius to Fahrenheit"}, | ||
{"fahrenheit_to_celsius", temperature_fahrenheit_to_celsius, METH_VARARGS, "Convert temperature from Fahrenheit to Celsius"}, | ||
{NULL, NULL, 0, NULL} /* Sentinel */ | ||
}; | ||
|
||
static struct PyModuleDef temperaturemodule = { | ||
PyModuleDef_HEAD_INIT, | ||
"temperature", /* name of module */ | ||
NULL, /* module documentation, may be NULL */ | ||
-1, /* size of per-interpreter state of the module, | ||
or -1 if the module keeps state in global variables. */ | ||
CoreMethods | ||
}; | ||
|
||
PyMODINIT_FUNC | ||
PyInit_temperature(void) | ||
{ | ||
PyObject *m; | ||
|
||
m = PyModule_Create(&temperaturemodule); | ||
if (m == NULL) | ||
return NULL; | ||
|
||
return m; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
project( | ||
'examplePy', | ||
'c', | ||
version: '0.1.dev0', | ||
license: 'MIT', | ||
meson_version: '>= 0.64.0', | ||
default_options: [ | ||
'buildtype=debugoptimized', | ||
'c_std=c99', | ||
'cpp_std=c++14', | ||
], | ||
) | ||
|
||
cc = meson.get_compiler('c') | ||
|
||
py_mod = import('python') | ||
py = py_mod.find_installation(pure: false) | ||
py_dep = py.dependency() | ||
|
||
subdir('examplePy') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[build-system] | ||
build-backend = "mesonpy" | ||
requires = [ | ||
"meson-python>=0.13.0rc0", | ||
] | ||
|
||
[project] | ||
name = "examplePy" | ||
version = "0.1" | ||
authors = [ | ||
{name = "Some Maintainer", email = "some-email@pyopensci.org"}, | ||
] | ||
maintainers = [ | ||
{name = "All the contributors"}, | ||
] | ||
description = "An example Python package used to support Python packaging tutorials" | ||
keywords = ["pyOpenSci", "python packaging"] | ||
readme = "README" | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: BSD License", | ||
"Operating System :: OS Independent", | ||
] |