Skip to content

Commit

Permalink
Merge pull request #654 from mgorny/tomllib
Browse files Browse the repository at this point in the history
Support using built-in tomllib in Python 3.11
  • Loading branch information
hhatto committed Dec 3, 2022
2 parents 74fd023 + 1f74c0b commit d0289ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions autopep8.py
Expand Up @@ -4018,13 +4018,16 @@ def read_config(args, parser):

def read_pyproject_toml(args, parser):
"""Read pyproject.toml and load configuration."""
import tomli
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

config = None

if os.path.exists(args.global_config):
with open(args.global_config, "rb") as fp:
config = tomli.load(fp)
config = tomllib.load(fp)

if not args.ignore_local_config:
parent = tail = args.files and os.path.abspath(
Expand All @@ -4033,7 +4036,7 @@ def read_pyproject_toml(args, parser):
pyproject_toml = os.path.join(parent, "pyproject.toml")
if os.path.exists(pyproject_toml):
with open(pyproject_toml, "rb") as fp:
config = tomli.load(fp)
config = tomllib.load(fp)
break
(parent, tail) = os.path.split(parent)

Expand Down
2 changes: 1 addition & 1 deletion setup.py 100755 → 100644
Expand Up @@ -10,7 +10,7 @@


INSTALL_REQUIRES = (
['pycodestyle >= 2.10.0', 'tomli']
['pycodestyle >= 2.10.0', 'tomli; python_version < "3.11"']
)


Expand Down

0 comments on commit d0289ea

Please sign in to comment.