Skip to content

Commit 2e6b895

Browse files
authored
Merge branch 'master' into scipy-linalg-2
2 parents 831f5bc + b234289 commit 2e6b895

File tree

2,205 files changed

+157329
-9394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,205 files changed

+157329
-9394
lines changed

.circleci/config.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/linters.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Check that code is formatted consistently
2+
#
3+
# Available Python versions:
4+
# https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
5+
6+
name: linters
7+
on:
8+
push:
9+
branches:
10+
- master
11+
pull_request:
12+
13+
jobs:
14+
tests:
15+
name: ${{ matrix.name }}
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- {name: Linux311, python: '3.11.0-rc.1', os: ubuntu-latest}
22+
steps:
23+
- name: Check out repository
24+
uses: actions/checkout@v2
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ matrix.python }}
30+
31+
- name: Restore cache
32+
id: cache
33+
uses: actions/cache@v3
34+
with:
35+
path: ./venv
36+
key: ${{ matrix.name }}-pip-${{ hashFiles('requirements.txt') }}
37+
restore-keys: |
38+
${{ matrix.name }}-pip-
39+
40+
- name: Install dependencies
41+
if: steps.cache.outputs.cache-hit != 'true'
42+
run: |
43+
python -m venv venv
44+
. venv/bin/activate
45+
python -m pip install --upgrade pip
46+
python -m pip install -r requirements.txt
47+
48+
- name: Check code style
49+
run: |
50+
. venv/bin/activate
51+
python -m flake8
52+
python -m black --check .
53+
54+
- name: Check directory layout
55+
run: |
56+
. venv/bin/activate
57+
python .github/workflows/dircheck.py

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ __pycache__/
88

99
# C extensions
1010
*.so
11+
*.o
1112

1213
# Distribution / packaging
1314
.Python
@@ -56,6 +57,8 @@ coverage.xml
5657
# Django stuff:
5758
*.log
5859
local_settings.py
60+
*.sqlite3
61+
nohup.out
5962

6063
# Flask stuff:
6164
instance/

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
Bonus materials, exercises, and example projects for Real Python's [Python tutorials](https://realpython.com).
44

5-
Build Status: [![CircleCI](https://circleci.com/gh/realpython/materials.svg?style=svg)](https://circleci.com/gh/realpython/materials)
5+
Build Status:
6+
[![GitHub Actions](https://img.shields.io/github/workflow/status/realpython/materials/linters?label=build)](https://github.com/realpython/materials/actions)
67

78
## Got a Question?
89

9-
The best way to get support for Real Python courses & articles and code in this repository is to join one of our [weekly Office Hours calls](https://realpython.com/office-hours/) or to ask your question in the [RP Community Slack](https://realpython.com/community/).
10+
The best way to get support for Real Python courses, articles, and code in this repository is to join one of our [weekly Office Hours calls](https://realpython.com/office-hours/) or to ask your question in the [RP Community Chat](https://realpython.com/community/).
1011

11-
Due to time constraints we cannot provide 1:1 support via GitHub. See you on Slack or on the next Office Hours call 🙂
12+
Due to time constraints, we cannot provide 1:1 support via GitHub. See you on Slack or on the next Office Hours call 🙂
1213

1314
## Adding Source Code & Sample Projects to This Repo (RP Contributors)
1415

1516
### Running Code Style Checks
1617

17-
We use [flake8](http://flake8.pycqa.org/en/latest/) and [black](https://github.com/ambv/black) to ensure a consistent code style for all of our sample code in this repository.
18+
We use [flake8](http://flake8.pycqa.org/en/latest/) and [black](https://black.readthedocs.io/) to ensure a consistent code style for all of our sample code in this repository.
1819

1920
Run the following commands to validate your code against the linters:
2021

@@ -25,11 +26,11 @@ $ black --check .
2526

2627
### Running Python Code Formatter
2728

28-
We're using a tool called [black](https://github.com/ambv/black) on this repo to ensure consistent formatting. On CI it runs in "check" mode to ensure any new files added to the repo are following PEP 8. If you see linter warnings that say something like "would reformat some_file.py" it means black disagrees with your formatting.
29+
We're using a tool called [black](https://black.readthedocs.io/) on this repo to ensure consistent formatting. On CI it runs in "check" mode to ensure any new files added to the repo follow PEP 8. If you see linter warnings that say something like "would reformat some_file.py" it means that black disagrees with your formatting.
2930

30-
**The easiest way to resolve these errors is to just run Black locally on the code and then committing those changes, as explained below.**
31+
**The easiest way to resolve these errors is to run Black locally on the code and then commit those changes, as explained below.**
3132

32-
To automatically re-format your code to be consistent with our code style guidelines, run [black](https://github.com/ambv/black) in the repository root folder:
33+
To automatically re-format your code to be consistent with our code style guidelines, run [black](https://black.readthedocs.io/) in the repository root folder:
3334

3435
```sh
3536
$ black .

add-to-path/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# How to Add Python to Path
2+
3+
Supporting materials for the Real Python tutorial [How to Add Python to PATH](https://realpython.com/add-python-to-path/).
4+
5+
Here you'll find a file for Windows and one for Linux and macOS. They have snippets and instructions distilled from the tutorials.
6+
7+
Additionally, you'll find some ways to set environment variables and modify `PATH` with PowerShell on Windows that aren't included in the tutorial.

add-to-path/linux-and-macos.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# ------------------------------------
2+
# Add Path to PATH
3+
# ------------------------------------
4+
5+
# Make sure you use the right profile for your system
6+
$ export PATH="<PATH_TO_PYTHON>:$PATH"
7+
8+
# ------------------------------------
9+
# Add Path-Adding Operation to Profile
10+
# ------------------------------------
11+
12+
# Make sure you use the right profile for your system
13+
$ echo export PATH="<PATH_TO_PYTHON>:$PATH" >> ~/.profile
14+
# Reread profile to see effect in same session
15+
$ source ~/.profile
16+
17+
# ------------------------------------
18+
# Filtering Bad Paths from PATH
19+
# ------------------------------------
20+
21+
# View current PATH
22+
$ echo $PATH
23+
# Output:
24+
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:
25+
# /sbin:/bin:/usr/games:/usr/local/games
26+
27+
# View on separate lines by replacing colons with newlines
28+
$ echo $PATH | tr ":" "\n"
29+
# Output:
30+
# /usr/local/sbin
31+
# /usr/local/bin
32+
# /usr/sbin
33+
# /home/realpython/badpython
34+
# /usr/bin
35+
# /sbin
36+
# /bin
37+
# /usr/games
38+
# /usr/local/games
39+
40+
# Filter out certain lines with grep -v
41+
$ echo $PATH | tr ":" "\n" | grep -v 'badpython'
42+
# Output:
43+
# /usr/local/sbin
44+
# /usr/local/bin
45+
# /usr/sbin
46+
# /usr/bin
47+
# /sbin
48+
# /bin
49+
# /usr/games
50+
# /usr/local/games
51+
52+
# Replace newlines with colons
53+
$ echo $PATH | tr ":" "\n" | grep -v 'badpython' | tr "\n" ":"
54+
# Output:
55+
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:
56+
# /usr/local/games
57+
58+
# Assign to PATH
59+
$ export PATH=`echo $PATH | tr ":" "\n" | grep -v 'badpython' | tr "\n" ":"`

add-to-path/windows.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# --------------------------------------------------
2+
# How to Add to `PATH` via GUI
3+
# --------------------------------------------------
4+
5+
<#
6+
7+
Once you've located your Python executable, open the Start menu and search
8+
for the _Edit the system environment variables_ entry, which opens up a
9+
_System Properties_ window. In the _Advanced_ tab, click on the button
10+
_Environment Variables_. There you'll see _User_ and _System_ variables,
11+
which you'll be able to edit.
12+
13+
In the section entitled _User Variables_, double-click on the entry that
14+
says _Path_. Another window will pop up showing a list of paths. Click the
15+
_New_ button and paste the path to your Python executable there. Once that's
16+
inserted, select your newly added path and click the _Move Up_ button until
17+
it's at the top.
18+
19+
That's it! You may need to reboot your computer for the changes to take
20+
effect, but you should now be able to call `python` from the command line.
21+
22+
#>
23+
24+
# --------------------------------------------------
25+
# Working With Environment Variables With PowerShell
26+
# --------------------------------------------------
27+
28+
# Set temporary environment variable (only active for current shell session)
29+
PS> $ENV:TEST = "VALUE"
30+
31+
# Set permanent environment variable (need to restart shell to take effect)
32+
PS> [Environment]::SetEnvironmentVariable("TEST", "VALUE", "User")
33+
34+
PS> cd ENV:
35+
PS> ls
36+
37+
<# OUTPUT
38+
39+
Name Value
40+
---- -----
41+
ALLUSERSPROFILE C:\ProgramData
42+
ANSICON 166x32766 (166x66)
43+
ANSICON_DEF 7
44+
APPDATA C:\Users\RealPython\AppData\Roaming
45+
AZ_ENABLED False
46+
...
47+
TEST VALUE
48+
...
49+
50+
#>
51+
52+
# View PATH
53+
PS> (cat ENV:PATH) -Split ";"
54+
55+
<# OUTPUT
56+
57+
C:\Program Files\PowerShell\7
58+
C:\Windows\system32
59+
C:\Windows
60+
C:\Windows\System32\WindowsPowerShell\v1.0\
61+
C:\Windows\System32\OpenSSH\
62+
63+
#>
64+
65+
# Append path to PATH
66+
PS> $ENV:PATH = "$ENV:PATH;C:\new\path"
67+
68+
# Prepend path to PATH
69+
PS> $ENV:PATH = "C:\new\path;$ENV:PATH"

advent-of-code/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Advent of Code: Solving Your Puzzles With Python
2+
3+
This repository holds the code for the Real Python [Advent of Code: Solving Your Puzzles With Python](https://realpython.com/python-advent-of-code/) tutorial.
4+
5+
## Dependencies
6+
7+
[Pytest](https://realpython.com/pytest-python-testing/) is used for testing. You should first create a virtual environment:
8+
9+
```console
10+
$ python -m venv venv
11+
$ source venv/bin/activate
12+
```
13+
14+
You can then install `pytest` with `pip`:
15+
16+
```console
17+
(venv) $ python -m pip install pytest
18+
```
19+
20+
The [aoc_grid.py](aoc_grid.py) example uses [Colorama](https://pypi.org/project/colorama/) and [NumPy](https://realpython.com/numpy-tutorial/). To run that example, you should also install those packages into your environment:
21+
22+
```console
23+
(venv) $ python -m pip install colorama numpy
24+
```
25+
26+
The puzzle solutions only use Python's standard library. Note that the solution to [Day 5, 2021](solutions/2021/05_hydrothermal_venture/) uses [structural pattern matching](https://realpython.com/python310-new-features/#structural-pattern-matching) which is only available in [Python 3.10](https://realpython.com/python310-new-features/) and later.
27+
28+
## Author
29+
30+
- **Geir Arne Hjelle**, E-mail: [[email protected]]([email protected])
31+
32+
## License
33+
34+
Distributed under the MIT license. See [`LICENSE`](../LICENSE) for more information.

advent-of-code/aoc_grid.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import numpy as np
2+
from colorama import Cursor
3+
4+
grid = np.array(
5+
[
6+
[1, 1, 1, 1, 1],
7+
[1, 0, 0, 0, 1],
8+
[1, 1, 1, 0, 1],
9+
[1, 0, 0, 2, 1],
10+
[1, 1, 1, 1, 1],
11+
]
12+
)
13+
14+
num_rows, num_cols = grid.shape
15+
for row in range(num_rows):
16+
for col in range(num_cols):
17+
symbol = " *o"[grid[row, col]]
18+
print(f"{Cursor.POS(col + 1, row + 2)}{symbol}")

0 commit comments

Comments
 (0)