Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ae6e72e
First fragile version of the simple file format with rudimentary pybi…
sflis Jan 20, 2020
b9d02f2
Only have one Archive streamer for the for the ICFFile object and upd…
sflis Jan 20, 2020
acb8a62
Adding more fields to the file header and writing a small script to t…
sflis Jan 22, 2020
4793bed
Added source file for easy env setting. Fixed typo in header.
sflis Jan 22, 2020
40f1f61
Working on project structure for sensible development and deployment
sflis Jan 31, 2020
c1b5027
Generating the setup.py with cmake magic using a two level template w…
sflis Jan 31, 2020
52e3c05
Added exceptions for the read_at method. Timestamps are now created u…
sflis Feb 1, 2020
87f94b1
Update, restore point
sflis Feb 10, 2020
8754140
Restore point dev
sflis Feb 13, 2020
b945261
update
sflis Feb 13, 2020
5a76931
Fixed wrong seek in file scan
sflis Feb 16, 2020
be4f921
Add RPath fix for custom install locations and add more tests
sflis Feb 18, 2020
f84139b
Merging with master and cleaning up build and dependencies
sflis Feb 20, 2020
eaaff18
CPP version of ICF now basically writes according to the specificatio…
sflis Feb 20, 2020
70b2db9
Minor fix to remove compiler warning
sflis Feb 20, 2020
a2a4067
Added test that tests the consistency between the c++ and python impl…
sflis Feb 21, 2020
a3c3e87
pip install almost works, still need to figure out how to handle the …
sflis Feb 21, 2020
a952a6a
Remove uneccesary steps from the pip install
sflis Feb 22, 2020
3673a3e
No need for setting the install prefix
sflis Mar 6, 2020
77e9baf
Fix pep8 compatible version strings
sflis Mar 6, 2020
0c83593
Undo changes to archive and propagate the version properly to setup.py
sflis Mar 6, 2020
1b55af6
Undo last change to archive
sflis Mar 6, 2020
bdf2319
Remove deps from build install
sflis Mar 6, 2020
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
178 changes: 178 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
cmake_minimum_required(VERSION 3.11...3.16)

project(icf VERSION 1.0 LANGUAGES CXX)
option(PYTHON_SETUP "If invoked by setup.py" OFF)
set(LIBTARGET ${PROJECT_NAME})
set(PYTARGET ${PROJECT_NAME}_py)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(EXISTS $ENV{CONDA_PREFIX})
set(CMAKE_INSTALL_PREFIX $ENV{CONDA_PREFIX})

endif()


if((APPLE) OR (EXISTS $ENV{CONDA_PREFIX}))
# The following settings were copied from
# https://cmake.org/Wiki/CMake_RPATH_handling
# to avoid the rpath issue (issue #11998) that appears on OS X El Capitan
# https://forge.in2p3.fr/issues/11998

# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
if(PYTHON_SETUP)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
else()
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
endif()

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()

find_package(Git QUIET)
# find_package(Python3 COMPONENTS Interpreter)
find_package(pybind11 QUIET)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include(CTest)
include(ExternalProject)

# Save executables to bin directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Dependencies
include(FetchContent)

if(NOT pybind11_FOUND)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG v2.4.3
GIT_SHALLOW TRUE
)

FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
FetchContent_Populate(pybind11)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()
endif()

if(NOT PYTHON_SETUP)
message(STATUS "${Cyan}doctest${ColourReset}")
FetchContent_Declare(
doctest
GIT_REPOSITORY https://github.com/onqtam/doctest
GIT_TAG 2.3.6
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(doctest)
if(NOT doctest_POPULATED)
FetchContent_Populate(doctest)
set(DOCTEST_WITH_TESTS OFF CACHE BOOL "No tests of doctests")
set(DOCTEST_NO_INSTALL ON CACHE BOOL "No doctest install")
add_subdirectory(${doctest_SOURCE_DIR} ${doctest_BINARY_DIR})
endif()
set(DOCTEST_INCLUDE_DIR ${doctest_SOURCE_DIR}/doctest CACHE INTERNAL "Path to include folder for doctest")
endif()


# src
add_library(${LIBTARGET} SHARED src/icfFile.cc)
target_include_directories(${LIBTARGET} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include/>
)
target_compile_features(${LIBTARGET} PUBLIC cxx_std_11)

if(PYTHON_SETUP AND NOT EXISTS $ENV{CONDA_PREFIX})
set_target_properties(${LIBTARGET}
PROPERTIES
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/icf/_ext/"
)
else()
install (TARGETS ${LIBTARGET} EXPORT icf-file-targets LIBRARY DESTINATION lib)
install (DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include)
endif()
# Makes it easier for IDEs to find all headers
source_group(TREE "${PROJECT_SOURCE_DIR}/include" PREFIX "Header Files" FILES ${HEADER_LIST})

#Get git version number
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=7
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(ICF_VERSION_LONG ${VERSION})
#parse the version information into pieces.
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" VERSION_SHA1 "${VERSION}")
set(ICF_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
message(STATUS ICF_VERSION)
configure_file( version_config.h.in ${CMAKE_BINARY_DIR}/generated/version_config.h )
include_directories( ${CMAKE_BINARY_DIR}/generated/)


# pybind
# set(PỲTARGET_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/icf/_ext/")
# message(${PYTARGET_OUTPUT_DIR})
pybind11_add_module(${PYTARGET} pybind/module.cc pybind/icfFile.cc)
target_link_libraries(${PYTARGET} PRIVATE ${LIBTARGET})
set_target_properties(${PYTARGET}
PROPERTIES
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/icf/_ext/"
)
if(NOT PYTHON_SETUP)
# Python stuff
# Creating a symlink to the python package
add_custom_command(TARGET ${PYTARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink "${PROJECT_SOURCE_DIR}/icf/" "${CMAKE_CURRENT_BINARY_DIR}/icf/_icf")
# Python stuff
# Creating a symlink to the python tests
add_custom_command(TARGET ${PYTARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink "${PROJECT_SOURCE_DIR}/pytest/" "${CMAKE_CURRENT_BINARY_DIR}/pytest")


if(Python3_Interpreter_FOUND)
add_test(NAME PythonTests COMMAND python3 -m pytest -r a -v WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pytest")
endif()


configure_file(setup.py.in "${PROJECT_BINARY_DIR}/setup.py")


# Place the initialization file in the output directory for the Python
# bindings. This will simplify the installation.
CONFIGURE_FILE(__init__.py
${CMAKE_CURRENT_BINARY_DIR}/icf/__init__.py
)


add_executable(test_icf ctests/test_icf.cc)# $<TARGET_OBJECTS:test_main>)
target_link_libraries(test_icf ${LIBTARGET})


# ctests
add_library(test_main OBJECT ctests/test_main.cc)
target_include_directories(test_main PUBLIC ${DOCTEST_INCLUDE_DIR})

add_executable(test_ICFFile ctests/ICFFile.cc $<TARGET_OBJECTS:test_main> )
add_test(NAME test_ICFFile COMMAND test_ICFFile)
target_link_libraries(test_ICFFile ${LIBTARGET})
target_include_directories(test_ICFFile PUBLIC ctests ${DOCTEST_INCLUDE_DIR})
target_compile_features(test_ICFFile PRIVATE cxx_std_11)

endif()
5 changes: 5 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ._icf import *
from ._ext.icf_py import *
from ._ext.icf_py import _get_version

__version__ = _get_version()
50 changes: 50 additions & 0 deletions ctests/ICFFile.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

#include "icf/icfFile.h"
#include "doctest.h"
#include <fstream>
#include <vector>
#include <iostream>
#include <chrono>

namespace icf {


TEST_CASE("ICFFile") {
icf::ICFFile icf_file(std::string("/tmp/test.icf"),ICFFile::trunc);
std::vector<uint8_t> data = {1,2,3,4,2,3,4};
auto n =3;
for(uint16_t i = 0; i<n; i++ ){
icf_file.write((void*)data.data(),data.size());
}
auto time_original = icf_file.get_timestamp();

SUBCASE("Consistency_while_writing") {

CHECK(icf_file.size() == n);

auto read_data = icf_file.read_at(1);
uint8_t *datar = (uint8_t*) read_data->data();
for(uint16_t i =0; i<data.size(); i++){
// std::cout<<data[i]<<" "<<datar[i]<<std::endl;
CHECK(data[i] == datar[i]);
}
}

icf_file.close();

SUBCASE("Consistency_while_reading") {
icf::ICFFile icf_file(std::string("/tmp/test.icf"));
CHECK(icf_file.size() == n);

auto read_data = icf_file.read_at(1);
uint8_t *datar = (uint8_t*) read_data->data();
for(uint16_t i =0; i<data.size(); i++){
// std::cout<<data[i]<<" "<<datar[i]<<std::endl;
CHECK(data[i] == datar[i]);
}
CHECK(time_original == icf_file.get_timestamp());
}

}

} // namespace icf
21 changes: 21 additions & 0 deletions ctests/test_icf.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>

#include "icf/icfFile.h"
#include <string>



int main(){

icf::ICFFile icf_file(std::string("test.icf"));
// std::cout<<icf_file.file_header_.file_identifier<<std::endl;
uint8_t data[] = {1,2,3,4,2,3,4};
icf_file.write((void*)data,7);
icf_file.write((void*)data,7);

auto read_data = icf_file.read_at(1);
std::cout<<(*read_data)[0]<<std::endl;
std::cout<<(*read_data)[1]<<std::endl;
std::cout<<(*read_data)[4]<<std::endl;

}
5 changes: 5 additions & 0 deletions ctests/test_main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2019 Cherenkov Telescope Array Observatory
// This software is distributed under the terms of the BSD-3-Clause license.

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
57 changes: 0 additions & 57 deletions examples/write_and_read.py

This file was deleted.

12 changes: 8 additions & 4 deletions icf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# from icf._icf import frame, pyicf
from . import frame, pyicf
from .frame import Frame
__version__ = "0.1.0"#_get_version()
from ._ext.icf_py import *
from ._ext.icf_py import _get_version

__version__ = _get_version()

# # from icf._icf import frame, pyicf
# from . import frame, pyicf
# from .frame import Frame
Loading