Skip to main content

No project description provided

Project description

hatch-cython

PyPI - Version PyPI - Python Version PyPI - Downloads Build Tests codecov Ruff


Table of Contents

Usage

The build hook name is cython.

  • pyproject.toml
[tool.hatch.build.targets.wheel.hooks.cython]
dependencies = ["hatch-cython"]

[tool.hatch.build.targets.wheel.hooks.cython.options]
<!-- include .h or .cpp directories -->
includes = []
<!-- include numpy headers -->
include_numpy = false
include_pyarrow = false

include_somelib = {
    pkg = "somelib",
    <!-- somelib.gets_include() -> str -->
    include = "gets_include",
    <!-- somelib.gets_libraries() -> list[str] -->
    libraries = "gets_libraries",
    <!-- somelib.gets_library_dirs() -> list[str] -->
    library_dirs = "gets_library_dirs",
    <!-- somelib.some_setup_op() before build -->
    required_call = "some_setup_op"
}

compile_args = [
    <!-- single string -->
    "-std=c++17",
    <!-- list of platforms + arg -->
    { platforms = ["nt"], arg = "-std=c++17" },
    <!-- single platform + arg -->
    { platforms = "posix", arg = "-I/abc/def" },
]

directives = { boundscheck = false, nonecheck = false, language_level = 3, binding = true }

compile_kwargs = { }
  • hatch.toml
[build.targets.wheel.hooks.cython]
dependencies = ["hatch-cython"]

[build.targets.wheel.hooks.cython.options]
<!-- optional, defaults below -->
directives = { boundscheck = false, nonecheck = false, language_level = 3, binding = true }
compile_args = [
    "-O3",
]
includes = []
include_numpy = false
<!-- equivalent to include_pyarrow = true -->
include_somelib = { pkg = "pyarrow", include="get_include", libraries="get_libraries", library_dirs="get_library_dirs", required_call="create_library_symlinks" }
define_macros = [
    ["NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"],
]

Configuration Options

Field Type
src str | None 
 directory within src dir or .  which aliases the package being built. e.g. package_a -> src/package_a_lib 
 src = "package_a"
directives directives to cython (see [compiler directives])
compile_args str or { platforms = ["*"] | "*", arg = str }. see extensions for what args may be relevant
extra_link_args str or { platforms = ["*"] | "*", arg = str }. see extensions for what args may be relevant
env { env = "VAR1", arg = "VALUE", platforms = ["*"], arch = ["*"] }
 if flag is one of:
 - ARFLAGS
 - LDSHARED 
 - LDFLAGS
 - CPPFLAGS 
 - CFLAGS 
 - CCSHARED
the current env vars will be merged with the value (provided platform & arch applies), separated by a space. This can be enabled by adding { env = "MYVAR" ... , merges = true } to the definition.
includes list str
includes_{package} { pkg = str, include = str, libraries = str| None, library_dirs = str | None , required_call = str | None } 
where all fields, but pkg, are attributes of pkg in the type of callable() -> list[str] | str | list[str] | str. pkg is a module, or loadable module object, which may be imported through import x.y.z.
includes_numpy | includes_pyarrow bool
3rd party named imports. must have the respective opt in dependencies
retain_intermediate_artifacts bool = False 
whether to keep .c | .cpp files
parallel bool = False 
if parallel, add openmp headers
important: if using macos, you need the homebrew llvm vs apple's llvm in order to pass -fopenmp to clang compiler
compiler compiler used at build-time. if msvc (Microsoft Visual Studio), /openmp is used as argument to compile instead of -fopenmp  when parallel = true. default = false
compile_py whether to include .py files when building cython exts. note, this can be enabled & you can do per file / matched file ignores as below. default = true
define_macros list of list str (of len 1 or 2). len 1 == [KEY] == #define KEY FOO . len 2 == [KEY, VALUE] == #define KEY VALUE. see extensions
** kwargs keyword = value pair arguments to pass to the extension module when building. see extensions

Files

[build.targets.wheel.hooks.cython.options.files]
exclude = [
    # anything matching no_compile is ignored by cython
    "*/no_compile/*",
    # note - anything "*" is escaped to "([^\s]*)" (non whitespace).
    # if you need an actual * for python regex, use as below:
    # this excludes all pyd or pytempl extensions
    "([^.]\\*).(pyd$|pytempl$)"
]
aliases = {"abclib._filewithoutsuffix" = "abclib.importalias"}

License

hatch-cython is distributed under the terms of the MIT license.

[compiler directives]:(https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#compiler-directives))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hatch_cython-0.2.5.tar.gz (24.2 kB view hashes)

Uploaded Source

Built Distribution

hatch_cython-0.2.5-py3-none-any.whl (18.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page