Skip to content

Commit

Permalink
Now shipping fhash in the thirdparty directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
nakib committed Nov 7, 2024
1 parent 755f499 commit 53ffd58
Show file tree
Hide file tree
Showing 47 changed files with 5,028 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ source-dir="src"
[dependencies]
#Pull from github
#testify = { git = "git@github.com:nakib/testify.git" }
#Use local copy
testify = {path = "thirdparty/testify"}
fhash = { git = "https://github.com/LKedward/fhash.git" }
#Pull from github
#fhash = {git = "https://github.com/LKedward/fhash.git"}
#Use local copy
fhash = {path = "thirdparty/fhash"}

#Use local copy from thirdparty directory
spglib = {path = "thirdparty/spglib"}
Expand Down
31 changes: 31 additions & 0 deletions thirdparty/fhash/.github/workflows/deploy_api_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build FORD docs & deploy to gh-pages
on:
push:
branches:
- master

jobs:
build:
name: Deploy docs
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: python -m pip install --upgrade pip ford

- name: Checkout master
uses: actions/checkout@v1

- name: Build docs
run: ford ford.md

- name: Deploy
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: api-doc
84 changes: 84 additions & 0 deletions thirdparty/fhash/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: fpm test

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
toolchain:
- {compiler: gcc, version: 10}
include:
- os: ubuntu-latest
toolchain: {compiler: intel, version: '2023.1'}
- os: ubuntu-latest
toolchain: {compiler: gcc, version: 12}

steps:
- uses: awvwgk/setup-fortran@v1
id: setup-fortran
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}

- run: ${{ env.FC }} --version
env:
FC: ${{ steps.setup-fortran.outputs.fc }}

- name: Install fpm
uses: fortran-lang/setup-fpm@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
uses: actions/checkout@v1

- name: Run tests and demo programs (debug)
run: |
fpm test
fpm run *-demo
- name: Run tests and demo programs (release)
run: |
fpm test --profile release
fpm run *-demo --profile release
gfortran-windows-msys2-mingw64:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Setup MinGW (MSYS2)
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: false
install: >-
git
wget
mingw-w64-x86_64-gcc-fortran
- name: Install fpm
shell: msys2 {0}
run: |
wget https://github.com/awvwgk/mingw-w64-fpm-pkgbuild/releases/download/current/mingw-w64-x86_64-fpm-0.2.0-1-any.pkg.tar.zst
pacman -U --noconfirm mingw-w64-x86_64-fpm-*-any.pkg.tar.zst
- name: Run tests and demo programs (debug)
shell: msys2 {0}
run: |
gfortran --version
fpm test
fpm run *-demo
- name: Run tests and demo programs (release)
shell: msys2 {0}
run: |
gfortran --version
fpm test --profile release
fpm run *-demo --profile release
5 changes: 5 additions & 0 deletions thirdparty/fhash/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build*
api-doc*
*~
.\#*
\#*\#
138 changes: 138 additions & 0 deletions thirdparty/fhash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
cmake_minimum_required(VERSION 3.0.2)

project(fhash Fortran)

if(DEFINED CMAKE_Fortran_COMPILER_VERSION)
set(Fortran_MODULE_DIRECTORY include/fortran_modules/${CMAKE_Fortran_COMPILER_ID}/${CMAKE_Fortran_COMPILER_VERSION})
else()
set(Fortran_MODULE_DIRECTORY include/fortran_modules/${CMAKE_Fortran_COMPILER_ID})
endif()

set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${Fortran_MODULE_DIRECTORY})

add_subdirectory(src)

include(CMakePackageConfigHelpers)

# Add all targets to the build-tree export set
export(TARGETS fhash
FILE "${PROJECT_BINARY_DIR}/fhashTargets.cmake")

# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE fhash)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/fhashConfig.cmake"
INSTALL_DESTINATION lib/cmake/fhash
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/fhashConfig.cmake"
DESTINATION lib/cmake/fhash
)

install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ DESTINATION ${Fortran_MODULE_DIRECTORY})

install(EXPORT fhash
FILE fhashTargets.cmake
DESTINATION lib/cmake/fhash
)

# -------------------
# Build documentation
# -------------------

set ( SKIP_DOC_GEN FALSE CACHE BOOL
"Disable building the API documentation with FORD" )
if ( NOT SKIP_DOC_GEN )
find_program(FORD ford)

find_package(PythonInterp)

if(NOT PYTHON_VERSION_STRING VERSION_LESS 3.5)
set(MARKDOWN_SUPPORTED_PYTHON true)
endif()

if(NOT MARKDOWN_SUPPORTED_PYTHON)
message(WARNING "Python version ${PYTHON_VERSION_STRING} is not supported by Python-Markdown, not attempting to build documentation.")
endif()

if(FORD AND MARKDOWN_SUPPORTED_PYTHON)

set(DOC_ROOT "${PROJECT_BINARY_DIR}/doc")
set(DOC_DIR "${DOC_ROOT}/fhash")
set(PROJ_DIR "${PROJECT_SOURCE_DIR}")
set(FORD_PROJECT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ford.md")
set(FORD_PROJECT_EXCLUDE_DIRS "${MPI_Fortran_INCLUDE_DIRS};${PROJECT_BINARY_DIR};${PROJ_DIR}/build;${PROJ_DIR}/tests;${PROJ_DIR}/sphinx")
set(FORD_PROJECT_EXCLUDE_FILES "random.f90;random_integer.f90")
set(MACRO_FLAG "")
string(REPLACE ";" "\ninclude:" FORD_PROJECT_INCLUDES "${PROJ_DIR}/src")
string(REPLACE ";" "\nexclude_dir:" FORD_PROJECT_EXCLUDE_DIRS "${FORD_PROJECT_EXCLUDE_DIRS}")
string(REPLACE ";" "\nexclude:" FORD_PROJECT_EXCLUDE_FILES "${FORD_PROJECT_EXCLUDE_FILES}")

# Pick the preprocessor to use based on the Fortran compiler
if ( "${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel" )
set ( FPP "fpp\n" )
else ()
set ( FPP "gfortran -E\n" ) # default to gfortran -E for gfortran and unsupported compilers
endif ()
file ( WRITE "${PROJECT_BINARY_DIR}/.PREPROCESSOR" "${FPP}" )

# Dynamically generate the FORD outputs list
message ( STATUS "Dynamically computing FORD output information..." )
if ( NOT (DEFINED FORD_OUTPUTS_CACHED) )
message ( STATUS "Running FORD to dynamically compute documentation outputs, this could take a while..." )
execute_process ( COMMAND ${CMAKE_COMMAND} -E remove_directory ${DOC_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${DOC_DIR}
COMMAND "${FORD}" --debug -q ${MACRO_FLAG} -d "${PROJ_DIR}" -o "${DOC_DIR}" -p "${PAGE_DIR}" "${FORD_PROJECT_FILE}" OUTPUT_QUIET )
else ()
message ( STATUS "Re-using cached FORD outputs, rather than regenerating them" )
endif()

# Compile a list of FORD output files
file ( GLOB_RECURSE FORD_OUTPUTS
"${DOC_DIR}/*.*" )
file ( GLOB_RECURSE FORD_CLEAN_OUTPUTS
"${DOC_DIR}/*.*" )

# Cache FORD outputs
if ( (DEFINED FORD_OUTPUTS) AND ( NOT ( "${FORD_OUTPUTS}" STREQUAL "" ) ) )
message ( STATUS "Caching FORD outputs" )
set ( FORD_OUTPUTS_CACHED "${FORD_OUTPUTS}"
CACHE STRING "variable containing FORD outputs to prevent rebuilding FORD docs" FORCE )
endif ()
message ( STATUS "Done dynamically computing FORD outputs." )

foreach ( DOC_SRC_FILE ${PROJECT_SOURCE_DIR}/ford.md ${FHASH_SOURCES} )
list ( APPEND FORD_DEPENDS "${DOC_SRC_FILE}" )
endforeach ()

# Re-build FORD output if needed
add_custom_command ( OUTPUT ${FORD_OUTPUTS_CACHED}
COMMAND "${FORD}" --debug ${MACRO_FLAG} -d "${PROJ_DIR}" -o "${DOC_DIR}" "${FORD_PROJECT_FILE}"
MAIN_DEPENDENCY "${FORD_PROJECT_FILE}"
DEPENDS ${FORD_DEPENDS}
COMMENT "Building HTML documentation for ${PROJECT_NAME} using FORD" )

add_custom_target ( documentation ALL
DEPENDS ${FORD_OUTPUTS_CACHED} )

# Install documentation
set ( INSTALL_API_DOCUMENTATION TRUE
CACHE BOOL "Install FORD generated documentation?" )
if ( INSTALL_API_DOCUMENTATION )
install ( DIRECTORY "${DOC_ROOT}/" DESTINATION share/doc )
else ()

# FORD Not found
message ( WARNING
"FORD not found. Please set the CMake cache variable FORD to point to the installed FORD executable, and reconfigure or disable building the documentation. FORD can be installed from PYPI with `sudo pip install FORD` or from <https://github.com/cmacmackin/ford> If you do not wish to install FORD and build the JSON-Fortran documentation, then please set the CMake cache variable SKIP_DOC_GEN to TRUE." )

endif ()
endif ()

endif()

enable_testing()
add_subdirectory(test)
9 changes: 9 additions & 0 deletions thirdparty/fhash/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/fhashTargets.cmake")

include(CMakeFindDependencyMacro)

check_required_components(fhash)

set(fhash_DOCDIR @CMAKE_INSTALL_PREFIX@/share/doc/fhash)
21 changes: 21 additions & 0 deletions thirdparty/fhash/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Laurence Kedward

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions thirdparty/fhash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# fhash
__[fpm](https://github.com/fortran-lang/fpm) package implementing a hash table with support for generic keys and values.__

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![fpm test](https://github.com/LKedward/fhash/workflows/fpm%20test/badge.svg?branch=master&event=push)](https://github.com/LKedward/fhash/actions)
[![ford docs](https://img.shields.io/badge/FORD%20API%20Docs-Deployed-green)](https://lkedward.github.io/fhash/)



## fpm usage

To use *fhash* within your *fpm* project, add the following to your package manifest file (`fpm.toml`):

```toml
[dependencies]
fhash = { git = "https://github.com/LKedward/fhash.git" }
```


## Simple example: scalar intrinsics

The package provides a `fhash_tbl_t` type with `set` and `get` methods for storing and retrieving key-value pairs.
The `fhash_key` interface (aliased to `key` below) is used to define a valid key from different inputs.

```fortran
program fhash_demo1
use fhash, only: fhash_tbl_t, key=>fhash_key
implicit none
type(fhash_tbl_t) :: tbl
integer :: val
call tbl%set(key('my_key_1'), value=10)
call tbl%set(key('my_key_2'), value=1.0)
call tbl%set(key(123456), value='a string value')
call tbl%set(key([1,2,3,4,5]), value=.false.)
call tbl%get(key('my_key_1'),val)
end program fhash_demo1
```

See the [Quickstart Guide](https://lkedward.github.io/fhash/page/index.html) for an explanation of this example and the API methods used.


## Advanced usage

- [More table methods](https://lkedward.github.io/fhash/page/1-methods-demo/index.html)
- [Storing custom derived types as values](https://lkedward.github.io/fhash/page/2-derived-type-demo/index.html)
- [Using custom derived types as keys](https://lkedward.github.io/fhash/page/3-custom-key-demo/index.html)


See <https://lkedward.github.io/fhash/> for the full API documentation.
31 changes: 31 additions & 0 deletions thirdparty/fhash/app/0-simple-demo/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
!> Example program demonstrating basic set/get usage
!> for different key/value types
program fhash_demo
use fhash, only: fhash_tbl_t, key=>fhash_key
implicit none

type(fhash_tbl_t) :: tbl
integer :: i
real :: r
character(:), allocatable :: char
logical :: bool

print *, '# fhash demo program: simple-demo'

call tbl%set(key('my_key_1'), value=10)
call tbl%set(key('my_key_2'), value=1.0)
call tbl%set(key(123456), value='a string value')
call tbl%set(key([1,2,3,4,5]), value=.false.)

call tbl%get(key('my_key_1'),i)
call tbl%get(key('my_key_2'),r)
call tbl%get(key(123456),char)
call tbl%get(key([1,2,3,4,5]),bool)

print *, 'Key = "my_key_1" Value = ',i
print *, 'Key = "my_key_2" Value = ',r
print *, 'Key = 123456 Value = "',char,'"'
print *, 'Key = [1,2,3,4,5] Value = ', bool
print *

end program fhash_demo
Loading

0 comments on commit 53ffd58

Please sign in to comment.