Skip to content

Commit

Permalink
edit, .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
robertDouglass committed Aug 7, 2024
1 parent 42be9b5 commit c1ab99e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hugosite/content/posts/compile_python_pycache_on_upsun.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ date = 2024-08-07T12:00:00+02:00
draft = false
+++

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:
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:

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

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.

First, prevent any `__pycache__` files from ever getting into git by adding this to your `.gitignore` file.

```bash
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
```

To have Upsun compile the pytyon code in the build hook, your build hook should look something like this in `.upsun/config.yaml`:

```yaml
Expand Down

0 comments on commit c1ab99e

Please sign in to comment.