Skip to content

Commit

Permalink
Ditch sed for Python. Default AP_BASE_URL is empty string now.
Browse files Browse the repository at this point in the history
  • Loading branch information
kordejong committed Jan 31, 2025
1 parent 79f0396 commit 9b4bd2a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: |
mkdir build
cd build
cmake -S .. -G Ninja
cmake -S .. -G Ninja -D AP_BASE_URL PathwaysGenerator
- name: Build web app
run: |
cmake --build build --target web_app
Expand Down
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ enable_testing()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/environment/cmake)

set(AP_BASE_URL "PathwaysGenerator" CACHE STRING
"Base url for web app. Use empty string for testing locally."
set(AP_BASE_URL "" CACHE STRING
"Base url for web app. Use empty string (the default) for testing locally."
)

find_package(Flet REQUIRED)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
find_package(Quarto)
find_package(Sed)
find_package(Sphinx REQUIRED)

set(AP_PLOT_GRAPHS
Expand Down
13 changes: 0 additions & 13 deletions environment/cmake/FindSed.cmake

This file was deleted.

42 changes: 19 additions & 23 deletions source/package/pathways_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,22 @@ configure_file(
@ONLY
)

if(NOT Sed_FOUND)
# Sed is used to patch index.html.
message(WARNING "Skipping the web_app target since sed was not found")
else()
add_custom_target(web_app
COMMAND
${CMAKE_COMMAND} -E copy_directory_if_different
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
COMMAND
${CMAKE_COMMAND} -E env "PIP_FIND_LINKS=file://${PROJECT_BINARY_DIR}/dist"
${Flet_EXECUTABLE} build web ${CMAKE_CURRENT_BINARY_DIR}
COMMAND
${Sed_EXECUTABLE} -i -f ${CMAKE_CURRENT_SOURCE_DIR}/patch_index_html.sed
${CMAKE_CURRENT_BINARY_DIR}/build/web/index.html
COMMAND
${CMAKE_COMMAND} -E echo
"Run a command like this to start the web app:"
"${Python3_EXECUTABLE} -m http.server --directory ${CMAKE_CURRENT_BINARY_DIR}/build/web"
DEPENDS
package
VERBATIM
)
endif()
add_custom_target(web_app
COMMAND
${CMAKE_COMMAND} -E copy_directory_if_different
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
COMMAND
${CMAKE_COMMAND} -E env "PIP_FIND_LINKS=file://${PROJECT_BINARY_DIR}/dist"
${Flet_EXECUTABLE} build web ${CMAKE_CURRENT_BINARY_DIR}
COMMAND
${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/patch_index_html.py
${CMAKE_CURRENT_BINARY_DIR}/build/web/index.html
COMMAND
${CMAKE_COMMAND} -E echo
"Run a command like this to start the web app:"
"${Python3_EXECUTABLE} -m http.server --directory ${CMAKE_CURRENT_BINARY_DIR}/build/web"
DEPENDS
package
VERBATIM
)
44 changes: 44 additions & 0 deletions source/package/pathways_app/patch_index_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
from pathlib import Path

import docopt


def main() -> int:
command = Path(sys.argv[0]).name
usage = f"""\
Patch web app's index.html
Usage:
{command} <pathname>
Arguments:
pathname Pathname of index.html file to patch
Options:
-h --help Show this screen and exit
"""
status = 1

try:
arguments = sys.argv[1:]
arguments = docopt.docopt(usage, arguments)
html_pathname = arguments["<pathname>"] # type: ignore

search_for = '<script src="python.js"></script>'
replace_with = f'{search_for}\n <script src="js/pathways.js"></script>'

path = Path(html_pathname)
content = path.read_text(encoding="utf-8")
content = content.replace(search_for, replace_with)
path.write_text(content, encoding="utf-8")

status = 0
except Exception as exception:
sys.stderr.write(f"{exception}\n")

return status


if __name__ == "__main__":
sys.exit(main())
1 change: 0 additions & 1 deletion source/package/pathways_app/patch_index_html.sed

This file was deleted.

0 comments on commit 9b4bd2a

Please sign in to comment.