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

Install #11

Merged
merged 4 commits into from
Aug 31, 2022
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
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
- name: Install dependencies
if: startsWith(matrix.os, 'macos')
run: brew install cmake llvm@12 fmt pybind11
- name: Install python dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install flake8 pytest
- name: Configure
run: |
cmake -S . -B ${{ github.workspace }}/build \
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@

# cmake
build/*

# python
__pycache__
python/src/pyfprops.egg-info
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
cmake_minimum_required(VERSION VERSION 3.16)

project(fprops)
project(
fprops
VERSION 0.1
LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

include(FetchContent)

Expand Down
5 changes: 5 additions & 0 deletions cmake/fpropsConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include(CMakeFindDependencyMacro)

find_dependency(fmt REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/fpropsTargets.cmake")
18 changes: 17 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
add_subdirectory(fprops)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
find_program(PYTHON "python" REQUIRED)

configure_file(setup.py.in setup.py)
install(CODE "execute_process(COMMAND ${PYTHON} -m pip install ${CMAKE_CURRENT_BINARY_DIR})")

add_subdirectory(src)

if (FPROPS_BUILD_TESTS)
find_program(PYTEST "pytest" REQUIRED)
enable_testing()
add_test(
NAME pyfprops-test
COMMAND ${PYTEST} ${CMAKE_CURRENT_SOURCE_DIR}
)
set_tests_properties(pyfprops-test PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/src:$ENV{PYTHONPATH}")
endif()
8 changes: 8 additions & 0 deletions python/setup.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from setuptools import Extension, setup

setup(
name='pyfprops',
version='${PROJECT_VERSION}',
packages=['pyfprops'],
package_dir={ '': '${CMAKE_CURRENT_SOURCE_DIR}/src' }
)
8 changes: 7 additions & 1 deletion python/fprops/CMakeLists.txt → python/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(pyfprops LANGUAGES CXX)

find_package(pybind11 REQUIRED)

pybind11_add_module(pyfprops fprops.cpp)
pybind11_add_module(${PROJECT_NAME} fprops.cpp)

target_include_directories(
${PROJECT_NAME}
Expand All @@ -17,3 +17,9 @@ target_link_libraries(
PUBLIC
fprops
)

install(
TARGETS ${PROJECT_NAME}
COMPONENT python
LIBRARY DESTINATION "${Python3_SITELIB}/pyfprops"
)
File renamed without changes.
6 changes: 6 additions & 0 deletions python/src/pyfprops/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .pyfprops import *

__all__ = [
IdealGas,
Nitrogen
]
14 changes: 14 additions & 0 deletions python/tests/test_nitrogen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pyfprops as fp
import pytest

def test_n2_valid():
n2 = fp.Nitrogen()
state = n2.p_T(1e6, 280)
assert state.p == 1e6
assert state.T == 280
assert state.rho == 12.074993445601923

def test_n2_invalid():
with pytest.raises(RuntimeError):
n2 = fp.Nitrogen()
state = n2.p_T(0.1e6, 60)
47 changes: 40 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
project(
fprops
VERSION 0.1
LANGUAGES CXX
)

add_library(${PROJECT_NAME}
add_library(
${PROJECT_NAME}
SHARED
BrentsMethod.cpp
FluidProperties.cpp
Expand Down Expand Up @@ -33,3 +28,41 @@ target_link_libraries(
PUBLIC
fmt::fmt
)

install(
TARGETS fprops
EXPORT fpropsTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fprops
FILES_MATCHING PATTERN "*.h"
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
fpropsConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(
EXPORT fpropsTargets
FILE fpropsTargets.cmake
NAMESPACE fprops::
DESTINATION lib/cmake/fprops
)

install(
FILES
"${CMAKE_SOURCE_DIR}/cmake/fpropsConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/fpropsConfigVersion.cmake"
DESTINATION
lib/cmake/${PROJECT_NAME}
)