Skip to content

Commit

Permalink
Merge pull request #1 from AidanJohnston/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
AidanJohnston authored Feb 13, 2024
2 parents 74a3a72 + f653a41 commit 699eaae
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 120 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# PYTHON
.venv
build
*.egg-info
dist/
_build/
_generate/
*.py[cod]
*env*
.tox

# CMAKE
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
*.so
23 changes: 0 additions & 23 deletions Makefile

This file was deleted.

91 changes: 27 additions & 64 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,59 +1,34 @@
========
Overview
========
=====
RASAL
=====

.. start-badges
.. list-table::
:stub-columns: 1

* - docs
- |docs|
* - tests
- | |github-actions|
| |codecov|
* - package
- | |version| |wheel| |supported-versions| |supported-implementations|
| |commits-since|
.. |docs| image:: https://readthedocs.org/projects/rasal/badge/?style=flat
:target: https://rasal.readthedocs.io/
:alt: Documentation Status

.. |github-actions| image:: https://github.com/AidanJohnston/rasal/actions/workflows/github-actions.yml/badge.svg
:alt: GitHub Actions Build Status
:target: https://github.com/AidanJohnston/rasal/actions

.. |codecov| image:: https://codecov.io/gh/AidanJohnston/rasal/branch/main/graphs/badge.svg?branch=main
:alt: Coverage Status
:target: https://app.codecov.io/github/AidanJohnston/rasal

.. |version| image:: https://img.shields.io/pypi/v/rasal.svg
:alt: PyPI Package latest release
:target: https://pypi.org/project/rasal

.. |wheel| image:: https://img.shields.io/pypi/wheel/rasal.svg
:alt: PyPI Wheel
:target: https://pypi.org/project/rasal

.. |supported-versions| image:: https://img.shields.io/pypi/pyversions/rasal.svg
:alt: Supported versions
:target: https://pypi.org/project/rasal

.. |supported-implementations| image:: https://img.shields.io/pypi/implementation/rasal.svg
:alt: Supported implementations
:target: https://pypi.org/project/rasal
Resolution and Sensors and Lens.

.. |commits-since| image:: https://img.shields.io/github/commits-since/AidanJohnston/rasal/v0.0.0.svg
:alt: Commits since latest release
:target: https://github.com/AidanJohnston/rasal/compare/v0.0.0...main
.. class:: center

.. image:: https://readthedocs.org/projects/rasal/badge/?version=latest&style=flat-square
:target: https://rasal.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://img.shields.io/pypi/v/rasal.svg?style=flat-square
:alt: PyPI Package latest release
:target: https://pypi.org/project/rasal

.. end-badges
.. image:: https://img.shields.io/pypi/dm/rasal?style=flat-square
:alt: PyPi Package Downloads
:target: https://pypi.org/project/rasal

.. image:: https://img.shields.io/pypi/wheel/rasal.svg?style=flat-square
:alt: PyPI Wheel
:target: https://pypi.org/project/rasal

Resolution and Sensors and Lens.
.. image:: https://img.shields.io/pypi/pyversions/rasal.svg?style=flat-square
:alt: Supported versions
:target: https://pypi.org/project/rasal

* Free software: MIT license
.. image:: https://img.shields.io/pypi/implementation/rasal.svg?style=flat-square
:alt: Supported implementations
:target: https://pypi.org/project/rasal

Installation
============
Expand Down Expand Up @@ -81,19 +56,7 @@ To run all the tests run::

tox

Note, to combine the coverage data from all the tox environments run:

.. list-table::
:widths: 10 90
:stub-columns: 1

- - Windows
- ::

set PYTEST_ADDOPTS=--cov-append
tox

- - Other
- ::
License
=======

PYTEST_ADDOPTS=--cov-append tox
Rasal is under the MIT license. See the LICENSE file for more information.
14 changes: 10 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
requires = [
"setuptools>=42",
"pybind11>=2.10.0",
"wheel",
"cmake>=3.12",
]

build-backend = "setuptools.build_meta"

[tool.cibuildwheel]
test-command = "python {project}/tests/test.py"
test-skip = "*universal2:arm64"
test-command = "pytest {project}/tests"
test-extras = ["test"]
test-skip = ["*universal2:arm64"]
# Setuptools bug causes collision between pypy and cpython artifacts
before-build = "rm -rf {project}/build"


[tool.ruff.per-file-ignores]
"ci/*" = ["S"]
Expand All @@ -18,7 +25,6 @@ ignore = [
"RUF001", # ruff-specific rules ambiguous-unicode-character-string
"S101", # flake8-bandit assert
"S308", # flake8-bandit suspicious-mark-safe-usage
"E501", # pycodestyle line-too-long
]
line-length = 79
select = [
Expand Down Expand Up @@ -54,5 +60,5 @@ forced-separate = ["conftest"]
force-single-line = true

[tool.black]
line-length = 140
line-length = 79
target-version = ["py38"]
162 changes: 146 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,173 @@
#!/usr/bin/env python
import os
import re
import subprocess
import sys
from pathlib import Path

from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext

from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import find_packages
from setuptools import setup


def read(*names, **kwargs):
with Path(__file__).parent.joinpath(*names).open(encoding=kwargs.get("encoding", "utf8")) as fh:
with Path(__file__).parent.joinpath(*names).open(
encoding=kwargs.get("encoding", "utf8")
) as fh:
return fh.read()

__name__ = "rasal"

__name__ = "rasal"
__version__ = "0.0.1"

# The main interface is through Pybind11Extension.
# * You can add cxx_std=11/14/17, and then build_ext can be removed.
# * You can set include_pybind11=false to add the include directory yourself,
# say from a submodule.
#
# Note:
# Sort input source files if you glob sources to ensure bit-for-bit
# reproducible builds (https://github.com/pybind/python_example/pull/53)

ext_modules = [
Pybind11Extension(
__name__,
["src/rasal/rasal.cpp"],
# Example: passing in the version to the compiled code
define_macros=[("VERSION_INFO", __version__)],
),

# Convert distutils Windows platform specifiers to CMake -A arguments
PLAT_TO_CMAKE = {
"win32": "Win32",
"win-amd64": "x64",
"win-arm32": "ARM",
"win-arm64": "ARM64",
}


# A CMakeExtension needs a sourcedir instead of a file list.
# The name must be the _single_ output extension from the CMake build.
# If you need multiple extensions, see scikit-build.
class CMakeExtension(Extension):
def __init__(self, name: str, sourcedir: str = "") -> None:
super().__init__(name, sources=[])
self.sourcedir = os.fspath(Path(sourcedir).resolve())


class CMakeBuild(build_ext):
def build_extension(self, ext: CMakeExtension) -> None:
# Must be in this form due to bug in .resolve() only fixed in Python 3.10+
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
extdir = ext_fullpath.parent.resolve()

# Using this requires trailing slash for auto-detection & inclusion of
# auxiliary "native" libs

debug = (
int(os.environ.get("DEBUG", 0))
if self.debug is None
else self.debug
)
cfg = "Debug" if debug else "Release"

# CMake lets you override the generator - we need to check this.
# Can be set with Conda-Build, for example.
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")

# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
# EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
# from Python.
cmake_args = [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
]
build_args = []
# Adding CMake arguments set as environment variable
# (needed e.g. to build for ARM OSx on conda-forge)
if "CMAKE_ARGS" in os.environ:
cmake_args += [
item for item in os.environ["CMAKE_ARGS"].split(" ") if item
]

# In this example, we pass in the version to C++. You might not need to.
cmake_args += [
f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"
]

if self.compiler.compiler_type != "msvc":
# Using Ninja-build since it a) is available as a wheel and b)
# multithreads automatically. MSVC would require all variables be
# exported for Ninja to pick it up, which is a little tricky to do.
# Users can override the generator with CMAKE_GENERATOR in CMake
# 3.15+.
if not cmake_generator or cmake_generator == "Ninja":
try:
import ninja

ninja_executable_path = Path(ninja.BIN_DIR) / "ninja"
cmake_args += [
"-GNinja",
f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}",
]
except ImportError:
pass

else:
# Single config generators are handled "normally"
single_config = any(
x in cmake_generator for x in {"NMake", "Ninja"}
)

# CMake allows an arch-in-generator style for backward compatibility
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})

# Specify the arch if using MSVC generator, but only if it doesn't
# contain a backward-compatibility arch spec already in the
# generator name.
if not single_config and not contains_arch:
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]

# Multi-config generators have a different way to specify configs
if not single_config:
cmake_args += [
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"
]
build_args += ["--config", cfg]

if sys.platform.startswith("darwin"):
# Cross-compile support for macOS - respect ARCHFLAGS if set
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
if archs:
cmake_args += [
"-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))
]

# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
# self.parallel is a Python 3 only way to set parallel jobs by hand
# using -j in the build_ext call, not supported by pip or PyPA-build.
if hasattr(self, "parallel") and self.parallel:
# CMake 3.12+ only.
build_args += [f"-j{self.parallel}"]

build_temp = Path(self.build_temp) / ext.name
if not build_temp.exists():
build_temp.mkdir(parents=True)

subprocess.run(
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True
)
subprocess.run(
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
)

ext_modules=[
CMakeExtension("rasal", "./src/"),
]


setup(
name=__name__,
version=__version__,
license="MIT",
description="Resolution and Sensors and Lens.",
long_description="{}\n{}".format(
re.compile("^.. start-badges.*^.. end-badges", re.M | re.S).sub("", read("README.rst")),
re.compile("^.. start-badges.*^.. end-badges", re.M | re.S).sub(
"", read("README.rst")
),
re.sub(":[a-z]+:`~?(.*?)`", r"``\1``", read("CHANGELOG.rst")),
),
author="Aidan Johnston",
Expand All @@ -47,6 +176,7 @@ def read(*names, **kwargs):
# py_modules=[path.stem for path in Path("src").glob("*.py")],
include_package_data=True,
ext_modules=ext_modules,
cmdclass={"build_ext": CMakeBuild},
# Currently, build_ext only provides an optional "highest supported C++
# level" feature, but in the future it may provide more features.
zip_safe=False,
Expand Down
Loading

0 comments on commit 699eaae

Please sign in to comment.