Skip to content

Commit

Permalink
Error details & Generator improvements (#22)
Browse files Browse the repository at this point in the history
* More error checking/code cleanup

* Create ObjectExistsError

* Read templates from files.

Syntax highlighting on templates if helpful. 😊

* Document how to run the generator

* Template type fixes

* Fix generator (note: only tested with manage schema)

* Improve exception

* Regenerate Manage models with 2022.1 schema

* Have pre-commit reformat line ending change

* Allow model/endpoint generation to run separately.

* Lazy-load endpoints

This resulted in a memory usage reduction from ~240Mb to ~50Mb and a time reduction from 2.8s to 136ms when running `python -c 'import pyconnectwise'`.

* Sort child endpoints so the endpoint files always generate the same.

* Regen manage 2022.1 with sorted child endpoints.
  • Loading branch information
sherbang authored Nov 22, 2023
1 parent 617cd64 commit cb70636
Show file tree
Hide file tree
Showing 2,029 changed files with 40,961 additions and 85,082 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ repos:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- repo: https://github.com/psf/black
rev: 23.10.1
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.3
rev: v0.1.4
hooks:
- id: ruff
args:
Expand All @@ -48,7 +48,7 @@ repos:
hooks:
- id: poetry-sort
- repo: https://github.com/python-poetry/poetry
rev: "1.6.0"
rev: "1.7.0"
hooks:
- id: poetry-check

Expand Down
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"recommendations": [
"editorconfig.editorconfig",
"ms-python.isort",
"ms-python.python",
"ms-python.vscode-pylance",
"redhat.vscode-yaml",
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Roadmap:

How-to:
=============
- [pyConnectWise - An API library for ConnectWise Manage and ConnectWise Automate, written in Python](#pyconnectwise---an-api-library-for-connectwise-manage-and-connectwise-automate-written-in-python)
- [Features:](#features)
- [Known Issues:](#known-issues)
- [Roadmap:](#roadmap)
- [How-to:](#how-to)
- [Install](#install)
- [Initializing the API Clients](#initializing-the-api-clients)
- [ConnectWise Manage](#connectwise-manage)
Expand All @@ -60,6 +65,7 @@ How-to:
- [Quick dependencies install on apt-based systems (using pipx to manage python tools)](#quick-dependencies-install-on-apt-based-systems-using-pipx-to-manage-python-tools)
- [Setting up your development environment](#setting-up-your-development-environment)
- [Testing](#testing)
- [Running code generation](#running-code-generation)
- [Supporting the project](#supporting-the-project)

# Install
Expand Down Expand Up @@ -254,6 +260,11 @@ pre-commit install
poetry run pytest
```

## Running code generation
```bash
poetry run python -m pyconnectwise_generator <path to schema file>
```

# Supporting the project
:heart: the project and would like to show your support? Please consider donating to the following charities:
- [Black Dog](https://donate.blackdoginstitute.org.au/)
Expand Down
9 changes: 0 additions & 9 deletions generate_models.sh

This file was deleted.

615 changes: 613 additions & 2 deletions poetry.lock

Large diffs are not rendered by default.

53 changes: 50 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[tool.black]
line-length = 120
skip-string-normalization = false

[tool.isort]
line_length = 120

[tool.poetry]
name = "pyconnectwise"
version = "0.5.1"
Expand Down Expand Up @@ -41,10 +48,39 @@ typing-extensions = "^4.8.0"
[tool.poetry.group.dev.dependencies]
astunparse = "^1.6"
black = "^23.7"
datamodel-code-generator = "^0.23.0"
isort = "^5.12"
pytest = "^7.1"
pytest-timeout = "^2.1"
requests-mock = "^1.11"
typer = "^0.9.0"

[tool.datamodel-codegen]
# These options are ordered/grouped to match documentation:
output-model-type = "pydantic_v2.BaseModel"

# Typing customization
base-class = "pyconnectwise.models.base.connectwise_model.ConnectWiseModel"
enum-field-as-literal = "all"
field-constraints = true
set-default-enum-member = true
use-annotated = true
use-standard-collections = true
use-union-operator = true

#Field customization
capitalise-enum-members = true
remove-special-field-name-prefix = true
snake-case-field = true
use-default = true
use-field-description = true

# Model customization
disable-timestamp = true
collapse-rool-models = true
reuse-model = true
target-python-version = "3.10"
use-title-as-name = true

[build-system]
requires = ["poetry-core"]
Expand All @@ -67,18 +103,29 @@ select = [
"ASYNC",
"B",
"C",
"C90",
"DTZ",
"E",
"F",
"FBT",
"FIX",
"FLY",
"FURB",
"I",
"INP",
"N8",
"PERF",
"PT",
"PTH",
"RET",
"RUF",
"S",
"SIM",
"T10",
"TCH",
"TID",
"TRY",
"UP",
]
# ANN101,ANN102 annotating self,cls is silly
# E501 is replaced by flake8-bugbear B950
Expand All @@ -87,8 +134,7 @@ ignore = ["ANN101", "ANN102", "E402", "E501", "E722"]

src = ["src", "tests"]

# Match black default
line-length = 88
line-length = 120

[tool.ruff.isort]
combine-as-imports = true
Expand All @@ -99,4 +145,5 @@ combine-as-imports = true
"src/pyconnectwise/endpoints/**" = ["A003"]
"src/pyconnectwise/models/**" = ["A003"]
# Documenting return types on pytest tests is pointless
"tests/**" = ["ANN201"]
# S101 - Using assert in tests is fine
"tests/**" = ["ANN201", "S101"]
Loading

0 comments on commit cb70636

Please sign in to comment.