From 4d6636d12db60080c2628adf0e589ea2cd44eb1e Mon Sep 17 00:00:00 2001 From: Nick Wang Date: Tue, 16 Apr 2024 17:11:44 +0000 Subject: [PATCH] fix install directory; --- .vscode/c_cpp_properties.json | 2 +- .vscode/launch.json | 6 +- .vscode/settings.json | 3 +- Makefile | 21 ++++- poetry.lock | 81 +------------------ pyproject.toml | 14 ++-- requirements.txt | 11 +-- {example => src/PyCXpress/example}/Makefile | 2 +- {example => src/PyCXpress/example}/main.cpp | 4 +- {example => src/PyCXpress/example}/model.py | 0 .../include/PyCXpress/core.hpp} | 21 ++++- .../include/PyCXpress/utils.hpp} | 0 12 files changed, 54 insertions(+), 111 deletions(-) rename {example => src/PyCXpress/example}/Makefile (89%) rename {example => src/PyCXpress/example}/main.cpp (95%) rename {example => src/PyCXpress/example}/model.py (100%) rename src/{cpp/PyCXpress.hpp => PyCXpress/include/PyCXpress/core.hpp} (92%) rename src/{cpp/Utils.hpp => PyCXpress/include/PyCXpress/utils.hpp} (100%) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 7b1f3d3..3a32747 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,7 +4,7 @@ "name": "Linux", "includePath": [ "${workspaceFolder}/**", - "${workspaceFolder}/src/cpp", + "${workspaceFolder}/src/PyCXpress/include", "/opt/conda/envs/py38/include/python3.8", "/opt/conda/envs/py38/lib/python3.8/site-packages/pybind11/include" ], diff --git a/.vscode/launch.json b/.vscode/launch.json index 4f2cf2e..2103acf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,13 +5,13 @@ "version": "0.2.0", "configurations": [ { - "name": "(gdb) 启动", + "name": "(gdb) on Example", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/example/example.out", + "program": "${workspaceFolder}/src/PyCXpress/example/example.out", "args": [], "stopAtEntry": false, - "cwd": "${workspaceFolder}/example", + "cwd": "${workspaceFolder}/src/PyCXpress/example/", "environment": [{ "name": "PATH", "value": "/opt/conda/envs/py38/bin" diff --git a/.vscode/settings.json b/.vscode/settings.json index 529fc19..542b4d9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "./src/python" ], "files.associations": { - "tuple": "cpp" + "tuple": "cpp", + "array": "cpp" } } \ No newline at end of file diff --git a/Makefile b/Makefile index 81375b0..a7fb1eb 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,22 @@ #* Variables SHELL := /usr/bin/env bash -PYTHON := python -PYTHONPATH := `pwd` -CXX_SOURCES = $(shell find . -name '*.cpp' -o -name '*.cxx' -o -name '*.cc' -o -name '*.c++' -o -name '*.hpp' -o -name '*.h') +THIS_MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST))) +REPO_DIR := $(patsubst %/,%,$(dir $(THIS_MAKEFILE))) +REPO_PREFIX := ../$(notdir $(abspath $(REPO_DIR))) + +PYTHON := python3 +PYTHONPATH := $(REPO_DIR)/src + +CXX_SOURCES = $(shell find $(REPO_DIR) -name '*.cpp' -o -name '*.cxx' -o -name '*.cc' -o -name '*.c++' -o -name '*.hpp' -o -name '*.h') + +#* Makefile debugging +print-%: ; @$(warning $* is $($*) ($(value $*)) (from $(origin $*))) + +define message +@echo -n "make[top]: " +@echo $(1) +endef #* Poetry .PHONY: poetry-download @@ -104,7 +117,7 @@ pytestcache-remove: .PHONY: build-dist build-dist: - poetry run python -m build --outdir dist/ + $(PYTHON) -m build --outdir dist/ .PHONY: build-remove build-remove: diff --git a/poetry.lock b/poetry.lock index 90ee89f..30d7fa6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -112,31 +112,6 @@ d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"] jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] uvloop = ["uvloop (>=0.15.2)"] -[[package]] -name = "build" -version = "1.2.1" -description = "A simple, correct Python build frontend" -optional = false -python-versions = ">=3.8" -files = [ - {file = "build-1.2.1-py3-none-any.whl", hash = "sha256:75e10f767a433d9a86e50d83f418e83efc18ede923ee5ff7df93b6cb0306c5d4"}, - {file = "build-1.2.1.tar.gz", hash = "sha256:526263f4870c26f26c433545579475377b2b7588b6f1eac76a001e873ae3e19d"}, -] - -[package.dependencies] -colorama = {version = "*", markers = "os_name == \"nt\""} -importlib-metadata = {version = ">=4.6", markers = "python_full_version < \"3.10.2\""} -packaging = ">=19.1" -pyproject_hooks = "*" -tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} - -[package.extras] -docs = ["furo (>=2023.08.17)", "sphinx (>=7.0,<8.0)", "sphinx-argparse-cli (>=1.5)", "sphinx-autodoc-typehints (>=1.10)", "sphinx-issues (>=3.0.0)"] -test = ["build[uv,virtualenv]", "filelock (>=3)", "pytest (>=6.2.4)", "pytest-cov (>=2.12)", "pytest-mock (>=2)", "pytest-rerunfailures (>=9.1)", "pytest-xdist (>=1.34)", "setuptools (>=42.0.0)", "setuptools (>=56.0.0)", "setuptools (>=56.0.0)", "setuptools (>=67.8.0)", "wheel (>=0.36.0)"] -typing = ["build[uv]", "importlib-metadata (>=5.1)", "mypy (>=1.9.0,<1.10.0)", "tomli", "typing-extensions (>=3.7.4.3)"] -uv = ["uv (>=0.1.18)"] -virtualenv = ["virtualenv (>=20.0.35)"] - [[package]] name = "certifi" version = "2024.2.2" @@ -595,25 +570,6 @@ files = [ {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, ] -[[package]] -name = "importlib-metadata" -version = "7.1.0" -description = "Read metadata from Python packages" -optional = false -python-versions = ">=3.8" -files = [ - {file = "importlib_metadata-7.1.0-py3-none-any.whl", hash = "sha256:30962b96c0c223483ed6cc7280e7f0199feb01a0e40cfae4d4450fc6fab1f570"}, - {file = "importlib_metadata-7.1.0.tar.gz", hash = "sha256:b78938b926ee8d5f020fc4772d487045805a55ddbad2ecf21c6d60938dc7fcd2"}, -] - -[package.dependencies] -zipp = ">=0.5" - -[package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] -perf = ["ipython"] -testing = ["flufl.flake8", "importlib-resources (>=1.3)", "jaraco.test (>=5.4)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy", "pytest-perf (>=0.9.2)", "pytest-ruff (>=0.2.1)"] - [[package]] name = "iniconfig" version = "2.0.0" @@ -1189,20 +1145,6 @@ typing-extensions = {version = ">=3.10.0", markers = "python_version < \"3.10\"" spelling = ["pyenchant (>=3.2,<4.0)"] testutils = ["gitpython (>3)"] -[[package]] -name = "pyproject-hooks" -version = "1.0.0" -description = "Wrappers to call pyproject.toml-based build backend hooks." -optional = false -python-versions = ">=3.7" -files = [ - {file = "pyproject_hooks-1.0.0-py3-none-any.whl", hash = "sha256:283c11acd6b928d2f6a7c73fa0d01cb2bdc5f07c57a2eeb6e83d5e56b97976f8"}, - {file = "pyproject_hooks-1.0.0.tar.gz", hash = "sha256:f271b298b97f5955d53fb12b72c1fb1948c22c1a6b70b315c54cedaca0264ef5"}, -] - -[package.dependencies] -tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} - [[package]] name = "pytest" version = "8.1.1" @@ -1520,13 +1462,13 @@ typing-extensions = ">=4.7.1" [[package]] name = "setuptools" -version = "69.5.0" +version = "69.5.1" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-69.5.0-py3-none-any.whl", hash = "sha256:3b2dbd8f63dcc6b7c327d0243c2d7dc8c96cc507c016f09221f3787e6e528719"}, - {file = "setuptools-69.5.0.tar.gz", hash = "sha256:8d881f842bfc0e29e93bc98a2e650e8845609adff4d2989ba6c748e67b09d5be"}, + {file = "setuptools-69.5.1-py3-none-any.whl", hash = "sha256:c636ac361bc47580504644275c9ad802c50415c7522212252c033bd15f301f32"}, + {file = "setuptools-69.5.1.tar.gz", hash = "sha256:6c1fccdac05a97e598fb0ae3bbed5904ccb317337a51139dcd51453611bbb987"}, ] [package.extras] @@ -1668,22 +1610,7 @@ platformdirs = ">=3.9.1,<5" docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"] -[[package]] -name = "zipp" -version = "3.18.1" -description = "Backport of pathlib-compatible object wrapper for zip files" -optional = false -python-versions = ">=3.8" -files = [ - {file = "zipp-3.18.1-py3-none-any.whl", hash = "sha256:206f5a15f2af3dbaee80769fb7dc6f249695e940acca08dfb2a4769fe61e538b"}, - {file = "zipp-3.18.1.tar.gz", hash = "sha256:2884ed22e7d8961de1c9a05142eb69a247f120291bc0206a00a7642f09b5b715"}, -] - -[package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] -testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ignore-flaky", "pytest-mypy", "pytest-ruff (>=0.2.1)"] - [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "78983f094db923a95e663942f3e45b4f351a92795970c90ec7586a058321474f" +content-hash = "8193a02a1aa5dee0c7e18950f25b6cfcc9ed8b84f70b511a236c220d242feb40" diff --git a/pyproject.toml b/pyproject.toml index e323655..d24d6ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "PyCXpress" -version = "0.0.2" +version = "0.0.3" description = "PyCXpress is a high-performance hybrid framework that seamlessly integrates Python and C++ to harness the flexibility of Python and the speed of C++ for efficient and expressive computation, particularly in the realm of deep learning and numerical computing." readme = "README.md" authors = ["chaoqing "] @@ -15,17 +15,13 @@ homepage = "https://github.com/chaoqing/PyCXpress" packages = [ { include = "PyCXpress", from = "src" }, ] -include = [ - { path = "src/cpp/", format = ["sdist", "wheel"] }, - { path = "example/", format = ["sdist", "wheel"] }, -] # Keywords description https://python-poetry.org/docs/pyproject/#keywords -keywords = [] #! Update me +keywords = ["CPP", "Embdedding"] # Pypi classifiers: https://pypi.org/classifiers/ -classifiers = [ #! Update me +classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Operating System :: OS Independent", @@ -38,7 +34,7 @@ classifiers = [ #! Update me [tool.poetry.scripts] # Entry points for the package https://python-poetry.org/docs/pyproject/#scripts -"PyCXpress" = "PyCXpress.__main__:main" +"pycxpress" = "PyCXpress.__main__:main" [tool.poetry.dependencies] python = "^3.8" @@ -144,7 +140,7 @@ addopts = [ source = ["tests"] [coverage.paths] -source = "PyCXpress" +source = "src" [coverage.run] branch = true diff --git a/requirements.txt b/requirements.txt index ffc6b33..c4deefe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,2 @@ -click==8.1.7 ; python_version >= "3.8" and python_version < "4.0" -colorama==0.4.6 ; python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows" -markdown-it-py==3.0.0 ; python_version >= "3.8" and python_version < "4.0" -mdurl==0.1.2 ; python_version >= "3.8" and python_version < "4.0" -pygments==2.17.2 ; python_version >= "3.8" and python_version < "4.0" -rich==13.7.1 ; python_version >= "3.8" and python_version < "4.0" -shellingham==1.5.4 ; python_version >= "3.8" and python_version < "4.0" -typer[all]==0.12.3 ; python_version >= "3.8" and python_version < "4.0" -typing-extensions==4.11.0 ; python_version >= "3.8" and python_version < "4.0" +numpy==1.24.4 ; python_version >= "3.8" and python_version < "4.0" +pybind11==2.12.0 ; python_version >= "3.8" and python_version < "4.0" diff --git a/example/Makefile b/src/PyCXpress/example/Makefile similarity index 89% rename from example/Makefile rename to src/PyCXpress/example/Makefile index 332b5d2..03feb75 100644 --- a/example/Makefile +++ b/src/PyCXpress/example/Makefile @@ -5,7 +5,7 @@ CC = c++ CFLAGS = -g -Wall -std=c++17 -fPIC CFLAGS = -I../src/cpp CFLAGS += $(shell python3-config --cflags --ldflags --embed) -CFLAGS += $(shell PYTHONPATH=../src/ python3 -m PyCXpress --includes) -I ../src/include +CFLAGS += $(shell PYTHONPATH=../../ python3 -m PyCXpress --includes) # The build target executable TARGET = example.out diff --git a/example/main.cpp b/src/PyCXpress/example/main.cpp similarity index 95% rename from example/main.cpp rename to src/PyCXpress/example/main.cpp index 4ad6b72..a336c57 100644 --- a/example/main.cpp +++ b/src/PyCXpress/example/main.cpp @@ -3,8 +3,8 @@ #include #define PYBIND11_DETAILED_ERROR_MESSAGES -#include -#include +#include +#include namespace pcx = PyCXpress; diff --git a/example/model.py b/src/PyCXpress/example/model.py similarity index 100% rename from example/model.py rename to src/PyCXpress/example/model.py diff --git a/src/cpp/PyCXpress.hpp b/src/PyCXpress/include/PyCXpress/core.hpp similarity index 92% rename from src/cpp/PyCXpress.hpp rename to src/PyCXpress/include/PyCXpress/core.hpp index 59a515d..3707853 100644 --- a/src/cpp/PyCXpress.hpp +++ b/src/PyCXpress/include/PyCXpress/core.hpp @@ -10,13 +10,22 @@ #include #include -#include "Utils.hpp" +#include "utils.hpp" + +#if !defined(PYCXPRESS_EXPORT) +# if defined(WIN32) || defined(_WIN32) +# define PYCXPRESS_EXPORT __declspec(dllexport) +# else +# define PYCXPRESS_EXPORT __attribute__((visibility("default"))) +# endif +#endif namespace PyCXpress { namespace py = pybind11; using namespace utils; -class Buffer { +class PYCXPRESS_EXPORT +Buffer { typedef unsigned char Bytes; template @@ -70,6 +79,9 @@ class Buffer { } else if (data_type == "double") { m_converter = __to_array; m_length /= sizeof(double); + } else if (data_type == "char") { + m_converter = __to_array; + m_length /= sizeof(char); } else { throw NotImplementedError(data_type); } @@ -104,7 +116,8 @@ class Buffer { py::array (*m_converter)(const std::vector &, void *); }; -class PythonInterpreter { +class PYCXPRESS_EXPORT +PythonInterpreter { public: explicit PythonInterpreter(bool init_signal_handlers = true, int argc = 0, const char *const *argv = nullptr, @@ -178,7 +191,7 @@ class PythonInterpreter { auto meta = d->cast(); m_buffers.insert(std::make_pair( meta[0].cast(), - Buffer{meta[2].cast(), meta[1].cast()})); + Buffer{meta[2].cast(), meta[1].cast()})); } for (auto d = output_fields.begin(); d != output_fields.end(); d++) { diff --git a/src/cpp/Utils.hpp b/src/PyCXpress/include/PyCXpress/utils.hpp similarity index 100% rename from src/cpp/Utils.hpp rename to src/PyCXpress/include/PyCXpress/utils.hpp