Skip to content

Commit f942609

Browse files
committed
Replace toml package with tomllib and tomli optionally
1 parent ac60214 commit f942609

File tree

5 files changed

+61
-148
lines changed

5 files changed

+61
-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: "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"

docs/docusaurus.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const config: Config = {
107107
},
108108
prism: {
109109
theme: prismThemes.oneDark,
110-
additionalLanguages: ["bash", "python", "markup-templating", "django", "json", "toml", "yaml"],
110+
additionalLanguages: ["bash", "python", "markup-templating", "django", "json", "yaml"],
111111
},
112112
} satisfies Preset.ThemeConfig,
113113

infrahub_sdk/ctl/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
from pathlib import Path
66

7-
import toml
87
import typer
98
from pydantic import Field, ValidationError, field_validator
109
from pydantic_settings import BaseSettings, SettingsConfigDict
1110

11+
try:
12+
import tomllib
13+
except ModuleNotFoundError:
14+
import tomli as tomllib
15+
1216
DEFAULT_CONFIG_FILE = "infrahubctl.toml"
1317
ENVVAR_CONFIG_FILE = "INFRAHUBCTL_CONFIG"
1418
INFRAHUB_REPO_CONFIG_FILE = ".infrahub.yml"
@@ -59,7 +63,7 @@ def load(self, config_file: str | Path = "infrahubctl.toml", config_data: dict |
5963

6064
if config_file.is_file():
6165
config_string = config_file.read_text(encoding="utf-8")
62-
config_tmp = toml.loads(config_string)
66+
config_tmp = tomllib.loads(config_string)
6367

6468
self._settings = Settings(**config_tmp)
6569
return

0 commit comments

Comments
 (0)