Skip to content

Commit a72dead

Browse files
Cleanup pluggable-libs & fix CI file output (#433, #447) (#448)
* Remove pluggable-libs submodule and cleanup (#433) * Fix GitHub Actions output format error for multiline file lists * Add requirements-dev.txt so CI can install dev dependencies
1 parent 931ed9f commit a72dead

File tree

10 files changed

+100
-61
lines changed

10 files changed

+100
-61
lines changed

.github/workflows/lint_pr.yml

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v3
1111
with:
12-
fetch-depth: 0 # To get all history for git diff commands
13-
12+
fetch-depth: 0 # To get all history for git diff commands
13+
1414
- name: Get changed Python files
1515
id: changed-files
1616
run: |
@@ -31,7 +31,7 @@ jobs:
3131
CHANGED_FILES="$CHANGED_FILES $SETUP_PY_CHANGED"
3232
fi
3333
fi
34-
34+
3535
# Check if any Python files were changed and set the output accordingly
3636
if [ -z "$CHANGED_FILES" ]; then
3737
echo "No Python files changed"
@@ -40,9 +40,11 @@ jobs:
4040
else
4141
echo "Changed Python files: $CHANGED_FILES"
4242
echo "has_python_changes=true" >> $GITHUB_OUTPUT
43-
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
43+
# Use proper delimiter formatting for GitHub Actions
44+
FILES_SINGLE_LINE=$(echo "$CHANGED_FILES" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')
45+
echo "files=$FILES_SINGLE_LINE" >> $GITHUB_OUTPUT
4446
fi
45-
47+
4648
- name: PR information
4749
if: ${{ github.event_name == 'pull_request' }}
4850
run: |
@@ -68,35 +70,35 @@ jobs:
6870
echo "No Python files were changed. Skipping linting."
6971
exit 0
7072
fi
71-
73+
7274
- uses: actions/checkout@v3
7375
with:
7476
fetch-depth: 0
75-
77+
7678
- uses: actions/setup-python@v4
7779
with:
7880
python-version: 3.12
79-
81+
8082
- uses: actions/cache@v3
8183
with:
8284
path: ~/.cache/pip
8385
key: ${{ runner.os }}-pip-${{ hashFiles('requirements-dev.txt') }}
8486
restore-keys: |
8587
${{ runner.os }}-pip-
86-
88+
8789
- name: Install dependencies
8890
run: |
8991
python -m pip install --upgrade pip
9092
pip install -r requirements-dev.txt
91-
93+
9294
# Flake8 linting
9395
- name: Lint with flake8
9496
if: ${{ matrix.tool == 'flake8' }}
9597
id: flake8
9698
run: |
9799
echo "Linting files: ${{ needs.check_changes.outputs.files }}"
98100
flake8 ${{ needs.check_changes.outputs.files }} --count --show-source --statistics
99-
101+
100102
# Format checking with isort and black
101103
- name: Format check
102104
if: ${{ matrix.tool == 'format' }}
@@ -106,27 +108,27 @@ jobs:
106108
isort --profile black --check ${{ needs.check_changes.outputs.files }}
107109
echo "Checking format with black for: ${{ needs.check_changes.outputs.files }}"
108110
black --check ${{ needs.check_changes.outputs.files }}
109-
111+
110112
# Type checking with mypy
111113
- name: Type check with mypy
112114
if: ${{ matrix.tool == 'mypy' }}
113115
id: mypy
114116
run: |
115117
echo "Type checking: ${{ needs.check_changes.outputs.files }}"
116118
mypy --ignore-missing-imports ${{ needs.check_changes.outputs.files }}
117-
119+
118120
# Run tests with pytest
119121
- name: Run tests with pytest
120122
if: ${{ matrix.tool == 'pytest' }}
121123
id: pytest
122124
run: |
123125
echo "Running pytest discovery..."
124126
python -m pytest --collect-only -v
125-
127+
126128
# First run any test files that correspond to changed files
127129
echo "Running tests for changed files..."
128130
changed_files="${{ needs.check_changes.outputs.files }}"
129-
131+
130132
# Extract module paths from changed files
131133
modules=()
132134
for file in $changed_files; do
@@ -137,13 +139,13 @@ jobs:
137139
modules+=("$module_path")
138140
fi
139141
done
140-
142+
141143
# Run tests for each module
142144
for module in "${modules[@]}"; do
143145
echo "Testing module: $module"
144146
python -m pytest -xvs tests/ -k "$module" || true
145147
done
146-
148+
147149
# Then run doctests on the changed files
148150
echo "Running doctests for changed files..."
149151
for file in $changed_files; do
@@ -152,26 +154,26 @@ jobs:
152154
python -m pytest --doctest-modules -v $file || true
153155
fi
154156
done
155-
157+
156158
# Check Python version compatibility
157159
- name: Check Python version compatibility
158160
if: ${{ matrix.tool == 'pyupgrade' }}
159161
id: pyupgrade
160162
run: pyupgrade --py312-plus ${{ needs.check_changes.outputs.files }}
161-
163+
162164
# Run tox
163165
- name: Run tox
164166
if: ${{ matrix.tool == 'tox' }}
165167
id: tox
166168
run: |
167169
echo "Running tox integration for changed files..."
168170
changed_files="${{ needs.check_changes.outputs.files }}"
169-
171+
170172
# Create a temporary tox configuration that extends the original one
171173
echo "[tox]" > tox_pr.ini
172174
echo "envlist = py312" >> tox_pr.ini
173175
echo "skip_missing_interpreters = true" >> tox_pr.ini
174-
176+
175177
echo "[testenv]" >> tox_pr.ini
176178
echo "setenv =" >> tox_pr.ini
177179
echo " COVERAGE_FILE = .coverage.{envname}" >> tox_pr.ini
@@ -182,24 +184,24 @@ jobs:
182184
echo " coverage" >> tox_pr.ini
183185
echo " python" >> tox_pr.ini
184186
echo "commands =" >> tox_pr.ini
185-
187+
186188
# Check if we have any implementation files that changed
187189
pattern_files=0
188190
test_files=0
189-
191+
190192
for file in $changed_files; do
191193
if [[ $file == patterns/* ]]; then
192194
pattern_files=1
193195
elif [[ $file == tests/* ]]; then
194196
test_files=1
195197
fi
196198
done
197-
199+
198200
# Only run targeted tests, no baseline
199201
echo " # Run specific tests for changed files" >> tox_pr.ini
200-
202+
201203
has_tests=false
202-
204+
203205
# Add coverage-focused test commands
204206
for file in $changed_files; do
205207
if [[ $file == *.py ]]; then
@@ -246,18 +248,18 @@ jobs:
246248
fi
247249
fi
248250
done
249-
251+
250252
# If we didn't find any specific tests to run, mention it
251253
if [ "$has_tests" = false ]; then
252254
echo " python -c \"print('No specific tests found for changed files. Consider adding tests.')\"" >> tox_pr.ini
253255
# Add a minimal test to avoid failure, but ensure it generates coverage data
254256
echo " coverage run -m pytest -xvs --cov=patterns --cov-append -k \"not integration\" --no-header" >> tox_pr.ini
255257
fi
256-
258+
257259
# Add coverage report command
258260
echo " coverage combine" >> tox_pr.ini
259261
echo " coverage report -m" >> tox_pr.ini
260-
262+
261263
# Run tox with the custom configuration
262264
echo "Running tox with custom PR configuration..."
263265
echo "======================== TOX CONFIG ========================"
@@ -272,7 +274,7 @@ jobs:
272274
runs-on: ubuntu-24.04
273275
steps:
274276
- uses: actions/checkout@v3
275-
277+
276278
- name: Summarize results
277279
run: |
278280
echo "## Pull Request Lint Results" >> $GITHUB_STEP_SUMMARY

patterns/behavioral/memento.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ def Transactional(method):
4747
4848
:param method: The function to be decorated.
4949
"""
50+
5051
def transaction(obj, *args, **kwargs):
5152
state = memento(obj)
5253
try:
5354
return method(obj, *args, **kwargs)
5455
except Exception as e:
5556
state()
5657
raise e
58+
5759
return transaction
5860

61+
5962
class NumObj:
6063
def __init__(self, value):
6164
self.value = value

patterns/behavioral/servant.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,26 @@
1919
References:
2020
- https://en.wikipedia.org/wiki/Servant_(design_pattern)
2121
"""
22+
2223
import math
2324

25+
2426
class Position:
2527
"""Representation of a 2D position with x and y coordinates."""
2628

2729
def __init__(self, x, y):
2830
self.x = x
2931
self.y = y
3032

33+
3134
class Circle:
3235
"""Representation of a circle defined by a radius and a position."""
3336

3437
def __init__(self, radius, position: Position):
3538
self.radius = radius
3639
self.position = position
3740

41+
3842
class Rectangle:
3943
"""Representation of a rectangle defined by width, height, and a position."""
4044

@@ -65,7 +69,7 @@ def calculate_area(shape):
6569
ValueError: If the shape type is unsupported.
6670
"""
6771
if isinstance(shape, Circle):
68-
return math.pi * shape.radius ** 2
72+
return math.pi * shape.radius**2
6973
elif isinstance(shape, Rectangle):
7074
return shape.width * shape.height
7175
else:

patterns/other/blackboard.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
class AbstractExpert(ABC):
1717
"""Abstract class for experts in the blackboard system."""
18+
1819
@abstractmethod
1920
def __init__(self, blackboard) -> None:
2021
self.blackboard = blackboard
@@ -31,6 +32,7 @@ def contribute(self) -> None:
3132

3233
class Blackboard:
3334
"""The blackboard system that holds the common state."""
35+
3436
def __init__(self) -> None:
3537
self.experts: list = []
3638
self.common_state = {
@@ -46,6 +48,7 @@ def add_expert(self, expert: AbstractExpert) -> None:
4648

4749
class Controller:
4850
"""The controller that manages the blackboard system."""
51+
4952
def __init__(self, blackboard: Blackboard) -> None:
5053
self.blackboard = blackboard
5154

@@ -63,6 +66,7 @@ def run_loop(self):
6366

6467
class Student(AbstractExpert):
6568
"""Concrete class for a student expert."""
69+
6670
def __init__(self, blackboard) -> None:
6771
super().__init__(blackboard)
6872

@@ -79,6 +83,7 @@ def contribute(self) -> None:
7983

8084
class Scientist(AbstractExpert):
8185
"""Concrete class for a scientist expert."""
86+
8287
def __init__(self, blackboard) -> None:
8388
super().__init__(blackboard)
8489

0 commit comments

Comments
 (0)