Python Project Layout: Difference between revisions
Jump to navigation
Jump to search
Line 40: | Line 40: | ||
For more details on virtual environments, see: {{Internal|Python_Language#Virtual_Environment|Virtual Environment}} | For more details on virtual environments, see: {{Internal|Python_Language#Virtual_Environment|Virtual Environment}} | ||
==<tt>.gitignore</tt>== | |||
< | <syntaxhighlight lang='text'> | ||
venv/ | |||
__pycache__/ | |||
idea/ | |||
</ | </syntaxhighlight> | ||
==Bash Wrapper== | ==Bash Wrapper== |
Revision as of 19:42, 25 October 2022
Internal
Overview
A typical Python project layout, which allows for code written in other programming languages as well, is similar to:
. ├─ .gitignore ├─ requirements.txt ├─ run ├─ src │ └─ mypackage │ ├─ __init__.py │ ├─ __main__.py │ └─ VERSION ├─ tests │ └─ mypackage │ ├─ │ └─ venv # created automatically upon virtual environment initialization ├─ bin
Setting a Manual Project
A project set up this way will be compatible with PyCharm. Also see:
Add the dependencies to requirements.txt
. For more details, see:
Initialize the virtual environment:
cd ${PROJECT_HOME} python3 -m venv venv venv/bin/pip install -r ./requirements.txt
For more details on virtual environments, see:
.gitignore
venv/
__pycache__/
idea/
Bash Wrapper
#!/usr/bin/env bash
function main() {
init_venv "$@"
PYTHONPATH="$(dirname $0)/src"
export PYTHONPATH
"$(dirname $0)/venv/bin/python3" -m mypackage "$@"
}
function init_venv() {
echo 'init_venv'
}
main "$@"
__main__.py
def main():
print('.x')
main()