Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code #23

Merged
merged 8 commits into from
Oct 8, 2024
Merged
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
19 changes: 19 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
Language: Cpp
BasedOnStyle: Google

ColumnLimit: 100

BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
max_line_length = 100

[*.py]
indent_size = 4

[Makefile]
indent_style = tab

[CMakeLists.txt]
indent_size = 2

[*.{json,yml,yaml}]
indent_size = 2
63 changes: 31 additions & 32 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,37 @@ jobs:

steps:

- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get install -y build-essential python-dev-is-python3 python3-numpy python3-pytest

- name: Build library
run: make PYTHON=python

- name: Run library tests
run: make test PYTHON=python

- name: Copy library to docs/ directory
run: cp -r permanent/ docs/permanent/

- name: Build documentation
uses: ammaraskar/sphinx-action@master
with:
build-command: "make html"
docs-folder: "docs/"

- name: Fix documentation permissions
run: |
chmod -c -R +rX "docs/build/html/" | while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/build/html/
- uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get install -y build-essential cmake

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install .

- name: PyTest
run: |
pip install pytest
pytest -v tests

- name: Build documentation
run: |
pip install sphinx sphinx_rtd_theme sphinx_copybutton
cd docs && make html

- name: Fix documentation permissions
run: |
chmod -c -R +rX "docs/build/html/" | while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/build/html/

deploy:

Expand Down
63 changes: 31 additions & 32 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,34 @@ jobs:

steps:

- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get install -y build-essential python-dev-is-python3 python3-numpy python3-pytest

- name: Build library
run: make PYTHON=python

- name: Run library tests
run: make test PYTHON=python

- name: Copy library to docs/ directory
run: cp -r permanent/ docs/permanent/

- name: Build documentation
uses: ammaraskar/sphinx-action@master
with:
build-command: "make html"
docs-folder: "docs/"

- name: Fix documentation permissions
run: |
chmod -c -R +rX "docs/build/html/" | while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/build/html/
- uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get install -y build-essential cmake

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install .

- name: PyTest
run: |
pip install pytest
pytest -v tests

- name: Build documentation
run: |
pip install sphinx sphinx_rtd_theme sphinx_copybutton
cd docs && make html

- name: Fix documentation permissions
run: |
chmod -c -R +rX "docs/build/html/" | while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/build/html/
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ tags
.vscode/

# Project files
compile_flags.txt
src/tuning
src/tuning.h
src/tuning.csv
/include/permanent/tuning.h

# Language server files
compile_commands.json
.ccls-cache
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ repos:
hooks:
- id: cppcheck
args: ["--inline-suppr", "--suppress=missingIncludeSystem",
"--suppress=*:src/swap.h", "--suppress=*:src/perm-mv0.h", "--suppress=*:src/kperm-gray.h"]
"--suppress=*:include/permanent/swap.h", "--suppress=*:include/permanent/perm-mv0.h", "--suppress=*:include/permanent/kperm-gray.h"]
- id: cpplint
args: ["--root=src", "--filter=-build/include_subdir"]
- id: clang-format
args: ["-i", "-style={BasedOnStyle: google, IndentWidth: 4}"]
args: ["-i", "-style=file"]
186 changes: 186 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Supported CMake versions

cmake_minimum_required(VERSION 3.23 FATAL_ERROR)

# Project configuration

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(MatrixPermanent VERSION 0.0.1 LANGUAGES CXX)

if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed; make a build directory and run CMake from it\n")
endif()

if(ENV{PERMANENT_TUNE})
set(PERMANENT_TUNE ON)
endif()

if(SKBUILD OR ENV{PERMANENT_PYTHON})
set(PERMANENT_PYTHON ON)
endif()

# Dependencies

if(PROJECT_IS_TOP_LEVEL AND PERMANENT_PYTHON)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
elseif(PERMANENT_TUNE)
find_package(Python REQUIRED COMPONENTS Interpreter)
endif()

# Tuning header target

set(PERMANENT_TUNING_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/permanent/tuning.h")
set(PERMANENT_TUNING_DATA "${CMAKE_BINARY_DIR}/tuning.csv")

if(PERMANENT_TUNE)
add_executable(PermanentTune src/tuning.cc)
target_include_directories(PermanentTune PRIVATE include)

add_custom_target(TuningData ALL
COMMAND
PermanentTune "${PERMANENT_TUNING_DATA}"
BYPRODUCTS
"${PERMANENT_TUNING_DATA}")

add_custom_target(TuningHeader ALL
COMMAND
${Python_EXECUTABLE}
"${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_tuning_header.py"
"${PERMANENT_TUNING_DATA}"
"${PERMANENT_TUNING_HEADER}"
BYPRODUCTS
"${PERMANENT_TUNING_HEADER}")
add_dependencies(TuningHeader TuningData)
else()
add_custom_target(TuningHeader ALL
COMMAND
cp "-f"
"${CMAKE_CURRENT_SOURCE_DIR}/include/permanent/tuning.default.h"
"${PERMANENT_TUNING_HEADER}"
BYPRODUCTS
"${PERMANENT_TUNING_HEADER}")
endif()

# Header library target

add_library(permanent_headers INTERFACE)
add_library(MatrixPermanent::headers ALIAS permanent_headers)
add_dependencies(permanent_headers TuningHeader)
target_include_directories(permanent_headers
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

if(PROJECT_IS_TOP_LEVEL)
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(CPack)
write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
VERSION
${PROJECT_VERSION}
COMPATIBILITY
SameMajorVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

install(TARGETS permanent_headers
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

install(
EXPORT
${PROJECT_NAME}_Targets
FILE
${PROJECT_NAME}Targets.cmake
NAMESPACE
${PROJECT_NAME}::
DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

install(
FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

install(
DIRECTORY
${PROJECT_SOURCE_DIR}/include/permanent
DESTINATION
include)
endif()

# Python library target

if(PROJECT_IS_TOP_LEVEL AND PERMANENT_PYTHON)
execute_process(
COMMAND
sh -c "${CMAKE_CXX_COMPILER} --version | head -n 1"
WORKING_DIRECTORY
${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE
_PERMANENT_COMPILER_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process(
COMMAND
git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY
${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE
_PERMANENT_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process(
COMMAND
git log -1 --format=%h
WORKING_DIRECTORY
${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE
_PERMANENT_GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process(
COMMAND
${Python_EXECUTABLE} "-c" "import numpy; print(numpy.get_include())"
OUTPUT_VARIABLE
NumPy_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE)

python_add_library(permanent MODULE src/main.cc WITH_SOABI)
target_include_directories(permanent
PRIVATE
include
${NumPy_INCLUDE_DIRS})
target_compile_definitions(permanent
PRIVATE
"_PERMANENT_VERSION=${PROJECT_VERSION}"
"_PERMANENT_COMPILER_VERSION=${_PERMANENT_COMPILER_VERSION}"
"_PERMANENT_GIT_BRANCH=${_PERMANENT_GIT_BRANCH}"
"_PERMANENT_GIT_COMMIT_HASH=${_PERMANENT_GIT_COMMIT_HASH}"
)
if (UNIX)
if (APPLE)
set_target_properties(permanent
PROPERTIES
LINK_FLAGS "-Wl,-dylib,-undefined,dynamic_lookup")
else()
set_target_properties(permanent
PROPERTIES
LINK_FLAGS "-Wl,--allow-shlib-undefined")
endif()
endif()
install(TARGETS permanent DESTINATION .)
endif()
Loading