Skip to content

Commit c111658

Browse files
authored
IFC-1811: Replace toml package with tomllib and tomli optionally (#551)
* Replace toml package with tomllib and tomli optionally * fix for mypy errors * update config, add pre-commit config * Make tomli package optional * Add towncrier housekeeping message * update python to uppercase p
1 parent ac60214 commit c111658

File tree

7 files changed

+86
-148
lines changed

7 files changed

+86
-148
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ jobs:
146146
- name: "Install dependencies"
147147
run: npm install
148148
- name: "Setup Python environment"
149-
run: "pip install invoke toml"
149+
run: "pip install invoke"
150150
- name: "Build docs website"
151151
run: "invoke docs"
152152

@@ -176,7 +176,7 @@ jobs:
176176
- name: "Install dependencies"
177177
run: "poetry install --no-interaction --no-ansi --extras ctl"
178178
- name: "Setup environment"
179-
run: "pip install invoke toml"
179+
run: "poetry run pip install invoke"
180180
- name: "Validate generated documentation"
181181
run: "poetry run invoke docs-validate"
182182

@@ -236,7 +236,11 @@ jobs:
236236
run: |
237237
pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }} --python python${{ matrix.python-version }}
238238
poetry config virtualenvs.create true --local
239-
pip install invoke toml codecov
239+
pip install invoke codecov
240+
- name: "Install tomli for Python < 3.11"
241+
if: matrix.python-version == '3.9' || matrix.python-version == '3.10'
242+
run: |
243+
pip install tomli
240244
- name: "Install Package"
241245
run: "poetry install --all-extras"
242246
- name: "Mypy Tests"
@@ -289,7 +293,7 @@ jobs:
289293
run: |
290294
pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }}
291295
poetry config virtualenvs.create true --local
292-
pip install invoke toml codecov
296+
pip install invoke codecov
293297
- name: "Install Package"
294298
run: "poetry install --all-extras"
295299
- name: "Integration Tests"
@@ -362,7 +366,7 @@ jobs:
362366
# run: |
363367
# pipx install poetry==${{ needs.prepare-environment.outputs.POETRY_VERSION }}
364368
# poetry config virtualenvs.create true --local
365-
# pip install invoke toml codecov
369+
# pip install invoke codecov
366370

367371
# - name: "Install Package"
368372
# run: "poetry install --all-extras"

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.3.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: check-ast
8+
- id: check-case-conflict
9+
- id: check-merge-conflict
10+
- id: check-toml
11+
- id: check-yaml
12+
- id: end-of-file-fixer
13+
14+
- repo: https://github.com/astral-sh/ruff-pre-commit
15+
# Ruff version.
16+
rev: v0.11.9
17+
hooks:
18+
# Run the linter.
19+
- id: ruff
20+
args: [--fix]
21+
# Run the formatter.
22+
- id: ruff-format

changelog/528.housekeeping.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace toml package with tomllib and tomli optionally for when Python version is less than 3.11

docs/docusaurus.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const config: Config = {
110110
additionalLanguages: ["bash", "python", "markup-templating", "django", "json", "toml", "yaml"],
111111
},
112112
} satisfies Preset.ThemeConfig,
113-
113+
114114
markdown: {
115115
format: "mdx",
116116
preprocessor: ({ filePath, fileContent }) => {

infrahub_sdk/ctl/config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
from __future__ import annotations
44

5+
import sys
56
from pathlib import Path
67

7-
import toml
88
import typer
99
from pydantic import Field, ValidationError, field_validator
1010
from pydantic_settings import BaseSettings, SettingsConfigDict
1111

12+
if sys.version_info >= (3, 11):
13+
import tomllib
14+
else:
15+
import tomli as tomllib
16+
1217
DEFAULT_CONFIG_FILE = "infrahubctl.toml"
1318
ENVVAR_CONFIG_FILE = "INFRAHUBCTL_CONFIG"
1419
INFRAHUB_REPO_CONFIG_FILE = ".infrahub.yml"
@@ -59,7 +64,7 @@ def load(self, config_file: str | Path = "infrahubctl.toml", config_data: dict |
5964

6065
if config_file.is_file():
6166
config_string = config_file.read_text(encoding="utf-8")
62-
config_tmp = toml.loads(config_string)
67+
config_tmp = tomllib.loads(config_string)
6368

6469
self._settings = Settings(**config_tmp)
6570
return

0 commit comments

Comments
 (0)