Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ reconfsm/fsm/__pycache__
reconfsm/converter/__pycache__
reconfsm/__pycache__
docs/build
.dockerignore
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# syntax=docker/dockerfile:1

FROM python:3.12-slim AS builder

WORKDIR /build

RUN pip install --upgrade pip setuptools wheel

COPY pyproject.toml README.md LICENSE ./
COPY reconfsm/ ./reconfsm/

RUN python -m venv /venv && \
/venv/bin/pip install --upgrade pip && \
/venv/bin/pip install .


FROM python:3.12-slim AS runtime

RUN apt-get update && \
apt-get install -y --no-install-recommends graphviz && \
rm -rf /var/lib/apt/lists/*

COPY --from=builder /venv /venv
ENV PATH="/venv/bin:$PATH"

COPY reconfsm/ /app/reconfsm/
COPY examples/ /app/examples/

WORKDIR /app

RUN useradd --create-home reconfsm
USER reconfsm

CMD ["/bin/bash"]
2 changes: 1 addition & 1 deletion reconfsm/fsm/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import json
import os
from transitions.extensions import GraphMachine
from .pathfinding import pathfinding_simulation
from .fsm_pathfinding import pathfinding_simulation
from .graph import graph_simulation


Expand Down
File renamed without changes.
44 changes: 1 addition & 43 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,12 @@
"""
conftest.py — shared pytest fixtures for the reconfsm test suite.

IMPORTANT – fsm.py import bootstrap
------------------------------------
reconfsm/fsm/fsm.py uses bare-name imports designed to be run from inside its
own directory:

from pathfinding import pathfinding_simulation
from graph import graph_simulation
"""

import sys
import types
from pathlib import Path
from unittest.mock import MagicMock
import pytest


# ---------------------------------------------------------------------------
# Bootstrap: stub out the bare 'pathfinding' and 'graph' imports in fsm.py
#
# fsm.py does: from pathfinding import pathfinding_simulation
# from graph import graph_simulation
#
# These are bare-name imports that only work when run from the fsm/ directory.
# When imported as a package, Python finds the installed PyPI 'pathfinding'
# package instead, which doesn't expose pathfinding_simulation → ImportError.
#
# Fix: inject lightweight stubs into sys.modules BEFORE reconfsm.fsm.fsm is
# imported for the first time. All subsequent imports hit the cache.
# ---------------------------------------------------------------------------

def _make_stub(module_name, **attrs):
mod = types.ModuleType(module_name)
for k, v in attrs.items():
setattr(mod, k, v)
return mod


if "reconfsm.fsm.fsm" not in sys.modules:
sys.modules.setdefault(
"pathfinding",
_make_stub("pathfinding", pathfinding_simulation=MagicMock()),
)
sys.modules.setdefault(
"graph",
_make_stub("graph", graph_simulation=MagicMock()),
)

from reconfsm.fsm.fsm import load_machine_from_json # noqa: E402
from reconfsm.fsm.fsm import load_machine_from_json


# ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reconfsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import sys
import pytest
from reconfsm.fsm.fsm import FSMachine, load_machine_from_json, main
from reconfsm.fsm.pathfinding import pathfinding_simulation, sort_and_display_paths
from reconfsm.fsm.fsm_pathfinding import pathfinding_simulation, sort_and_display_paths
from reconfsm.fsm.graph import graph_simulation


Expand Down
Loading