Skip to content

Commit cb70636

Browse files
authored
Error details & Generator improvements (#22)
* 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.
1 parent 617cd64 commit cb70636

File tree

2,029 files changed

+40961
-85082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,029 files changed

+40961
-85082
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ repos:
3232
- id: python-check-blanket-noqa
3333
- id: python-check-blanket-type-ignore
3434
- repo: https://github.com/psf/black
35-
rev: 23.10.1
35+
rev: 23.11.0
3636
hooks:
3737
- id: black
3838
- repo: https://github.com/astral-sh/ruff-pre-commit
3939
# Ruff version.
40-
rev: v0.1.3
40+
rev: v0.1.4
4141
hooks:
4242
- id: ruff
4343
args:
@@ -48,7 +48,7 @@ repos:
4848
hooks:
4949
- id: poetry-sort
5050
- repo: https://github.com/python-poetry/poetry
51-
rev: "1.6.0"
51+
rev: "1.7.0"
5252
hooks:
5353
- id: poetry-check
5454

.vscode/extensions.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"recommendations": [
33
"editorconfig.editorconfig",
4-
"ms-python.isort",
54
"ms-python.python",
65
"ms-python.vscode-pylance",
76
"redhat.vscode-yaml",

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Roadmap:
3838

3939
How-to:
4040
=============
41+
- [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)
42+
- [Features:](#features)
43+
- [Known Issues:](#known-issues)
44+
- [Roadmap:](#roadmap)
45+
- [How-to:](#how-to)
4146
- [Install](#install)
4247
- [Initializing the API Clients](#initializing-the-api-clients)
4348
- [ConnectWise Manage](#connectwise-manage)
@@ -60,6 +65,7 @@ How-to:
6065
- [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)
6166
- [Setting up your development environment](#setting-up-your-development-environment)
6267
- [Testing](#testing)
68+
- [Running code generation](#running-code-generation)
6369
- [Supporting the project](#supporting-the-project)
6470

6571
# Install
@@ -254,6 +260,11 @@ pre-commit install
254260
poetry run pytest
255261
```
256262

263+
## Running code generation
264+
```bash
265+
poetry run python -m pyconnectwise_generator <path to schema file>
266+
```
267+
257268
# Supporting the project
258269
:heart: the project and would like to show your support? Please consider donating to the following charities:
259270
- [Black Dog](https://donate.blackdoginstitute.org.au/)

generate_models.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

poetry.lock

Lines changed: 613 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
[tool.black]
2+
line-length = 120
3+
skip-string-normalization = false
4+
5+
[tool.isort]
6+
line_length = 120
7+
18
[tool.poetry]
29
name = "pyconnectwise"
310
version = "0.5.1"
@@ -41,10 +48,39 @@ typing-extensions = "^4.8.0"
4148
[tool.poetry.group.dev.dependencies]
4249
astunparse = "^1.6"
4350
black = "^23.7"
51+
datamodel-code-generator = "^0.23.0"
4452
isort = "^5.12"
4553
pytest = "^7.1"
4654
pytest-timeout = "^2.1"
4755
requests-mock = "^1.11"
56+
typer = "^0.9.0"
57+
58+
[tool.datamodel-codegen]
59+
# These options are ordered/grouped to match documentation:
60+
output-model-type = "pydantic_v2.BaseModel"
61+
62+
# Typing customization
63+
base-class = "pyconnectwise.models.base.connectwise_model.ConnectWiseModel"
64+
enum-field-as-literal = "all"
65+
field-constraints = true
66+
set-default-enum-member = true
67+
use-annotated = true
68+
use-standard-collections = true
69+
use-union-operator = true
70+
71+
#Field customization
72+
capitalise-enum-members = true
73+
remove-special-field-name-prefix = true
74+
snake-case-field = true
75+
use-default = true
76+
use-field-description = true
77+
78+
# Model customization
79+
disable-timestamp = true
80+
collapse-rool-models = true
81+
reuse-model = true
82+
target-python-version = "3.10"
83+
use-title-as-name = true
4884

4985
[build-system]
5086
requires = ["poetry-core"]
@@ -67,18 +103,29 @@ select = [
67103
"ASYNC",
68104
"B",
69105
"C",
106+
"C90",
107+
"DTZ",
70108
"E",
71109
"F",
110+
"FBT",
72111
"FIX",
73112
"FLY",
113+
"FURB",
114+
"I",
115+
"INP",
74116
"N8",
75117
"PERF",
118+
"PT",
76119
"PTH",
77120
"RET",
78121
"RUF",
122+
"S",
79123
"SIM",
124+
"T10",
80125
"TCH",
126+
"TID",
81127
"TRY",
128+
"UP",
82129
]
83130
# ANN101,ANN102 annotating self,cls is silly
84131
# E501 is replaced by flake8-bugbear B950
@@ -87,8 +134,7 @@ ignore = ["ANN101", "ANN102", "E402", "E501", "E722"]
87134

88135
src = ["src", "tests"]
89136

90-
# Match black default
91-
line-length = 88
137+
line-length = 120
92138

93139
[tool.ruff.isort]
94140
combine-as-imports = true
@@ -99,4 +145,5 @@ combine-as-imports = true
99145
"src/pyconnectwise/endpoints/**" = ["A003"]
100146
"src/pyconnectwise/models/**" = ["A003"]
101147
# Documenting return types on pytest tests is pointless
102-
"tests/**" = ["ANN201"]
148+
# S101 - Using assert in tests is fine
149+
"tests/**" = ["ANN201", "S101"]

0 commit comments

Comments
 (0)