Skip to content

Commit

Permalink
cpp init
Browse files Browse the repository at this point in the history
  • Loading branch information
AidanJohnston committed Jan 24, 2024
1 parent 94017d2 commit 74a3a72
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
build
*.egg-info
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
default: help

help:
@echo "Rasal makefile commands, run with make <command>"
@echo
@grep -E '^[a-zA-Z0-9 -]+:.*#' Makefile | sort | while read -r l; do printf "\t\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done
@echo

.PHONY: clean
clean: # Clean your working directory.
@printf "\033[36m ---------- $@: Cleaning workding directory ----------\033[0m\n"
rm -rf .venv
rm -rf .tox
rm -rf build
rm -rf *.egg-info
rm -rf *.pyc

.PHONY: dev
dev: clean # Build and enter a dev environment.
@printf "\033[36m ---------- $@: Building dev environment ----------\033[0m\n"
python -m venv .venv;
.venv/bin/pip install ./
.venv/bin/python
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[build-system]
requires = [
"setuptools>=30.3.0",
"setuptools>=42",
"pybind11>=2.10.0",
]
build-backend = "setuptools.build_meta"

[tool.cibuildwheel]
test-command = "python {project}/tests/test.py"
test-skip = "*universal2:arm64"

[tool.ruff.per-file-ignores]
"ci/*" = ["S"]
Expand Down
37 changes: 27 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
from pathlib import Path

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

Expand All @@ -10,10 +11,30 @@ def read(*names, **kwargs):
with Path(__file__).parent.joinpath(*names).open(encoding=kwargs.get("encoding", "utf8")) as fh:
return fh.read()

__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__)],
),
]

setup(
name="rasal",
version="0.0.0",
name=__name__,
version=__version__,
license="MIT",
description="Resolution and Sensors and Lens.",
long_description="{}\n{}".format(
Expand All @@ -23,10 +44,11 @@ def read(*names, **kwargs):
author="Aidan Johnston",
author_email="contact@aidanjohnston.ca",
url="https://github.com/AidanJohnston/rasal",
packages=find_packages("src"),
package_dir={"": "src"},
py_modules=[path.stem for path in Path("src").glob("*.py")],
# py_modules=[path.stem for path in Path("src").glob("*.py")],
include_package_data=True,
ext_modules=ext_modules,
# Currently, build_ext only provides an optional "highest supported C++
# level" feature, but in the future it may provide more features.
zip_safe=False,
classifiers=[
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down Expand Up @@ -66,9 +88,4 @@ def read(*names, **kwargs):
# "rst": ["docutils>=0.11"],
# ":python_version=="2.6"": ["argparse"],
},
entry_points={
"console_scripts": [
"rasal = rasal.cli:main",
]
},
)
1 change: 0 additions & 1 deletion src/rasal/__init__.py

This file was deleted.

14 changes: 0 additions & 14 deletions src/rasal/__main__.py

This file was deleted.

30 changes: 0 additions & 30 deletions src/rasal/cli.py

This file was deleted.

Empty file added src/rasal/filmback.cpp
Empty file.
Empty file.
Empty file added src/rasal/lens.cpp
Empty file.
52 changes: 52 additions & 0 deletions src/rasal/rasal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <pybind11/pybind11.h>
#include <nlohmann/json.hpp>

#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)

/*
* _____ _____ _
* | __ \ /\ / ____| /\ | |
* | |__) | / \ | (___ / \ | |
* | _ / / /\ \ \___ \ / /\ \ | |
* | | \ \ / ____ \ ____) / ____ \| |____
* |_| \_\/_/ \_\_____/_/ \_\______|
*
*/

int add(int i, int j) {
return i + j;
}

namespace py = pybind11;

PYBIND11_MODULE(rasal, m) {
m.doc() = R"pbdoc(
Resolution and Sensors and Lens.
_____ _____ _
| __ \ /\ / ____| /\ | |
| |__) | / \ | (___ / \ | |
| _ / / /\ \ \___ \ / /\ \ | |
| | \ \ / ____ \ ____) / ____ \| |____
|_| \_\/_/ \_\_____/_/ \_\______|
)pbdoc";

m.def("add", &add, R"pbdoc(
Add two numbers
Some other explanation about the add function.
)pbdoc");

m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc(
Subtract two numbers
Some other explanation about the subtract function.
)pbdoc");

#ifdef VERSION_INFO
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
#else
m.attr("__version__") = "dev";
#endif
}
Empty file added src/rasal/resolution.cpp
Empty file.
15 changes: 15 additions & 0 deletions src/rasal/sensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Sensor {

int width;
int height;

public:
Sensor (int, int)

}

Sensor::Sensor (int width, int height) {
width = width
heigh = height
}

0 comments on commit 74a3a72

Please sign in to comment.