Skip to content

Commit c1ab99e

Browse files
edit, .gitignore
1 parent 42be9b5 commit c1ab99e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

hugosite/content/posts/compile_python_pycache_on_upsun.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date = 2024-08-07T12:00:00+02:00
44
draft = false
55
+++
66

7-
When the python interpretor executes python files, it compiles them to bytecode and saves the bytecode as files in a directory called `__pycache__` in the same directory as the code itself. You might have seen such files, here's an example from a Django project:
7+
When the python interpretor executes python files, it compiles them to bytecode and saves it as files in a directory called `__pycache__` in the same directory as the code itself. You might have seen such files, here's an example from a Django project:
88

99
```bash
1010
$ ls -1 __pycache__/
@@ -27,6 +27,15 @@ You have two options for how to get the bytecode into place to gain the efficien
2727

2828
The second option is superior because it is compiling on the system it will run on, and you won't get any unexpected errors due to mismatches in versions or operating systems.
2929

30+
First, prevent any `__pycache__` files from ever getting into git by adding this to your `.gitignore` file.
31+
32+
```bash
33+
# Byte-compiled / optimized / DLL files
34+
__pycache__/
35+
*.py[cod]
36+
*$py.class
37+
```
38+
3039
To have Upsun compile the pytyon code in the build hook, your build hook should look something like this in `.upsun/config.yaml`:
3140

3241
```yaml

0 commit comments

Comments
 (0)