Skip to content

Commit

Permalink
docs: Include section on special variables in Nitrogen #73
Browse files Browse the repository at this point in the history
  • Loading branch information
lo5 committed Aug 22, 2022
1 parent 5f7e141 commit 71558c1
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions help/docs/reference/nitrogen.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,40 @@ like Flask, Tornado, Starlette, etc. where it's useful to inspect the command's
```
START python -m flask run
```


## Special Variables

Use special variables to refer to the file containing Nitrogen instructions.

Given a file `/path/to/foo.py`:

| Variable | Translates to | Example |
|---|---|---|
| `__file__` | File path | `/path/to/foo.py` |
| `__dir__` | File's parent directory | `/path/to` |
| `__base__` | File name with extension | `foo.py` |
| `__name__` | File name without extension | `foo` |
| `__ext__` | File extension | `.py` |

Special variables are useful when you want to avoid hard-coding the current file name in instructions.

**Example 1.** Setting an environment variable for Flask:

```
# Before
ENV FLASK_ENV foo.py
# After
ENV FLASK_ENV __base__
```

**Example 2.** Launching an app using Uvicorn:

```
# Before
START python -m uvicorn foo:app
# After
START python -m uvicorn __name__:app
```

0 comments on commit 71558c1

Please sign in to comment.