OpenAdaptAI / OpenAdapt

Open Source Generative Process Automation (i.e. Generative RPA). AI-First Process Automation with Large ([Language (LLMs) / Action (LAMs) / Multimodal (LMMs)] / Visual Language (VLMs)) Models
https://www.OpenAdapt.AI
MIT License
896 stars 117 forks source link

Refactor config #485

Open abrichr opened 1 year ago

abrichr commented 1 year ago

Feature request

Currently we have:

_DEFAULTS = {
    "FOO": "bar",
    ...
}

This requires lots of linter pragmas. This task involves refactoring simply:

FOO = "bar"

This will involve considering loading variables from .env and saving defaults correctly (e.g. DEFAULTS = locals() ?)

Motivation

Too many linter pragmas when using config vars

Checklist - [X] Extract `openadapt/config.py` ✓ https://github.com/OpenAdaptAI/OpenAdapt/commit/26b994ea64e5e83d7ff4f6f550a5562589db36f4 - [X] Create `tests/test_config.py` ✓ https://github.com/OpenAdaptAI/OpenAdapt/commit/210457c3f2e00bcd9214f82b56af7c934527345e - [X] Check `tests/test_config.py` ✗ - [X] Modify `tests/test_config.py` ! No changes made - [X] Check `tests/test_config.py` ✗ ![Flowchart](http://24.199.78.105:8082/public/f5e1eaea5907d9df0d2d723ddb8396adf0c367cd78b5e196277832d9073958ce_485_flowchart.svg)
sweep-ai[bot] commented 11 months ago

Here's the PR! https://github.com/OpenAdaptAI/OpenAdapt/pull/516.

Sweep Basic Tier: I'm using GPT-4. You have 4 GPT-4 tickets left for the month and 2 for the day.

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

Actions (click)

Sandbox Execution ✓

Here are the sandbox execution logs prior to making any changes:

Sandbox logs for 5708256
pre-commit install 1/4 ✓
pre-commit installed at .git/hooks/pre-commit
trunk init 2/4 ✓
⡿ Downloading Trunk 1.17.2...
⡿ Downloading Trunk 1.17.2...
⢿ Downloading Trunk 1.17.2...
⣻ Downloading Trunk 1.17.2...
⣽ Downloading Trunk 1.17.2...
⣾ Downloading Trunk 1.17.2...
⣷ Downloading Trunk 1.17.2...
✔ Downloading Trunk 1.17.2... done
⡿ Verifying Trunk sha256...
✔ Verifying Trunk sha256... done
⡿ Unpacking Trunk...
✔ Unpacking Trunk... done

✔ 18 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.26 (2 github-workflow files)
  bandit 1.7.5 (75 python files)
  black 23.9.1 (75 python files)
  checkov 3.0.32 (8 yaml files)
  flake8 6.1.0 (75 python files)
  git-diff-check (111 files)
  isort 5.12.0 (75 python files)
  markdownlint 0.37.0 (6 markdown files) (created .markdownlint.yaml)
  osv-scanner 1.4.3 (1 lockfile file)
  oxipng 9.0.0 (8 png files)
  prettier 3.0.3 (6 markdown, 8 yaml files)
  ruff 0.1.5 (75 python files) (created ruff.toml)
  shellcheck 0.9.0 (2 shell files) (created .shellcheckrc)
  shfmt 3.6.0 (2 shell files)
  taplo 0.8.1 (1 toml file)
  trivy 0.47.0 (8 yaml files)
  trufflehog 3.62.1 (111 files)
  yamllint 1.33.0 (8 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
trunk fmt tests/test_config.py || exit 0 3/4 ✓
  NOTICES  
 tests/test_config.py  ignored empty file [black]
 Hint: use --force to check ignored files
Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_config.py 4/4 ✓
  NOTICES  
 tests/test_config.py  ignored empty file [black]
 Hint: use --force to check ignored files
Checked 1 file
✔ No issues

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.

Install Sweep Configs: Pull Request

Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/OpenAdaptAI/OpenAdapt/blob/5708256fab70ba8f661b900d72ed9c76b8662c0a/alembic.ini#L5-L70 https://github.com/OpenAdaptAI/OpenAdapt/blob/5708256fab70ba8f661b900d72ed9c76b8662c0a/openadapt/config.py#L87-L224 https://github.com/OpenAdaptAI/OpenAdapt/blob/5708256fab70ba8f661b900d72ed9c76b8662c0a/CONTRIBUTING.md#L1-L40

Step 2: ⌨️ Coding

trunk fmt tests/test_config.py || exit 0 1/2 ✓
 ✔ Formatted tests/test_config.py
Re-checking autofixed files...

 ✔ Formatted tests/test_config.py
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_config.py 2/2 ❌ (`1`)
  ISSUES  
tests/test_config.py:10:0
 10:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 11:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 23:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 27:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 28:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 29:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
Checked 1 file
✖ 6 new issues

trunk fmt tests/test_config.py || exit 0 1/2 ✓
 ✔ Formatted tests/test_config.py
Re-checking autofixed files...

 ✔ Formatted tests/test_config.py
Re-checking autofixed files...

Checked 1 file
✔ No issues
trunk check --fix --print-failures tests/test_config.py 2/2 ❌ (`1`)
  ISSUES  
tests/test_config.py:10:0
 10:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 11:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 23:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 27:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 28:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
 29:0  low  Use of assert detected. The enclosed code will be removed when compiling to optimised byte       bandit/B101
            code.                                                                                                       
Checked 1 file
✖ 6 new issues


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/refactor-config-management.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord

abrichr commented 11 months ago

Unless there are compelling reasons otherwise, we likely want to go with Pydantic, as per https://github.com/OpenAdaptAI/OpenAdapt/pull/489#issuecomment-1806343167, e.g:

from pydantic import BaseModel, Field
from typing import Optional

class Config(BaseModel):
    cache_dir_path: str = Field(default=".cache")
    cache_enabled: bool = Field(default=True)
    cache_verbosity: int = Field(default=0)
    db_echo: bool = Field(default=False)
    db_fname: str = Field(default="openadapt.db")

config = Config(_env_file='.env')