22# -*- coding: utf-8 -*-
33
44import os
5+ import sys
56
67import click
7- import toml
8+
9+ if sys .version_info >= (3 , 11 ):
10+ import tomllib
11+ else :
12+ import tomli as tomllib
813
914
1015def load_toml (settings , subcommand ):
@@ -13,8 +18,8 @@ def load_toml(settings, subcommand):
1318
1419 if os .path .exists (settings ):
1520 if os .path .isfile (settings ):
16- with open (settings , "r " ) as f :
17- config = toml .load (f )
21+ with open (settings , "rb " ) as f :
22+ config = tomllib .load (f )
1823 else :
1924 kci_err ("The --settings location is not a kci-dev config file" )
2025 raise click .Abort ()
@@ -23,43 +28,19 @@ def load_toml(settings, subcommand):
2328 home_dir = os .path .expanduser ("~" )
2429 user_path = os .path .join (home_dir , ".config" , "kci-dev" , fname )
2530 if os .path .exists (user_path ):
26- with open (user_path , "r " ) as f :
27- config = toml .load (f )
31+ with open (user_path , "rb " ) as f :
32+ config = tomllib .load (f )
2833 return config
2934
3035 global_path = os .path .join ("/" , "etc" , fname )
3136 if os .path .exists (global_path ):
32- with open (global_path , "r" ) as f :
33- config = toml .load (f )
34- return config
35-
36- example_configuration = ".kci-dev.toml.example"
37- # Installed with Poetry
38- poetry_example_configuration = os .path .join (
39- os .path .dirname (__file__ ), "../.." , example_configuration
40- )
41- if os .path .exists (poetry_example_configuration ):
42- if subcommand != "config" :
43- kci_err (f"Please use `kci-dev config` to create a config file" )
44- with open (poetry_example_configuration , "r" ) as f :
45- config = toml .load (f )
46- return config
47-
48- # Installed with PyPI
49- kci_err (f"Configuration not found" )
50- pypi_example_configuration = os .path .join (
51- os .path .dirname (__file__ ), ".." , example_configuration
52- )
53- if os .path .exists (pypi_example_configuration ):
54- if subcommand != "config" :
55- kci_err (f"Please use `kci-dev config` to create a config file" )
56- with open (pypi_example_configuration , "r" ) as f :
57- config = toml .load (f )
37+ with open (global_path , "rb" ) as f :
38+ config = tomllib .load (f )
5839 return config
5940
6041 if not config :
6142 kci_err (
62- f"No ` { fname } ` configuration file found at ` { global_path } `, ` { user_path } ` or ` { settings } ` "
43+ f"No config file found, please use `kci-dev config` to create a config file "
6344 )
6445 raise click .Abort ()
6546
0 commit comments