From 34e8bdc6e0eb6de4ecf4e7aad937bacaeac31d58 Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Tue, 27 Aug 2024 17:00:02 +0100 Subject: [PATCH] Autosave: 2024-08-27 17:00:02 --- zk/Python_application_structure.md | 73 ++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/zk/Python_application_structure.md b/zk/Python_application_structure.md index 07d1949..c6eb66e 100644 --- a/zk/Python_application_structure.md +++ b/zk/Python_application_structure.md @@ -1,10 +1,77 @@ --- title: Python_application_structure -tags: [] -created: Tuesday, August 27, 2024 +tags: [python] +created: Tuesday, August 27, 2024 --- -# Python_application_structure +# Python application structure +## Directory layout +``` +src/ + cli.py OR app.py + constants.py + __init__.py +tests/ +requirements.txt +setup.py +``` +## `requirements.txt` + +Dependencies used within the venv for the project, e.g: + +``` +google-auth==1.35.0 +google-auth-httplib2==0.1.0 +google-auth-oauthlib==0.4.6 +google-api-python-client==2.26.1 +gspread==3.7.0 +requests==2.25.1 +oauth2client==4.1.3 +``` + +## `setup.py` + +The declaration file for the application, equivalent to `package.json`, e.g: + +```py +from setuptools import setup, find_packages + +setup( + name="eolas-db", + version="0.1", + packages=find_packages(where="src"), + package_dir={"": "src"}, + install_requires=[ + # List your project dependencies here + ], + entry_points={ + "console_scripts": [ + "eolas-db=cli:main", + ], + }, +) +``` + +The `entry_points` key is important. This is the first execution point of the +application. Typically you would name your entry-point script as `app.py` or +`cli.py` and then specify its `main` function. + +E.g. in `cli.py`: + +```py +def main(): + print('run the application') + +if __name__ == "__main__": + main() + +``` + +## `__init__.py` + +See +[[Python_modules_and_imports#distinguishing-_modules_-from-_packages_]]|Python +modules]]