Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ indent_size = 4
# Markdown documentation
[*.md]
trim_trailing_whitespace = false

# Makefile
[{Makefile,**.mk}]
indent_style = tab
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.18)

set(PYCADES_VERSION "0.1.70200")
set(PYCADES_VERSION "0.1.70300")
project(PythonModule
LANGUAGES CXX
VERSION ${PYCADES_VERSION}
Expand All @@ -17,6 +17,7 @@ endif()

find_package(Python3 REQUIRED COMPONENTS Development.Module)
find_package(Boost REQUIRED)
find_package(Patch REQUIRED)

execute_process(
COMMAND bash -c "if type dpkg > /dev/null 2>&1; then dpkg -l|grep cprocsp-pki-cades|awk ' { print $3 } '; else rpm -qa|grep cprocsp-pki-cades; fi|cut -d. -f1|cut -d- -f1"
Expand Down
37 changes: 34 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,48 @@ help: ## Display this help screen
@grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: clean
clean: clean-build ## Clean project
clean: clean-build clean-test clean-pyc ## Clean project

.PHONY: clean-build
clean-build:
rm -fr build
rm -fr build/
rm -fr dist/
rm -fr .eggs/
rm -fr .mypy_cache
rm -fr .ruff_cache
rm -rf .py-build-cmake_cache
rm -fr samples/*.so
find . -name '*.egg-info' -not -path '.venv/*' -exec rm -fr {} +
find . -name '*.egg' -not -path '.venv/*' -exec rm -f {} +

.PHONY: clean-pyc
clean-pyc:
find . -name '*.pyc' -not -path '.venv/*' -exec rm -f {} +
find . -name '*.pyo' -not -path '.venv/*' -exec rm -f {} +
find . -name '*~' -not -path '.venv/*' -exec rm -f {} +
find . -name '__pycache__' -not -path '.venv/*' -exec rm -fr {} +

.PHONY: clean-test
clean-test:
rm -fr .tox/
rm -fr .nox/
rm -f .coverage
rm -fr htmlcov/

.PHONY: library
library: build-library ## Build shared library

.PHONY: build-library
build-library: ## Build shared library
build-library:
cmake -S . -B build
cmake --build build -j$$(nproc)

.PHONY: rebuild-library
rebuild-library: clean build-library ## Clean and rebuild the library from scratch

.PHONY: package
package: build-package ## Build python package

.PHONY: build-package
build-package: clean
uv build
19 changes: 19 additions & 0 deletions patches/001-rename-lib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/src/PyCades.cpp b/src/PyCades.cpp
index 117bc8e..58feaea 100755
--- a/src/PyCades.cpp
+++ b/src/PyCades.cpp
@@ -48,11 +48,11 @@ static PyMethodDef pycadesMethods[] = {
{"ModuleVersion", pycades_ModuleVersion, METH_NOARGS, "pycades module version"},
{NULL, NULL, 0, NULL} };

-PyMODINIT_FUNC PyInit_pycades(void) {
+PyMODINIT_FUNC PyInit__pycades(void) {
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
- "pycades",
- "pycades",
+ "_pycades",
+ NULL,
-1,
pycadesMethods,
NULL,
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[project]
name = "pycades"
dynamic = [ "version" ]
description = "The Pycades extension provides a programming interface similar to CryptoPro"
readme = "README.md"
authors = [
{ name = "CryptoPro LLC", email = "info@cryptopro.ru"}
]
maintainers = [
{ name = "cpsdenis", email = "sdenis@cryptopro.ru"}
]
license-files = ["LICENSE"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: POSIX :: Linux",
"Topic :: Software Development :: Libraries :: Python Modules",
]
requires-python = ">=3.9"
dependencies = []

[project.urls]
homepage = "https://docs.cryptopro.ru/cades/pycades"
documentation = "https://docs.cryptopro.ru/cades/pycades"
source = "https://github.com/CryptoPro/pycades"

[tool.py-build-cmake.module]
name = "pycades"
directory = "src"

[tool.py-build-cmake.sdist]
include = ["CMakeLists.txt", "patches/*", "src/*", "samples/*", "doc/*"]

[tool.py-build-cmake.cmake]
minimum_version = "3.18"
source_path = "."
build_args = ["-j"]
install_components = ["python_modules"]

# [tool.py-build-cmake.stubgen]

[build-system]
requires = ["py-build-cmake~=0.5.0"]
build-backend = "py_build_cmake.build"
63 changes: 53 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,58 @@ set(pycades_LIB_SRCS
PyCadesVersion.cpp PyEnrollContainer.cpp PyEnrollContainers.cpp PyEnrollContainerKey.cpp
PyEnrollContainerKeys.cpp PyEnrollCspInformation.cpp
)
add_library(pycades SHARED ${pycades_LIB_SRCS})

if(DEFINED PY_BUILD_CMAKE_IMPORT_NAME AND NOT "${PY_BUILD_CMAKE_IMPORT_NAME}" STREQUAL "")
set (TARGET_NAME "_pycades")

message("-- Applying ${CMAKE_CURRENT_SOURCE_DIR}/../patches/001-rename-lib.patch")

execute_process(
COMMAND ${Patch_EXECUTABLE} -p1 -i ${CMAKE_CURRENT_SOURCE_DIR}/../patches/001-rename-lib.patch
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.. # Подняться на уровень выше
RESULT_VARIABLE PATCH_RESULT
)

if(NOT PATCH_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to apply patch")
endif()

Python3_add_library(pycades MODULE ${pycades_LIB_SRCS} WITH_SOABI)

set_target_properties(pycades PROPERTIES
PREFIX ""
OUTPUT_NAME ${TARGET_NAME}
)

install(TARGETS pycades
EXCLUDE_FROM_ALL
COMPONENT python_modules
DESTINATION ${PY_BUILD_CMAKE_IMPORT_NAME})

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pycades.pyi
DESTINATION ${PY_BUILD_CMAKE_IMPORT_NAME}
RENAME _pycades.pyi
COMPONENT python_modules)

else()
set (TARGET_NAME "pycades")

add_library(pycades SHARED ${pycades_LIB_SRCS})

set_target_properties(pycades PROPERTIES
PREFIX ""
OUTPUT_NAME ${TARGET_NAME}
)

add_custom_command(TARGET pycades
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${TARGET_NAME}> "${CMAKE_SOURCE_DIR}/samples/"
COMMENT "Copying pycades module to samples directory"
)

endif()



target_compile_definitions(pycades PRIVATE
UNIX
Expand Down Expand Up @@ -46,10 +97,6 @@ target_include_directories(pycades PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/cplib
)

set_target_properties(pycades PROPERTIES
PREFIX ""
OUTPUT_NAME "pycades"
)

find_library(FOUND_LIB_CPPCADES
NAMES cppcades
Expand All @@ -64,8 +111,4 @@ target_link_libraries(pycades PRIVATE
${FOUND_LIB_CPLIB}
)

add_custom_command(TARGET pycades
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pycades> "${CMAKE_SOURCE_DIR}/samples/"
COMMENT "Copying pycades module to samples directory"
)

3 changes: 3 additions & 0 deletions src/pycades/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._pycades import *

__version__ = "0.1.70300"