Skip to content

Commit d745ad6

Browse files
authored
Doc: Update stylesheets and clean up documentations (#8)
* Update stylesheets * Use uv for both doc and lib * Install glib outside config * Add argp for macos * Fix doc build * Use C++ 17
1 parent edc41d8 commit d745ad6

File tree

9 files changed

+1072
-61
lines changed

9 files changed

+1072
-61
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,68 @@ permissions:
77

88
jobs:
99
build:
10-
runs-on: ubuntu-latest
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, macos-latest, macos-14]
14+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
15+
1116
steps:
1217
- uses: actions/checkout@v4
18+
with:
19+
submodules: recursive
1320

14-
- name: Set up Python
15-
uses: actions/setup-python@v4
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v4
1623
with:
17-
python-version: "3.10"
24+
version: "latest"
1825

19-
- name: Init submodules
20-
run: git submodule update --init --recursive
26+
- name: Set up Python ${{ matrix.python-version }}
27+
run: uv python install ${{ matrix.python-version }}
2128

22-
- name: Prepare
23-
run: bash src/libCacheSim/scripts/install_dependency.sh
29+
- name: Install system dependencies (Ubuntu)
30+
if: matrix.os == 'ubuntu-latest'
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y pkg-config libglib2.0-dev libzstd-dev
2434
25-
- name: Build main libCacheSim project
35+
- name: Install system dependencies (macOS)
36+
if: matrix.os == 'macos-latest' || matrix.os == 'macos-14'
2637
run: |
27-
pushd src/libCacheSim
28-
cmake -G Ninja -B build
29-
ninja -C build
30-
popd
38+
brew install glib pkg-config zstd argp-standalone
3139
32-
- name: Build libCacheSim-python
40+
- name: Build and test with uv
3341
run: |
34-
pip install -e .[dev]
42+
uv venv --python ${{ matrix.python-version }}
43+
uv pip install -e .[dev]
44+
uv run python -c "import libcachesim; print('✓ Import successful for Python ${{ matrix.python-version }} on ${{ matrix.os }}')"
3545
3646
- name: Run tests
3747
run: |
38-
python -m pytest tests/
48+
if [ -d "tests" ]; then
49+
uv run python -m pytest tests/ -v
50+
else
51+
echo "No tests directory found, skipping tests"
52+
fi
3953
4054
docs:
4155
runs-on: ubuntu-latest
4256
steps:
4357
- uses: actions/checkout@v4
4458

45-
- name: Set up Python
46-
uses: actions/setup-python@v4
59+
- name: Install uv
60+
uses: astral-sh/setup-uv@v4
4761
with:
48-
python-version: "3.x"
62+
version: "latest"
4963

50-
- name: Cache dependencies
51-
uses: actions/cache@v3
52-
with:
53-
path: ~/.cache/pip
54-
key: ${{ runner.os }}-pip-docs-${{ hashFiles('docs/requirements.txt') }}
55-
restore-keys: |
56-
${{ runner.os }}-pip-docs-
64+
- name: Set up Python
65+
run: uv python install 3.11
5766

58-
- name: Install documentation dependencies
67+
- name: Install documentation dependencies and build
5968
run: |
69+
# Install MkDocs and dependencies using pip in a temporary venv
70+
python3 -m venv temp-docs-env
71+
source temp-docs-env/bin/activate
6072
pip install -r docs/requirements.txt
61-
62-
- name: Test documentation build
63-
run: |
6473
cd docs
6574
mkdocs build --clean --strict

CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,50 @@ project(libCacheSim-python)
33
set(DESCRIPTION "The libCacheSim Python Package")
44
set(PROJECT_WEB "http://cachemon.github.io/libCacheSim-python")
55

6+
# Auto-initialize submodules if not already done
7+
find_package(Git QUIET)
8+
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
9+
# Check if submodule is initialized
10+
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/src/libCacheSim/CMakeLists.txt")
11+
message(STATUS "Initializing git submodules...")
12+
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
13+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
14+
RESULT_VARIABLE GIT_SUBMOD_RESULT)
15+
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
16+
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}")
17+
endif()
18+
endif()
19+
endif()
20+
21+
# Auto-build libCacheSim if needed
22+
set(LIBCACHESIM_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/libCacheSim")
23+
if(NOT EXISTS "${LIBCACHESIM_SOURCE_DIR}/CMakeLists.txt")
24+
message(FATAL_ERROR "libCacheSim submodule not found. Please run 'git submodule update --init --recursive'")
25+
endif()
26+
27+
# Build libCacheSim first
28+
set(LIBCACHESIM_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/libCacheSim/build")
29+
if(NOT EXISTS "${LIBCACHESIM_BUILD_DIR}/export_vars.cmake")
30+
message(STATUS "Building libCacheSim...")
31+
execute_process(
32+
COMMAND ${CMAKE_COMMAND} -S ${LIBCACHESIM_SOURCE_DIR} -B ${LIBCACHESIM_BUILD_DIR} -G Ninja
33+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
34+
RESULT_VARIABLE CMAKE_CONFIG_RESULT
35+
)
36+
if(NOT CMAKE_CONFIG_RESULT EQUAL "0")
37+
message(FATAL_ERROR "Failed to configure libCacheSim")
38+
endif()
39+
40+
execute_process(
41+
COMMAND ${CMAKE_COMMAND} --build ${LIBCACHESIM_BUILD_DIR}
42+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
43+
RESULT_VARIABLE CMAKE_BUILD_RESULT
44+
)
45+
if(NOT CMAKE_BUILD_RESULT EQUAL "0")
46+
message(FATAL_ERROR "Failed to build libCacheSim")
47+
endif()
48+
endif()
49+
650
# Note(haocheng): now we still utilize the exported cache from
751
# the main project, which should be deprecated soon
852

@@ -49,6 +93,9 @@ else()
4993
add_compile_definitions(LOGLEVEL=7)
5094
endif()
5195

96+
set(CMAKE_CXX_STANDARD 17)
97+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
98+
5299
# Find python and pybind11
53100
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
54101
find_package(pybind11 CONFIG REQUIRED)

docs/mkdocs.yml

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,62 @@
1-
site_name: libCacheSim Python Documentation
1+
site_name: libCacheSim Python
22
site_url: https://cachemon.github.io/libCacheSim-python/
33
repo_url: https://github.com/cacheMon/libCacheSim-python
44
repo_name: cacheMon/libCacheSim-python
5+
edit_uri: edit/main/docs/src/
56

67
docs_dir: src
78

89
nav:
9-
- Home: index.md
10-
- Quick Start: quickstart.md
11-
- API Reference: api.md
12-
- Examples: examples.md
10+
- Home:
11+
- libCacheSim Python: index.md
12+
- Getting Started:
13+
- Quick Start: quickstart.md
14+
- API Reference:
15+
- API Documentation: api.md
16+
- Examples:
17+
- Usage Examples: examples.md
1318

1419
theme:
1520
name: material
1621
language: en
1722
palette:
23+
# Palette toggle for automatic mode
24+
- media: "(prefers-color-scheme)"
25+
toggle:
26+
icon: material/brightness-auto
27+
name: Switch to light mode
1828
# Palette toggle for light mode
19-
- scheme: default
20-
primary: custom
21-
accent: custom
29+
- media: "(prefers-color-scheme: light)"
30+
scheme: default
31+
primary: white
2232
toggle:
2333
icon: material/brightness-7
2434
name: Switch to dark mode
25-
# Palette toggle for dark mode
26-
- scheme: slate
27-
primary: custom
28-
accent: custom
35+
# Palette toggle for dark mode
36+
- media: "(prefers-color-scheme: dark)"
37+
scheme: slate
38+
primary: black
2939
toggle:
3040
icon: material/brightness-4
31-
name: Switch to light mode
41+
name: Switch to system preference
3242
font:
3343
text: Open Sans
3444
features:
35-
- header.autohide
45+
- content.action.edit
46+
- content.code.copy
47+
- content.tabs.link
48+
- navigation.tracking
3649
- navigation.tabs
37-
- navigation.footer
50+
- navigation.tabs.sticky
3851
- navigation.sections
39-
- navigation.expand
40-
- navigation.path
52+
- navigation.prune
4153
- navigation.top
42-
- toc.follow
4354
- search.highlight
4455
- search.share
45-
- search.suggest
46-
- content.code.copy
47-
- content.code.annotate
56+
- toc.follow
4857

4958
extra_css:
50-
- ../stylesheets/extra.css
59+
- stylesheets/extra.css
5160

5261
plugins:
5362
- search
@@ -71,25 +80,29 @@ plugins:
7180
Examples: 使用示例
7281

7382
markdown_extensions:
83+
- attr_list
84+
- md_in_html
7485
- admonition
7586
- pymdownx.details
7687
- pymdownx.superfences:
7788
custom_fences:
7889
- name: mermaid
7990
class: mermaid
8091
format: !!python/name:pymdownx.superfences.fence_code_format
92+
- pymdownx.tabbed:
93+
alternate_style: true
8194
- pymdownx.highlight:
8295
anchor_linenums: true
8396
line_spans: __span
8497
pygments_lang_class: true
8598
- pymdownx.inlinehilite
8699
- pymdownx.snippets
87-
- pymdownx.tabbed:
88-
alternate_style: true
89100
- pymdownx.keys
90101
- pymdownx.mark
91102
- pymdownx.tilde
92-
- codehilite
103+
- pymdownx.emoji:
104+
emoji_index: !!python/name:material.extensions.emoji.twemoji
105+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
93106
- toc:
94107
permalink: true
95108
- tables

docs/src/en/plugin.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Plugin System
2+
3+
We enable user add any customized cache via libCacheSim's plugin system.
4+
5+
With user-defined sive python hook functions,
6+
7+
```c++
8+
py::function cache_init_hook;
9+
py::function cache_hit_hook;
10+
py::function cache_miss_hook;
11+
py::function cache_eviction_hook;
12+
py::function cache_remove_hook;
13+
py::function cache_free_hook;
14+
```
15+
16+
We can simulate and determine the cache eviction behavior from the python side.

0 commit comments

Comments
 (0)