This commit is contained in:
leehk 2025-02-13 10:53:14 +08:00
parent 8a5118dc6f
commit 0921f44ebd
24 changed files with 84 additions and 3923 deletions

View File

@ -1,201 +0,0 @@
# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml
# ruff
.ruff_cache/
# LSP config files
pyrightconfig.json
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide
data/*
!data/.gitkeep
logs/*
!logs/.gitkeep
# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode

View File

@ -1,21 +0,0 @@
lint-check:
@poetry run ruff check src/ tests/
lint-fix:
@poetry run ruff --fix src/ tests/
format-check:
@poetry run black --check --diff src/ tests/
format-fix:
@poetry run black src/ tests/
statictypes-check:
@poetry run pyright src/ tests/
run-tests:
@poetry run pytest
complete-check: lint-check format-check statictypes-check run-tests
complete-fix: lint-fix format-fix

View File

@ -1,24 +0,0 @@
# Introduction
This repository is used as a prototype template for setting up new Python project.
The documentation in `docs` contains the recommended practices.
# Installation
## Requirements
- Install [pyenv](https://github.com/pyenv/pyenv#installation) to manage the Python versions
- Install [Poetry](https://python-poetry.org/docs/#installation) to manage the dependencies
Run the following command in this project root folder to install the dependencies:
```bash
poetry install
```
Or you can install the dependencies with `pip`:
```bash
pip install -r requirements.txt
```

View File

@ -1,86 +0,0 @@
# Formatting
`Black` is recommended to format the Python files. It is a highly opinionated formatter that follows PEP8.
## Typical Workflow
1. Add [`black`](https://pypi.org/project/black/) python library as dev dependency in the virtual environment. Pin down the version if necessary.
=== "Poetry"
```bash
poetry add -G dev black
```
=== "Conda"
```bash
conda install black
```
2. Install `Black` vscode extension as specified in [Computer Setup](./0_computer_setup.md)
3. Enable format on save in your editor
## Additional settings
`Black` can be customized through `pyproject.toml`
`Black` settings are explained in [here](https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html).
# Linting
`Ruff` is recommended to lint the Python files.
## Typical Workflow
1. Add [`ruff`](https://pypi.org/project/ruff/) python library as dev dependency in the virtual environment. Pin down the version if necessary.
=== "Poetry"
```bash
poetry add -G dev ruff
```
=== "Conda"
```bash
conda install ruff
```
2. Install `Ruff` vscode extension as specified in [Computer Setup](./0_computer_setup.md)
## Additional setting
`Ruff` can be customized through `pyproject.toml`
`Ruff` settings are explained in [here](https://beta.ruff.rs/docs/configuration/).
# Type checking
`Pyright` is recommended to type check all python files in the project.
## Typical Worklow
1. Add [`pyright`](https://pypi.org/project/pyright/) python library as dev dependency in the virtual environment. Pin down the version if necessary.
=== "Poetry"
```bash
poetry add -G dev pyright
```
=== "Conda"
```bash
conda install pyright
```
2. Install `Python` vscode extension as specified in [Computer Setup](./0_computer_setup.md)
## Additional setting
`Pyright` can be customized through `pyproject.toml`
`Pyright` settings are explained in [here](https://github.com/microsoft/pyright/blob/main/docs/configuration.md)

View File

@ -1,101 +0,0 @@
# Visual Studio Code setup
1. Recommended vscode extensions for Python Development
- [`Python`](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
- [`Black`](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter)
- [`Ruff`](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff)
- [`Jupyter`](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter)
- [`autoDocstring`](https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring)
- [`Even Better TOML`](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml)
- [`YAML`](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml)
- [`Remote Development`](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack)
- [`Docker`](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker)
- [`GitLens`](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)
2. Enable strict typehints in the setting
```json
{
"python.analysis.typeCheckingMode": "strict",
"python.analysis.inlayHints.pytestParameters": true,
"python.analysis.inlayHints.functionReturnTypes": true
}
```
3. Format using `Black` and Lint using `Ruff` on save
!!! warning
Set all these settings to false for existing projects that never use `Black` or `Ruff` before.
```json
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
}
},
"python.formatting.provider": "none",
"notebook.formatOnSave.enabled": true
}
```
4. Test using `pytest`
```json
{
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["tests"]
}
```
5. Use `google` documentation style
```json
{
"autoDocstring.docstringFormat": "google"
}
```
6. Guides from the internet
- [Python in Visual Studio](https://code.visualstudio.com/docs/languages/python)
# Virtual Environment Management
Pyenv and Poetry is typically used for managing Python package, while Conda is more popular in Data Science project.
Both features virtual environment creation, but Poetry offers finer details on installing packages for production or development, publishing the Python package.
1. **Both** [`Pyenv`](https://github.com/pyenv/pyenv) **AND** [`Poetry`](https://github.com/python-poetry/poetry/)
!!! note "Pyenv Installation"
Pyenv installation may requires executing more than one line in terminal, you also need to set your shell profile (`.zshrc` or `.bash_profile`).
Read carefully [here](https://github.com/pyenv/pyenv#installation)
!!! note "Poetry Installation"
If you have old Poetry version (<1.2), you need to uninstall it and install the latest version.
2. **Either** [Conda `Miniforge` **OR** `Mambaforge`](https://github.com/conda-forge/miniforge)
3. [Docker](https://www.docker.com/)
# Gitignore
Download gitignore template from [gitignore.io](https://www.toptal.com/developers/gitignore/).
[`Python` and `visualstudiocode`](https://www.toptal.com/developers/gitignore/api/python,visualstudiocode) are recommended arguments for starter.
## Alternative Way
You may create command line function `gi` to download gitignore file. Follow the guide in [here](https://docs.gitignore.io/install/command-line). Then, you can the command in the project root folder.
```bash
gi python,visualstudiocode >> .gitignore
```

View File

@ -1,37 +0,0 @@
# Introduction
[`MkDocs`](https://www.mkdocs.org/) is a static site generator that's geared towards building project documentation. Documentation source files are written in `Markdown`, and configured with a single `YAML` configuration file.
# Installation
`MkDocs` is a Python library and there are also some extras recommended plugins to be installed.
1. [`mkdocs-material`](https://pypi.org/project/mkdocs-material/) - Theme
2. [`mkdocstrings`](https://pypi.org/project/mkdocstrings/) - Auto generate documentation from docstrings
3. [`mkdocs-jupyter`](https://pypi.org/project/mkdocs-jupyter/) - Embed Jupyter notebook in the documentation
=== "Poetry"
```bash
poetry add -G doc mkdocs mkdocs-material "mkdocstrings[python]" mkdocs-jupyter
```
=== "Conda"
```bash
conda install mkdocs mkdocs-material mkdocstrings mkdocs-jupyter
```
# Workflow
1. Install mkdocs and the plugins as above
2. Run `mkdocs new .` in the project root folder. It will create `mkdocs.yml` and `docs` folder
3. Edit `mkdocs.yml` to configure the site
4. Write the documentation in `docs` folder
# References:
- [MkDocs docs](https://www.mkdocs.org/)

View File

@ -1,41 +0,0 @@
# Introduction
This documentation contains Python recommended practice. It is intended to be used as a reference for Python developers.
## TODO Project:
1. Deploy this documentation to Azure Static Web Apps. Set it private for Evonik users and ensure the url page is fixed so it is easy to be share and bookmarked.
2. Create Python template with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and possibly [`cruft`](https://cruft.github.io/cruft/)
References:
- [Introducing a project template for modern Python packages](https://blog.wolt.com/engineering/2022/08/11/project-template-for-modern-python-packages/)
## TODO Documentation Contents:
1. Dockerize the project
References:
- https://pythonspeed.com/docker/
2. Setup environment variables thorugh `.env`
3. CI / CD with Azure Pipelines
4. Testing with pytest, coverage, mock, and tox
References:
- https://cjolowicz.github.io/posts/hypermodern-python-02-testing/
5. Makefile / pre-commit
References:
- https://earthly.dev/blog/python-makefile/
- https://pre-commit.com/
6. Logging with structlog instead?
References:
- https://www.structlog.org/en/stable/

View File

@ -1,26 +0,0 @@
# Introduction
Logging is a very important part of any application. It allows you to see what is happening in your application, and is especially useful when debugging.
Logging is already built in `Python` though `logging` library, and we may add `rich` library to make it more beautiful.
=== "Poetry"
```bash
poetry add rich
```
=== "Conda"
```bash
conda install rich
```
There are several ways to write logging configuration. You can specify it with `yaml` file, `ini` file, `json` file, Python `dict` or simply as Python code.
If [rich handler](https://rich.readthedocs.io/en/stable/logging.html) is used, you can only write the configuration as Python code.
# References:
- [Logging for ML Systems](https://madewithml.com/courses/mlops/logging/)
- [Python Logging Guide Best Practices and Hands-on Examples](https://coralogix.com/blog/python-logging-best-practices-tips/)

View File

@ -1,113 +0,0 @@
# Pyenv and Poetry
Pyenv is meant to manage multiple Python versions installed in the computer. It allows you to download different Python versions. You can set a global Python version and a different local Python version for a specific project, so when you enter that directory, the Python version is automatically switched to the one you set.
Poetry is meant to manage virtual environment of a Python project. Poetry does not have a way to download Python specific version needed in a project, so it requires Pyenv to provide one.
## Typical Workflow
You need to replace `<project name>` and `<Python version>` based on your needs. For example, you may set `<project name>` to `my-project` and `<Python version>` to `3.11.3`.
### New Project
1. Decide which Python version should be used for the new project.
2. Ensure you have the Python version needed in the computer. You may check it through `pyenv versions`
If it is not installed yet, you may run `pyenv install <Python version>` in the terminal.
!!! note
You can also check installable Python list by running `pyenv install --list`
3. Create the new project folder by running `poetry new --src <project name>` and change directory to the project folder `cd <project name>`
4. Now set the Python version locally `pyenv local <Python version>`
5. Ensure Python version requirement in `pyproject.toml` satisfies Python version specified in the previous step
6. Set Poetry to create the virtual environment and prefer active Python in the path
```
poetry config virtualenvs.in-project true --local
poetry config virtualenvs.prefer-active-python true --local
```
!!! note
`in-project` is needed to ensure the virtual environment folder `.venv` is created in the project root folder. This is useful when you want find this folder easily during docker multi-stage build.
`prefer-active-python` is needed to ensure Poetry uses the Python version specified in the previous step.
You can also set the configuration globally by replacing `--local` with `--global`. This is useful when you want to use the same configuration for all projects.
7. Create the Python virtual environment by running `poetry install`
8. Activate the virtual environment by running `poetry shell`
9. You can specify third-party dependencies with `poetry add` ([doc here](https://python-poetry.org/docs/cli/#add)) in the terminal or directly edit `pyproject.toml`
### Convert Existing Project
!!! tip
It is usually unnecessary to convert existing Python virtual environment manager to Poetry if you already have one. However, if you want to convert it, you can follow the steps below.
It follows the same steps above, except in creating project folder since you already existing one. So instead of running `poetry new --src <project name>`, run `poetry init --no-interaction --python <Python version>`.
- References:
- [Pyenv docs](https://github.com/pyenv/pyenv)
- [Poetry docs](https://python-poetry.org/docs/)
# Conda or Mamba
## Typical Workflow
You need to replace `<project name>`, `<Python version>`, and `<environment name>` based on your needs. For example, you may set `<project name>` to `my-project`, `<Python version>` to `3.11.3`, and `<environment name>` to `my-env`.
If `mamba` is installed, replace `conda` command with `mamba` for faster third-party packages installation.
### New Project
1. Create new folder `mkdir <project name> && cd <project name>`
2. Specify the Python virtual environment requirements by creating `environment.yml` file in project root folder
```yaml
name: <environment name>
channels:
- conda-forge
dependencies:
- python=<Python version>
- pandas=2.0
- ...
```
3. Create Python virtual environment and install third party dependencies by running `conda env create -f environment.yml`
4. Activate the environment by running `conda activate <environment name>`
5. You can specify third-party dependencies with `conda install` ([doc here](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html)) in the terminal or directly edit `environment.yml`
- References:
- [Conda docs](https://docs.conda.io/projects/conda/en/latest/user-guide/index.html)
### Convert Existing Project
!!! tip
It is usually unnecessary to convert existing Python virtual environment manager to Conda if you already have one. However, if you want to convert it, you can follow the steps below.
It follows the same steps above, except in creating project folder since you already existing one. You may freeze the existing dependencies through `pip freeze > requirements.txt` and create `environment.yml` file with the following content:
```yaml
name: <environment name>
channels:
- conda-forge
dependencies:
- python=<Python version>
- pip
- pip:
- -r requirements.txt
```

View File

@ -1,46 +0,0 @@
site_name: Project Docs
nav:
- Home: index.md
- Computer Setup: computer_setup.md
- Virtual Environment: virtual_environment.md
- Code Quality: code_quality.md
- Logging: logging.md
- Documentation: documentation.md
plugins:
- search
- mkdocstrings
- mkdocs-jupyter:
execute: false
include_source: true
watch:
- src/proto_docs
theme:
name: material
features:
- navigation.top
palette:
- media: '(prefers-color-scheme: dark)'
scheme: slate
primary: deep purple
accent: purple
toggle:
icon: material/brightness-7
name: Switch to light mode
- media: '(prefers-color-scheme: light)'
scheme: default
primary: blue grey
accent: light blue
toggle:
icon: material/brightness-4
name: Switch to dark mode
markdown_extensions:
- admonition
- pymdownx.details
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true

File diff suppressed because it is too large Load Diff

View File

@ -1,39 +0,0 @@
[tool.poetry]
name = "proto-docs"
version = "0.1.0"
description = ""
authors = ["Lee Hong Kai <leehongkai@gmail.com>"]
readme = "README.md"
packages = [{ include = "proto_docs", from = "src" }]
[tool.poetry.dependencies]
python = "~3.11"
typer = { extras = ["all"], version = "~0.9.0" }
rich = "~13.3.5"
[tool.poetry.group.dev.dependencies]
pytest = "~7.3.1"
coverage = "~7.2.5"
pytest-cov = "~4.0.0"
pytest-mock = "~3.10.0"
jupyter = "~1.0.0"
black = "~23.3.0"
ruff = "~0.0.267"
pyright = "~1.1.308"
tox = "~4.5.1"
[tool.poetry.group.doc.dependencies]
mkdocs = "~1.4.3"
mkdocs-material = "~9.1.12"
mkdocstrings = { extras = ["python"], version = "~0.21.2" }
mkdocs-jupyter = "~0.24.1"
[tool.poetry.scripts]
main = "proto_docs.cli:app"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

View File

@ -1,139 +0,0 @@
anyio==3.6.2 ; python_version >= "3.11" and python_version < "3.12"
appnope==0.1.3 ; python_version >= "3.11" and python_version < "3.12" and platform_system == "Darwin" or python_version >= "3.11" and python_version < "3.12" and sys_platform == "darwin"
argon2-cffi-bindings==21.2.0 ; python_version >= "3.11" and python_version < "3.12"
argon2-cffi==21.3.0 ; python_version >= "3.11" and python_version < "3.12"
arrow==1.2.3 ; python_version >= "3.11" and python_version < "3.12"
asttokens==2.2.1 ; python_version >= "3.11" and python_version < "3.12"
attrs==23.1.0 ; python_version >= "3.11" and python_version < "3.12"
backcall==0.2.0 ; python_version >= "3.11" and python_version < "3.12"
beautifulsoup4==4.12.2 ; python_version >= "3.11" and python_version < "3.12"
black==23.3.0 ; python_version >= "3.11" and python_version < "3.12"
bleach==6.0.0 ; python_version >= "3.11" and python_version < "3.12"
cachetools==5.3.0 ; python_version >= "3.11" and python_version < "3.12"
certifi==2023.5.7 ; python_version >= "3.11" and python_version < "3.12"
cffi==1.15.1 ; python_version >= "3.11" and python_version < "3.12"
chardet==5.1.0 ; python_version >= "3.11" and python_version < "3.12"
charset-normalizer==3.1.0 ; python_version >= "3.11" and python_version < "3.12"
click==8.1.3 ; python_version >= "3.11" and python_version < "3.12"
colorama==0.4.6 ; python_version >= "3.11" and python_version < "3.12"
comm==0.1.3 ; python_version >= "3.11" and python_version < "3.12"
coverage==7.2.5 ; python_version >= "3.11" and python_version < "3.12"
coverage[toml]==7.2.5 ; python_version >= "3.11" and python_version < "3.12"
debugpy==1.6.7 ; python_version >= "3.11" and python_version < "3.12"
decorator==5.1.1 ; python_version >= "3.11" and python_version < "3.12"
defusedxml==0.7.1 ; python_version >= "3.11" and python_version < "3.12"
distlib==0.3.6 ; python_version >= "3.11" and python_version < "3.12"
executing==1.2.0 ; python_version >= "3.11" and python_version < "3.12"
fastjsonschema==2.16.3 ; python_version >= "3.11" and python_version < "3.12"
filelock==3.12.0 ; python_version >= "3.11" and python_version < "3.12"
fqdn==1.5.1 ; python_version >= "3.11" and python_version < "3.12"
ghp-import==2.1.0 ; python_version >= "3.11" and python_version < "3.12"
griffe==0.27.5 ; python_version >= "3.11" and python_version < "3.12"
idna==3.4 ; python_version >= "3.11" and python_version < "3.12"
iniconfig==2.0.0 ; python_version >= "3.11" and python_version < "3.12"
ipykernel==6.23.1 ; python_version >= "3.11" and python_version < "3.12"
ipython-genutils==0.2.0 ; python_version >= "3.11" and python_version < "3.12"
ipython==8.13.2 ; python_version >= "3.11" and python_version < "3.12"
ipywidgets==8.0.6 ; python_version >= "3.11" and python_version < "3.12"
isoduration==20.11.0 ; python_version >= "3.11" and python_version < "3.12"
jedi==0.18.2 ; python_version >= "3.11" and python_version < "3.12"
jinja2==3.1.2 ; python_version >= "3.11" and python_version < "3.12"
jsonpointer==2.3 ; python_version >= "3.11" and python_version < "3.12"
jsonschema==4.17.3 ; python_version >= "3.11" and python_version < "3.12"
jsonschema[format-nongpl]==4.17.3 ; python_version >= "3.11" and python_version < "3.12"
jupyter-client==8.2.0 ; python_version >= "3.11" and python_version < "3.12"
jupyter-console==6.6.3 ; python_version >= "3.11" and python_version < "3.12"
jupyter-core==5.3.0 ; python_version >= "3.11" and python_version < "3.12"
jupyter-events==0.6.3 ; python_version >= "3.11" and python_version < "3.12"
jupyter-server-terminals==0.4.4 ; python_version >= "3.11" and python_version < "3.12"
jupyter-server==2.5.0 ; python_version >= "3.11" and python_version < "3.12"
jupyter==1.0.0 ; python_version >= "3.11" and python_version < "3.12"
jupyterlab-pygments==0.2.2 ; python_version >= "3.11" and python_version < "3.12"
jupyterlab-widgets==3.0.7 ; python_version >= "3.11" and python_version < "3.12"
jupytext==1.14.5 ; python_version >= "3.11" and python_version < "3.12"
markdown-it-py==2.2.0 ; python_version >= "3.11" and python_version < "3.12"
markdown==3.3.7 ; python_version >= "3.11" and python_version < "3.12"
markupsafe==2.1.2 ; python_version >= "3.11" and python_version < "3.12"
matplotlib-inline==0.1.6 ; python_version >= "3.11" and python_version < "3.12"
mdit-py-plugins==0.3.5 ; python_version >= "3.11" and python_version < "3.12"
mdurl==0.1.2 ; python_version >= "3.11" and python_version < "3.12"
mergedeep==1.3.4 ; python_version >= "3.11" and python_version < "3.12"
mistune==2.0.5 ; python_version >= "3.11" and python_version < "3.12"
mkdocs-autorefs==0.4.1 ; python_version >= "3.11" and python_version < "3.12"
mkdocs-jupyter==0.24.1 ; python_version >= "3.11" and python_version < "3.12"
mkdocs-material-extensions==1.1.1 ; python_version >= "3.11" and python_version < "3.12"
mkdocs-material==9.1.12 ; python_version >= "3.11" and python_version < "3.12"
mkdocs==1.4.3 ; python_version >= "3.11" and python_version < "3.12"
mkdocstrings-python==1.0.0 ; python_version >= "3.11" and python_version < "3.12"
mkdocstrings==0.21.2 ; python_version >= "3.11" and python_version < "3.12"
mkdocstrings[python]==0.21.2 ; python_version >= "3.11" and python_version < "3.12"
mypy-extensions==1.0.0 ; python_version >= "3.11" and python_version < "3.12"
nbclassic==1.0.0 ; python_version >= "3.11" and python_version < "3.12"
nbclient==0.7.4 ; python_version >= "3.11" and python_version < "3.12"
nbconvert==7.4.0 ; python_version >= "3.11" and python_version < "3.12"
nbformat==5.8.0 ; python_version >= "3.11" and python_version < "3.12"
nest-asyncio==1.5.6 ; python_version >= "3.11" and python_version < "3.12"
nodeenv==1.8.0 ; python_version >= "3.11" and python_version < "3.12"
notebook-shim==0.2.3 ; python_version >= "3.11" and python_version < "3.12"
notebook==6.5.4 ; python_version >= "3.11" and python_version < "3.12"
packaging==23.1 ; python_version >= "3.11" and python_version < "3.12"
pandocfilters==1.5.0 ; python_version >= "3.11" and python_version < "3.12"
parso==0.8.3 ; python_version >= "3.11" and python_version < "3.12"
pathspec==0.11.1 ; python_version >= "3.11" and python_version < "3.12"
pexpect==4.8.0 ; python_version >= "3.11" and python_version < "3.12" and sys_platform != "win32"
pickleshare==0.7.5 ; python_version >= "3.11" and python_version < "3.12"
platformdirs==3.5.1 ; python_version >= "3.11" and python_version < "3.12"
pluggy==1.0.0 ; python_version >= "3.11" and python_version < "3.12"
prometheus-client==0.16.0 ; python_version >= "3.11" and python_version < "3.12"
prompt-toolkit==3.0.38 ; python_version >= "3.11" and python_version < "3.12"
psutil==5.9.5 ; python_version >= "3.11" and python_version < "3.12"
ptyprocess==0.7.0 ; python_version >= "3.11" and python_version < "3.12" and os_name != "nt" or python_version >= "3.11" and python_version < "3.12" and sys_platform != "win32"
pure-eval==0.2.2 ; python_version >= "3.11" and python_version < "3.12"
pycparser==2.21 ; python_version >= "3.11" and python_version < "3.12"
pygments==2.15.1 ; python_version >= "3.11" and python_version < "3.12"
pymdown-extensions==10.0.1 ; python_version >= "3.11" and python_version < "3.12"
pyproject-api==1.5.1 ; python_version >= "3.11" and python_version < "3.12"
pyright==1.1.308 ; python_version >= "3.11" and python_version < "3.12"
pyrsistent==0.19.3 ; python_version >= "3.11" and python_version < "3.12"
pytest-cov==4.0.0 ; python_version >= "3.11" and python_version < "3.12"
pytest-mock==3.10.0 ; python_version >= "3.11" and python_version < "3.12"
pytest==7.3.1 ; python_version >= "3.11" and python_version < "3.12"
python-dateutil==2.8.2 ; python_version >= "3.11" and python_version < "3.12"
python-json-logger==2.0.7 ; python_version >= "3.11" and python_version < "3.12"
pywin32==306 ; sys_platform == "win32" and platform_python_implementation != "PyPy" and python_version >= "3.11" and python_version < "3.12"
pywinpty==2.0.10 ; python_version >= "3.11" and python_version < "3.12" and os_name == "nt"
pyyaml-env-tag==0.1 ; python_version >= "3.11" and python_version < "3.12"
pyyaml==6.0 ; python_version >= "3.11" and python_version < "3.12"
pyzmq==25.0.2 ; python_version >= "3.11" and python_version < "3.12"
qtconsole==5.4.3 ; python_version >= "3.11" and python_version < "3.12"
qtpy==2.3.1 ; python_version >= "3.11" and python_version < "3.12"
regex==2023.5.5 ; python_version >= "3.11" and python_version < "3.12"
requests==2.30.0 ; python_version >= "3.11" and python_version < "3.12"
rfc3339-validator==0.1.4 ; python_version >= "3.11" and python_version < "3.12"
rfc3986-validator==0.1.1 ; python_version >= "3.11" and python_version < "3.12"
rich==13.3.5 ; python_version >= "3.11" and python_version < "3.12"
ruff==0.0.267 ; python_version >= "3.11" and python_version < "3.12"
send2trash==1.8.2 ; python_version >= "3.11" and python_version < "3.12"
setuptools==67.7.2 ; python_version >= "3.11" and python_version < "3.12"
shellingham==1.5.0.post1 ; python_version >= "3.11" and python_version < "3.12"
six==1.16.0 ; python_version >= "3.11" and python_version < "3.12"
sniffio==1.3.0 ; python_version >= "3.11" and python_version < "3.12"
soupsieve==2.4.1 ; python_version >= "3.11" and python_version < "3.12"
stack-data==0.6.2 ; python_version >= "3.11" and python_version < "3.12"
terminado==0.17.1 ; python_version >= "3.11" and python_version < "3.12"
tinycss2==1.2.1 ; python_version >= "3.11" and python_version < "3.12"
toml==0.10.2 ; python_version >= "3.11" and python_version < "3.12"
tornado==6.3.2 ; python_version >= "3.11" and python_version < "3.12"
tox==4.5.1 ; python_version >= "3.11" and python_version < "3.12"
traitlets==5.9.0 ; python_version >= "3.11" and python_version < "3.12"
typer[all]==0.9.0 ; python_version >= "3.11" and python_version < "3.12"
typing-extensions==4.5.0 ; python_version >= "3.11" and python_version < "3.12"
uri-template==1.2.0 ; python_version >= "3.11" and python_version < "3.12"
urllib3==2.0.2 ; python_version >= "3.11" and python_version < "3.12"
virtualenv==20.23.0 ; python_version >= "3.11" and python_version < "3.12"
watchdog==3.0.0 ; python_version >= "3.11" and python_version < "3.12"
wcwidth==0.2.6 ; python_version >= "3.11" and python_version < "3.12"
webcolors==1.13 ; python_version >= "3.11" and python_version < "3.12"
webencodings==0.5.1 ; python_version >= "3.11" and python_version < "3.12"
websocket-client==1.5.1 ; python_version >= "3.11" and python_version < "3.12"
widgetsnbextension==4.0.7 ; python_version >= "3.11" and python_version < "3.12"

View File

@ -1,22 +0,0 @@
from typing import Annotated
import typer
from rich import print
# logger = logging.getLogger(__name__)
from proto_docs.logger import logger
app = typer.Typer()
@app.callback()
def main():
logger.debug("Calling main() function")
logger.debug("Exiting main() function")
@app.command()
def commander_1(arg_1: Annotated[int, typer.Option()] = 1):
logger.info("Calling commander_1 function")
print(f"Another command with {arg_1=}")
logger.info("Exiting commander_1 function")

View File

@ -1,44 +0,0 @@
import logging
import logging.config
import logging.handlers
from pathlib import Path
from rich.logging import RichHandler
BASE_DIR = Path(__file__).resolve().parent.parent.parent.absolute()
LOGS_DIR = Path(BASE_DIR, "logs")
LOGS_DIR.mkdir(parents=True, exist_ok=True)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# Create handlers
console_handler = RichHandler(markup=True)
console_handler.setLevel(logging.DEBUG)
info_handler = logging.handlers.RotatingFileHandler(
filename=Path(LOGS_DIR, "info.log"),
maxBytes=10485760, # 1 MB
backupCount=10,
)
info_handler.setLevel(logging.INFO)
error_handler = logging.handlers.RotatingFileHandler(
filename=Path(LOGS_DIR, "error.log"),
maxBytes=10485760, # 1 MB
backupCount=10,
)
error_handler.setLevel(logging.ERROR)
# Create formatters
minimal_formatter = logging.Formatter(fmt="%(message)s")
detailed_formatter = logging.Formatter(
fmt="%(levelname)s %(asctime)s [%(name)s:%(filename)s:%(funcName)s:%(lineno)d]\n%(message)s\n"
)
# Hook it all up
console_handler.setFormatter(fmt=minimal_formatter)
info_handler.setFormatter(fmt=detailed_formatter)
error_handler.setFormatter(fmt=detailed_formatter)
logger.addHandler(hdlr=console_handler)
logger.addHandler(hdlr=info_handler)
logger.addHandler(hdlr=error_handler)

View File

@ -4,6 +4,7 @@ verify_ssl = true
name = "pypi"
[packages]
python-decouple = "*"
langchain = "*"
google-genai = "*"
chromadb = "*"

View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "28be69b45a38197768a0d75d0a4aaf28f019b543b4c51469059041db57c2ef71"
"sha256": "e07757601728009a107744dd9ac5294f41b1d899f9eb933017612d645e232d0c"
},
"pipfile-spec": 6,
"requires": {
@ -212,7 +212,7 @@
"charset-normalizer": {
"hashes": [
"sha256:44251f18cd68a75b56585dd00dae26183e102cd5e0f9f1466e6df5da2ed64ea3",
"sha256:b97e690a2118911e39b4042088092771b4ae3fc3aa86518f84b8cf6888dbdb41",
"sha256:91b36a978b5ae0ee86c394f5a54d6ef44db1de0815eb43de826d41d21e4af3de",
"sha256:d98b1668f06378c6dbefec3b92299716b931cd4e6061f3c875a71ced1780ab85"
],
"markers": "python_version >= '3.7'",
@ -331,14 +331,6 @@
],
"version": "==0.9"
},
"eval-type-backport": {
"hashes": [
"sha256:cb6ad7c393517f476f96d456d0412ea80f0a8cf96f6892834cd9340149111b0a",
"sha256:f0576b4cf01ebb5bd358d02314d31846af5e07678387486e2c798af0e7d849c1"
],
"markers": "python_version < '3.10'",
"version": "==0.2.2"
},
"exceptiongroup": {
"hashes": [
"sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b",
@ -616,11 +608,11 @@
},
"google-genai": {
"hashes": [
"sha256:c48ac44612ad6aadc0bf96b12fa4314756baa16382c890fff793bcb53e9a9cc8"
"sha256:609d61bee73f1a6ae5b47e9c7dd4b469d50318f050c5ceacf835b0f80f79d2d9"
],
"index": "pypi",
"markers": "python_version >= '3.9'",
"version": "==1.1.0"
"version": "==1.2.0"
},
"google-generativeai": {
"hashes": [
@ -642,11 +634,11 @@
"grpc"
],
"hashes": [
"sha256:c3e7b33d15fdca5374cc0a7346dd92ffa847425cc4ea941d970f13680052ec8c",
"sha256:d7abcd75fabb2e0ec9f74466401f6c119a0b498e27370e9be4c94cb7e382b8ed"
"sha256:21398025365f138be356d5923e9168737d94d46a72aefee4a6110a1f23463c86",
"sha256:579de760800d13616f51cf8be00c876f00a9f146d3e6510e19d1f4111758b741"
],
"markers": "python_version >= '3.7'",
"version": "==1.66.0"
"version": "==1.67.0"
},
"grpc-google-iam-v1": {
"hashes": [
@ -841,7 +833,7 @@
"sha256:45e54197d28b7a7f1559e60b95e7c567032b602131fbd588f1497f47880aa68b",
"sha256:71522656f0abace1d072b9e5481a48f07c138e00f079c38c8f883823f9c26bd7"
],
"markers": "python_full_version < '3.10.2'",
"markers": "python_version >= '3.8'",
"version": "==8.5.0"
},
"importlib-resources": {
@ -978,11 +970,11 @@
},
"langchain-core": {
"hashes": [
"sha256:26504cf1e8e6c310adad907b890d4e3c147581cfa7434114f6dc1134fe4bc6d3",
"sha256:a057ebeddd2158d3be14bde341b25640ddf958b6989bd6e47160396f5a8202ae"
"sha256:328688228ece259da734417d477994a69cf8202dea9ed4271f2d792e3575c6fc",
"sha256:81a4097226e180fa6c64e2d2ab38dcacbbc23b64fc109fb15622910fe8951670"
],
"markers": "python_version >= '3.9' and python_version < '4.0'",
"version": "==0.3.34"
"version": "==0.3.35"
},
"langchain-google-genai": {
"hashes": [
@ -1392,7 +1384,7 @@
"sha256:f870204a840a60da0b12273ef34f7051e98c3b5961b61b0c2c1be6dfd64fbcd3",
"sha256:ffa75af20b44f8dba823498024771d5ac50620e6915abac414251bd971b4529f"
],
"markers": "python_version >= '3.9'",
"markers": "python_version < '3.12'",
"version": "==1.26.4"
},
"oauthlib": {
@ -1405,42 +1397,38 @@
},
"onnxruntime": {
"hashes": [
"sha256:006c8d326835c017a9e9f74c9c77ebb570a71174a1e89fe078b29a557d9c3848",
"sha256:016229660adea180e9a32ce218b95f8f84860a200f0f13b50070d7d90e92956c",
"sha256:17ed7382d2c58d4b7354fb2b301ff30b9bf308a1c7eac9546449cd122d21cae5",
"sha256:190103273ea4507638ffc31d66a980594b237874b65379e273125150eb044857",
"sha256:1c3e5d415b78337fa0b1b75291e9ea9fb2a4c1f148eb5811e7212fed02cfffa8",
"sha256:31c12840b1cde4ac1f7d27d540c44e13e34f2345cf3642762d2a3333621abb6a",
"sha256:38475e29a95c5f6c62c2c603d69fc7d4c6ccbf4df602bd567b86ae1138881c49",
"sha256:477b93df4db467e9cbf34051662a4b27c18e131fa1836e05974eae0d6e4cf29b",
"sha256:4b3d723cc154c8ddeb9f6d0a8c0d6243774c6b5930847cc83170bfe4678fafb3",
"sha256:50cbb8dc69d6befad4746a69760e5b00cc3ff0a59c6c3fb27f8afa20e2cab7e7",
"sha256:5bd8b875757ea941cbcfe01582970cc299893d1b65bd56731e326a8333f638a3",
"sha256:636bc1d4cc051d40bc52e1f9da87fbb9c57d9d47164695dfb1c41646ea51ea66",
"sha256:68e7051bef9cfefcbb858d2d2646536829894d72a4130c24019219442b1dd2ed",
"sha256:84fa57369c06cadd3c2a538ae2a26d76d583e7c34bdecd5769d71ca5c0fc750e",
"sha256:9a174073dc5608fad05f7cf7f320b52e8035e73d80b0a23c80f840e5a97c0147",
"sha256:a36511dc07c5c964b916697e42e366fa43c48cdb3d3503578d78cef30417cb84",
"sha256:b2046fc9560f97947bbc1acbe4c6d48585ef0f12742744307d3364b131ac5778",
"sha256:bdc471a66df0c1cdef774accef69e9f2ca168c851ab5e4f2f3341512c7ef4666",
"sha256:c1dfe4f660a71b31caa81fc298a25f9612815215a47b286236e61d540350d7b6",
"sha256:d2d366fbcc205ce68a8a3bde2185fd15c604d9645888703785b61ef174265168",
"sha256:d863e8acdc7232d705d49e41087e10b274c42f09e259016a46f32c34e06dc4fd",
"sha256:dc5430f473e8706fff837ae01323be9dcfddd3ea471c900a91fa7c9b807ec5d3",
"sha256:df2a94179a42d530b936f154615b54748239c2908ee44f0d722cb4df10670f68",
"sha256:e3a4ce906105d99ebbe817f536d50a91ed8a4d1592553f49b3c23c4be2560ae6",
"sha256:fae4b4de45894b9ce7ae418c5484cbf0341db6813effec01bb2216091c52f7fb"
"sha256:06bfbf02ca9ab5f28946e0f912a562a5f005301d0c419283dc57b3ed7969bb7b",
"sha256:0df6f2df83d61f46e842dbcde610ede27218947c33e994545a22333491e72a3b",
"sha256:19c2d843eb074f385e8bbb753a40df780511061a63f9def1b216bf53860223fb",
"sha256:22b0655e2bf4f2161d52706e31f517a0e54939dc393e92577df51808a7edc8c9",
"sha256:4c4b251a725a3b8cf2aab284f7d940c26094ecd9d442f07dd81ab5470e99b83f",
"sha256:5eec64c0269dcdb8d9a9a53dc4d64f87b9e0c19801d9321246a53b7eb5a7d1bc",
"sha256:7b2908b50101a19e99c4d4e97ebb9905561daf61829403061c1adc1b588bc0de",
"sha256:8508887eb1c5f9537a4071768723ec7c30c28eb2518a00d0adcd32c89dea3221",
"sha256:a19bc6e8c70e2485a1725b3d517a2319603acc14c1f1a017dda0afe6d4665b41",
"sha256:bb71a814f66517a65628c9e4a2bb530a6edd2cd5d87ffa0af0f6f773a027d99e",
"sha256:bd386cc9ee5f686ee8a75ba74037750aca55183085bf1941da8efcfe12d5b120",
"sha256:bda6aebdf7917c1d811f21d41633df00c58aff2bef2f598f69289c1f1dabc4b3",
"sha256:c9158465745423b2b5d97ed25aa7740c7d38d2993ee2e5c3bfacb0c4145c49d8",
"sha256:cc01437a32d0042b606f462245c8bbae269e5442797f6213e36ce61d5abdd8cc",
"sha256:d30367df7e70f1d9fc5a6a68106f5961686d39b54d3221f760085524e8d38e16",
"sha256:d3b616bb53a77a9463707bb313637223380fc327f5064c9a782e8ec69c22e6a2",
"sha256:d82daaec24045a2e87598b8ac2b417b1cce623244e80e663882e9fe1aae86410",
"sha256:e50ba5ff7fed4f7d9253a6baf801ca2883cc08491f9d32d78a80da57256a5439",
"sha256:f1f56e898815963d6dc4ee1c35fc6c36506466eff6d16f3cb9848cea4e8c8172",
"sha256:f6243e34d74423bdd1edf0ae9596dd61023b260f546ee17d701723915f06a9f7",
"sha256:fb44b08e017a648924dbe91b82d89b0c105b1adcfe31e90d1dc06b8677ad37be"
],
"version": "==1.19.2"
"version": "==1.20.1"
},
"openai": {
"hashes": [
"sha256:72b0826240ce26026ac2cd17951691f046e5be82ad122d20a8e1b30ca18bd11e",
"sha256:ce1851507218209961f89f3520e06726c0aa7d0512386f0f977e3ac3e4f2472e"
"sha256:dcb7f9fb4fbc3f27e3ffd2d7bf045be9211510d7fafefcef7ad2302cb27484e0",
"sha256:ef3f6864ae2f75fa6296bc9811acf684b95557fcb611fe95734215a8b9150b43"
],
"index": "pypi",
"markers": "python_version >= '3.8'",
"version": "==1.61.1"
"version": "==1.62.0"
},
"opentelemetry-api": {
"hashes": [
@ -1633,10 +1621,10 @@
},
"posthog": {
"hashes": [
"sha256:319036f83436981b3bdc750b0ed067b5439c510ed601933f8fc043d0989c73c6",
"sha256:f749bb4aa4610678c3ea71e0f491cfb2dce570196b9753a04260ff08e52dfb6d"
"sha256:0afd0132055a3da9c6b0ecf763e7f2ce2b66659ef16169883394d0835c30d501",
"sha256:54e9de232459846b1686a0cfb58acb02b7ccda379d837e1eb1c3af62c3775915"
],
"version": "==3.12.1"
"version": "==3.13.0"
},
"propcache": {
"hashes": [
@ -1999,6 +1987,14 @@
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==2.9.0.post0"
},
"python-decouple": {
"hashes": [
"sha256:ba6e2657d4f376ecc46f77a3a615e058d93ba5e465c01bbe57289bfb7cce680f",
"sha256:d0d45340815b25f4de59c974b855bb38d03151d81b037d9e3f463b0c9f8cbd66"
],
"index": "pypi",
"version": "==3.8"
},
"python-dotenv": {
"hashes": [
"sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca",
@ -2108,11 +2104,11 @@
},
"sentry-sdk": {
"hashes": [
"sha256:afa82713a92facf847df3c6f63cec71eb488d826a50965def3d7722aa6f0fdab",
"sha256:c359a1edf950eb5e80cffd7d9111f3dbeef57994cb4415df37d39fda2cf22364"
"sha256:7623cfa9e2c8150948a81ca253b8e2bfe4ce0b96ab12f8cd78e3ac9c490fd92f",
"sha256:a6d38e0fb35edda191acf80b188ec713c863aaa5ad8d5798decb8671d02077b6"
],
"markers": "python_version >= '3.6'",
"version": "==2.20.0"
"version": "==2.21.0"
},
"setproctitle": {
"hashes": [
@ -2873,7 +2869,7 @@
"sha256:2c9958f6430a2040341a52eb608ed6dd93ef4392e02ffe219417c1b28b5dd1f4",
"sha256:ac1bbe05fd2991f160ebce24ffbac5f6d11d83dc90891255885223d42b3cd931"
],
"markers": "python_version < '3.10'",
"markers": "python_version >= '3.9'",
"version": "==3.21.0"
},
"zstandard": {

View File

@ -0,0 +1,31 @@
import os
from decouple import config
from langchain.chat_models import init_chat_model
from langchain_google_vertexai import VertexAIEmbeddings
from langchain_mongodb import MongoDBAtlasVectorSearch
# Get the BASE_URL from the environment variables
GOOGLE_API_KEY = config("GOOGLE_API_KEY", cast=str)
WANDB_API_KEY = config("WANDB_API_KEY", cast=str)
LANGSMITH_API_KEY = config("LANGSMITH_API_KEY", cast=str)
LANGCHAIN_PROJECT = config("LANGCHAIN_PROJECT", cast=str)
# Set environment variables
os.environ["LANGCHAIN_TRACING"] = "true"
os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
os.environ["LANGCHAIN_PROJECT"] = LANGCHAIN_PROJECT
os.environ["LANGCHAIN_API_KEY"] = LANGSMITH_API_KEY
os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY
llm = init_chat_model("gemini-2.0-flash-001", model_provider="google_vertexai")
embeddings = VertexAIEmbeddings(model="text-embedding-004")
vector_store = MongoDBAtlasVectorSearch(
embedding=embeddings,
collection=MONGODB_COLLECTION,
index_name=ATLAS_VECTOR_SEARCH_INDEX_NAME,
relevance_score_fn="cosine",
)