Repository navigation
Expand file tree
/
Copy pathsoftware_intro.html
More file actions
647 lines (568 loc) · 27 KB
/
Copy pathsoftware_intro.html
File metadata and controls
647 lines (568 loc) · 27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Applied Software Engineering - Introduction</title>
<link rel="stylesheet" href="https://unpkg.com/reveal.js@5.1.0/dist/reset.css">
<link rel="stylesheet" href="https://unpkg.com/reveal.js@5.1.0/dist/reveal.css">
<link rel="stylesheet" href="https://unpkg.com/reveal.js@5.1.0/dist/theme/white.css">
<link rel="stylesheet" href="https://unpkg.com/reveal.js@5.1.0/plugin/highlight/monokai.css">
<style>
.reveal h1, .reveal h2, .reveal h3 {
text-transform: none;
}
.reveal pre {
font-size: 0.55em;
width: 100%;
}
.reveal pre code {
max-height: 500px;
}
.reveal ul {
display: block;
}
.reveal .small-text {
font-size: 0.7em;
}
.reveal .highlight-box {
background-color: #f0f0f0;
padding: 20px;
border-radius: 10px;
margin: 20px 0;
}
.two-columns {
display: flex;
gap: 40px;
}
.two-columns > div {
flex: 1;
}
.diagram-center {
display: flex;
justify-content: center;
margin: 20px 0;
}
.reveal a.tool-link {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<!-- Title Slide -->
<section>
<h1>Applied Software Engineering</h1>
<h3>Tools and Best Practices for Python Development</h3>
<p class="small-text">
Decision-Making and Motion Planning for Automated Driving<br>
KIT - Karlsruhe Institute of Technology
</p>
</section>
<!-- Outline -->
<section>
<h2>Topics</h2>
<ol>
<li>Git and GitHub</li>
<li>Python and uv</li>
<li>Unit Testing and TDD</li>
<li>Linting and Code Quality</li>
<li>IDE and Debugging</li>
</ol>
</section>
<!-- ============================================ -->
<!-- SECTION 1: Git and GitHub -->
<!-- ============================================ -->
<section>
<h2>1. Git and GitHub</h2>
</section>
<section>
<h3>What is Version Control?</h3>
<ul>
<li>Track changes to files over time</li>
<li>Collaborate with others without conflicts</li>
<li>Revert to previous versions when needed</li>
<li>Maintain a complete history of your project</li>
</ul>
<div class="highlight-box">
<strong><a class="tool-link" href="https://git-scm.com/">Git</a></strong> = Distributed version control system<br>
<strong><a class="tool-link" href="https://github.com/">GitHub</a></strong> = Web-based hosting for Git repositories
</div>
<p class="small-text">
Docs: <a class="tool-link" href="https://git-scm.com/doc">git-scm.com/doc</a>
</p>
</section>
<section>
<h3>Git Basics</h3>
<pre><code class="language-bash"># Clone a repository
git clone https://github.com/KIT-MRT/behavior_generation_lecture_python.git
# Check status of your changes
git status
# Stage changes for commit
git add myfile.py
# Commit with a message
git commit -m "Add new feature for path planning"
# Push to remote repository
git push origin main
# Pull latest changes (fetch + merge)
git pull origin main</code></pre>
<p class="small-text">
Resources: <a class="tool-link" href="https://docs.github.com/en/get-started">GitHub Getting Started</a>,
<a class="tool-link" href="https://git-scm.com/docs">Git reference</a>
</p>
</section>
<section>
<h3>Branching and Merging</h3>
<div class="two-columns">
<div>
<pre><code class="language-bash"># Create a new branch
git checkout -b feature/new-controller
# Switch between branches
git checkout main
# Merge a branch
git merge feature/new-controller
# Delete a branch
git branch -d feature/new-controller</code></pre>
</div>
<div>
<div class="diagram-center">
<svg width="300" height="200" viewBox="0 0 300 200" xmlns="http://www.w3.org/2000/svg">
<line x1="20" y1="150" x2="280" y2="150" stroke="#333" stroke-width="4" />
<path d="M 80 150 Q 100 50 140 50 L 200 50 Q 240 50 260 150" stroke="#e74c3c" stroke-width="4" fill="none" />
<circle cx="50" cy="150" r="10" fill="#333" />
<circle cx="80" cy="150" r="10" fill="#333" />
<circle cx="140" cy="50" r="10" fill="#e74c3c" />
<circle cx="200" cy="50" r="10" fill="#e74c3c" />
<circle cx="260" cy="150" r="10" fill="#333" stroke="#e74c3c" stroke-width="3" />
<text x="20" y="180" font-family="sans-serif" font-size="14" fill="#333">main</text>
<text x="140" y="30" font-family="sans-serif" font-size="14" fill="#e74c3c" text-anchor="middle">feature/new-controller</text>
</svg>
</div>
<p><strong>Why branches?</strong></p>
<ul class="small-text">
<li>Isolate development work</li>
<li>Work on features independently</li>
<li>Review before merging to main</li>
</ul>
</div>
</div>
</section>
<section>
<h3>GitHub Workflow</h3>
<ol>
<li><strong>Fork/Clone</strong> the repository</li>
<li><strong>Create a branch</strong> for your feature</li>
<li><strong>Make changes</strong> and commit</li>
<li><strong>Push</strong> to your fork/branch</li>
<li><strong>Open a Pull Request (PR)</strong></li>
<li><strong>Code Review</strong> by teammates</li>
<li><strong>Merge</strong> after approval</li>
</ol>
</section>
<!-- ============================================ -->
<!-- SECTION 2: Python and uv -->
<!-- ============================================ -->
<section>
<h2>2. Python and uv</h2>
</section>
<section>
<h3>The Python Environment Problem</h3>
<ul>
<li>Different projects need different Python versions</li>
<li>Package version conflicts between projects</li>
<li>"It works on my machine" syndrome</li>
<li>Reproducibility across team members</li>
</ul>
<div class="highlight-box">
<strong>Solution:</strong> Virtual environments + lock files
</div>
</section>
<section>
<h3><a class="tool-link" href="https://docs.astral.sh/uv/">uv</a> - Modern Python Package Manager</h3>
<ul>
<li>Fast (written in Rust, 10-100x faster than pip)</li>
<li>Manages Python versions</li>
<li>Creates virtual environments automatically</li>
<li>Generates lock files for reproducibility</li>
</ul>
<p class="small-text">
Docs: <a class="tool-link" href="https://docs.astral.sh/uv/">docs.astral.sh/uv</a>
</p>
</section>
<section>
<h3>uv - Common Commands</h3>
<pre><code class="language-bash"># Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create a new project
uv init my-project
# Install dependencies
uv sync
# Add a new package
uv add numpy
# Run a script
uv run python my_script.py</code></pre>
</section>
<section>
<h3>pyproject.toml</h3>
<p>Central configuration file for Python projects:</p>
<p class="small-text">
Example (shortened). Full file:
<a class="tool-link" href="https://github.com/KIT-MRT/behavior_generation_lecture_python/blob/main/pyproject.toml">pyproject.toml</a>
</p>
<pre><code class="language-toml">[project]
name = "behavior_generation_lecture_python"
version = "0.0.2"
requires-python = ">=3.12, <3.13"
dependencies = [
"numpy>=1.26.0",
"matplotlib>=2.2.4",
"scipy>=1.11.0",
# ...
]
[project.optional-dependencies]
dev = [
"pytest",
# ...
]</code></pre>
</section>
<!-- ============================================ -->
<!-- SECTION 3: Unit Testing and TDD -->
<!-- ============================================ -->
<section>
<h2>3. Unit Testing and TDD</h2>
</section>
<section>
<h3>Why Testing?</h3>
<ul>
<li><strong>Confidence:</strong> Know your code works</li>
<li><strong>Refactoring:</strong> Change code safely</li>
<li><strong>Documentation:</strong> Tests show how to use code</li>
<li><strong>Collaboration:</strong> Catch breaking changes early</li>
<li><strong>Design:</strong> Forces modular, testable code</li>
</ul>
</section>
<section>
<h3>pytest Basics</h3>
<pre><code class="language-python"># tests/test_a_star.py
import pytest
from behavior_generation_lecture_python.graph_search.a_star import a_star
def test_a_star_finds_path():
"""Test that A* finds a valid path."""
start = (0, 0)
goal = (5, 5)
path = a_star(start, goal, grid)
assert path is not None
assert path[0] == start
assert path[-1] == goal
def test_a_star_no_path():
"""Test that A* returns None when no path exists."""
path = a_star(start, goal, blocked_grid)
assert path is None</code></pre>
<p class="small-text">
Docs: <a class="tool-link" href="https://docs.pytest.org/">docs.pytest.org</a>
</p>
</section>
<section>
<h3>Running Tests</h3>
<pre><code class="language-bash"># Run all tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=src
# Run specific test file
uv run pytest tests/test_a_star.py
# Run tests matching a pattern
uv run pytest -k "test_a_star"
# Show verbose output
uv run pytest -v
# Stop on first failure
uv run pytest -x</code></pre>
<p class="small-text">
Coverage plugin: <a class="tool-link" href="https://pytest-cov.readthedocs.io/">pytest-cov</a>
</p>
</section>
<section>
<h3>Test-Driven Development (TDD)</h3>
<div class="two-columns">
<div>
<h4>The TDD Cycle:</h4>
<div class="diagram-center">
<svg width="350" height="300" viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">
<defs>
<marker id="arrowhead" markerWidth="10" markerHeight="7" refX="0" refY="3.5" orient="auto">
<polygon points="0 0, 10 3.5, 0 7" fill="#666" />
</marker>
</defs>
<circle cx="150" cy="50" r="40" fill="#ffdddd" stroke="#e74c3c" stroke-width="3"/>
<text x="150" y="55" text-anchor="middle" font-family="sans-serif" font-size="14" font-weight="bold" fill="#c0392b">RED</text>
<text x="150" y="110" text-anchor="middle" font-family="sans-serif" font-size="10" fill="#666">Write failing test</text>
<circle cx="236" cy="200" r="40" fill="#ddffdd" stroke="#27ae60" stroke-width="3"/>
<text x="236" y="205" text-anchor="middle" font-family="sans-serif" font-size="14" font-weight="bold" fill="#27ae60">GREEN</text>
<text x="236" y="260" text-anchor="middle" font-family="sans-serif" font-size="10" fill="#666">Make it pass</text>
<circle cx="64" cy="200" r="40" fill="#ddeeff" stroke="#2980b9" stroke-width="3"/>
<text x="64" y="205" text-anchor="middle" font-family="sans-serif" font-size="14" font-weight="bold" fill="#2980b9">REFACTOR</text>
<text x="64" y="260" text-anchor="middle" font-family="sans-serif" font-size="10" fill="#666">Improve code</text>
<path d="M 185 65 Q 250 80 245 155" stroke="#666" stroke-width="2" fill="none" marker-end="url(#arrowhead)"/>
<path d="M 210 230 Q 150 280 90 230" stroke="#666" stroke-width="2" fill="none" marker-end="url(#arrowhead)"/>
<path d="M 50 165 Q 40 80 115 60" stroke="#666" stroke-width="2" fill="none" marker-end="url(#arrowhead)"/>
</svg>
</div>
<p>Repeat!</p>
</div>
<div>
<h4>Benefits:</h4>
<ul class="small-text">
<li>Clear requirements before coding</li>
<li>Better design decisions</li>
<li>High test coverage by default</li>
<li>Faster debugging</li>
</ul>
</div>
</div>
</section>
<!-- ============================================ -->
<!-- SECTION 4: Linting and Code Quality -->
<!-- ============================================ -->
<section>
<h2>4. Linting and Code Quality</h2>
</section>
<section>
<h3>What is Linting?</h3>
<ul>
<li>Static analysis of code for errors and style issues</li>
<li>Catches bugs before running the code</li>
<li>Enforces consistent code style across team</li>
<li>Improves code readability and maintainability</li>
</ul>
<div class="highlight-box">
<strong>Linter:</strong> Finds problems<br>
<strong>Formatter:</strong> Fixes style automatically
</div>
</section>
<section>
<h3><a class="tool-link" href="https://docs.astral.sh/ruff/">ruff</a> - Fast Python Linter</h3>
<pre><code class="language-bash"># Format code (like Black)
uv run ruff format
# Check for linting issues
uv run ruff check
# Auto-fix what can be fixed
uv run ruff check --fix</code></pre>
<p class="small-text">ruff is 10-100x faster than traditional tools!</p>
<p>Common issues caught:</p>
<ul class="small-text">
<li>Unused imports and variables</li>
<li>Line too long</li>
<li>Missing docstrings</li>
</ul>
<p class="small-text">
Docs: <a class="tool-link" href="https://docs.astral.sh/ruff/">docs.astral.sh/ruff</a>
</p>
</section>
<section>
<h3><a class="tool-link" href="https://mypy.readthedocs.io/">mypy</a> - Static Type Checking</h3>
<pre><code class="language-python"># Without type hints - mypy cannot help
def calculate_reward(state, action):
return state * action # Bug if state is a list!
# With type hints - mypy catches errors
def calculate_reward(state: float, action: float) -> float:
return state * action # mypy ensures correct types</code></pre>
<pre><code class="language-bash"># Run type checking
uv run mypy path/to/package_or_module</code></pre>
<p class="small-text">Type hints = documentation + error prevention</p>
<p class="small-text">
Docs: <a class="tool-link" href="https://mypy.readthedocs.io/">mypy.readthedocs.io</a>
</p>
</section>
<section>
<h3>Continuous Integration (CI)</h3>
<p>CI is an automated quality gate that runs on every push / pull request.</p>
<ul class="small-text">
<li>Fast feedback: catch issues early</li>
<li>Reproducible results: same checks for everyone</li>
<li>Protects main: merges only after checks pass</li>
</ul>
<p class="small-text">
Our CI:
<a class="tool-link" href="https://github.com/KIT-MRT/behavior_generation_lecture_python/blob/main/.github/workflows/ci.yml">.github/workflows/ci.yml</a>,
</p>
</section>
<section>
<h3>Typical Local Workflow</h3>
<pre><code class="language-bash"># Create a branch
git checkout -b feature/my-change
# Install (use the lock file)
uv sync --all-extras
# Run checks (see CI workflow for the exact commands)
uv run ruff format
uv run ruff check
uv run mypy path/to/package_or_module
uv run pytest</code></pre>
</section>
<!-- ============================================ -->
<!-- SECTION 5: IDE and Debugging -->
<!-- ============================================ -->
<section>
<h2>5. IDE and Debugging</h2>
</section>
<section>
<h3>VS Code / Cursor Setup</h3>
<ul>
<li><strong><a class="tool-link" href="https://code.visualstudio.com/">VS Code</a> / <a class="tool-link" href="https://www.cursor.com/">Cursor</a>:</strong> IDE</li>
<li><strong><a class="tool-link" href="https://marketplace.visualstudio.com/items?itemName=ms-python.python">Python Extension</a>:</strong> Syntax highlighting, IntelliSense</li>
<li><strong><a class="tool-link" href="https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance">Pylance</a>:</strong> Fast type checking</li>
<li><strong><a class="tool-link" href="https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff">Ruff Extension</a>:</strong> Linting and formatting</li>
<li><strong><a class="tool-link" href="https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter">Jupyter Extension</a>:</strong> Run notebooks</li>
</ul>
</section>
<section>
<h3>VS Code / Cursor Settings</h3>
<pre><code class="language-json">// .vscode/settings.json
{
"python.defaultInterpreterPath": ".venv/bin/python",
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff"
}
}</code></pre>
</section>
<section>
<h3>Common Setup Issues (and Fixes)</h3>
<ul>
<li><strong>Wrong interpreter:</strong> Select <code>.venv/bin/python</code> in the IDE</li>
<li><strong>Missing extras:</strong> Run <code>uv sync --all-extras</code> (docs, dev tools)</li>
</ul>
<p class="small-text">
Repo files:
<a class="tool-link" href="https://github.com/KIT-MRT/behavior_generation_lecture_python/blob/main/uv.lock">uv.lock</a>,
<a class="tool-link" href="https://github.com/KIT-MRT/behavior_generation_lecture_python/blob/main/pyproject.toml">pyproject.toml</a>
</p>
</section>
<section>
<h3>Debugging in VS Code</h3>
<div class="two-columns">
<div>
<h4>Key Features:</h4>
<ul class="small-text">
<li><strong>Breakpoints:</strong> Click left of line number</li>
<li><strong>Step Over (F10):</strong> Execute current line</li>
<li><strong>Step Into (F11):</strong> Enter function</li>
<li><strong>Step Out:</strong> Exit function</li>
<li><strong>Continue (F5):</strong> Run to next breakpoint</li>
</ul>
</div>
<div>
<h4>Debug Views:</h4>
<ul class="small-text">
<li><strong>Variables:</strong> See current values</li>
<li><strong>Watch:</strong> Monitor expressions</li>
<li><strong>Call Stack:</strong> See function calls</li>
<li><strong>Debug Console:</strong> Evaluate code</li>
</ul>
</div>
</div>
<p class="small-text">
Docs: <a class="tool-link" href="https://code.visualstudio.com/docs/python/debugging">Python debugging in VS Code</a>
</p>
</section>
<!-- Summary -->
<section>
<h2>Summary</h2>
<table>
<tr>
<th>Topic</th>
<th>Key Tools</th>
</tr>
<tr>
<td>Version Control</td>
<td>
<a class="tool-link" href="https://git-scm.com/">git</a>,
<a class="tool-link" href="https://docs.github.com/">GitHub</a>,
Pull Requests
</td>
</tr>
<tr>
<td>Environment</td>
<td>
<a class="tool-link" href="https://docs.astral.sh/uv/">uv</a>,
<a class="tool-link" href="https://github.com/KIT-MRT/behavior_generation_lecture_python/blob/main/pyproject.toml">pyproject.toml</a>,
<a class="tool-link" href="https://github.com/KIT-MRT/behavior_generation_lecture_python/blob/main/uv.lock">uv.lock</a>
</td>
</tr>
<tr>
<td>Testing</td>
<td>
<a class="tool-link" href="https://docs.pytest.org/">pytest</a>,
<a class="tool-link" href="https://pytest-cov.readthedocs.io/">pytest-cov</a>,
TDD
</td>
</tr>
<tr>
<td>Code Quality</td>
<td>
<a class="tool-link" href="https://docs.astral.sh/ruff/">ruff</a>,
<a class="tool-link" href="https://mypy.readthedocs.io/">mypy</a>
</td>
</tr>
<tr>
<td>Development</td>
<td>
<a class="tool-link" href="https://code.visualstudio.com/">VS Code</a>,
<a class="tool-link" href="https://www.cursor.com/">Cursor</a>,
<a class="tool-link" href="https://code.visualstudio.com/docs/python/debugging">Python debugger</a>
</td>
</tr>
</table>
</section>
<section>
<h2>Getting Started</h2>
<pre><code class="language-bash"># Clone the repository
git clone https://github.com/KIT-MRT/behavior_generation_lecture_python.git
cd behavior_generation_lecture_python
# Install dependencies
uv sync --all-extras
# Run the tests
uv run pytest
# Start exploring!
uv run jupyter lab</code></pre>
<p>
<a href="https://kit-mrt.github.io/behavior_generation_lecture_python/">
Documentation
</a>
</p>
</section>
<section>
<h2>Ready to Go Deeper?</h2>
<div class="highlight-box">
<strong><a class="tool-link" href="https://missing.csail.mit.edu/">The Missing Semester of Your CS Education</a></strong>
<p class="small-text">MIT course on essential developer tools and workflows</p>
</div>
<h3 class="small-text">Advanced Tools Worth Exploring:</h3>
<ul class="small-text">
<li>
<strong><a class="tool-link" href="https://www.vim.org/">vim</a> / <a class="tool-link" href="https://neovim.io/">neovim</a>:</strong>
Powerful terminal editor, also available as <a class="tool-link" href="https://marketplace.visualstudio.com/items?itemName=vscodevim.vim">VS Code extension</a>
</li>
<li>
<strong><a class="tool-link" href="https://github.com/jesseduffield/lazygit">lazygit</a>:</strong>
Terminal UI for git commands with keyboard shortcuts
</li>
<li>
<strong><a class="tool-link" href="https://code.visualstudio.com/docs/devcontainers/containers">Dev Containers</a>:</strong>
Consistent development environments beyond python, using Docker (across operating systems)
</li>
</ul>
</section>
</div>
</div>
<script src="https://unpkg.com/reveal.js@5.1.0/dist/reveal.js"></script>
<script src="https://unpkg.com/reveal.js@5.1.0/plugin/highlight/highlight.js"></script>
<script src="https://unpkg.com/reveal.js@5.1.0/plugin/notes/notes.js"></script>
<script>
Reveal.initialize({
hash: true,
slideNumber: true,
plugins: [ RevealHighlight, RevealNotes ]
});
</script>
</body>
</html>