Skip to content

Commit

Permalink
raise import error
Browse files Browse the repository at this point in the history
  • Loading branch information
hirosassa committed Feb 17, 2021
1 parent 58b9034 commit 04b1111
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions yapf/yapflib/file_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ def GetDefaultStyleForDir(dirname, default_style=style.DEFAULT_STYLE):
pass # It's okay if it's not there.
else:
with fd:
import toml
try:
import toml
except ImportError:
raise errors.YapfError(
"toml package is needed for using pyproject.toml as a configuration file"
)

pyproject_toml = toml.load(config_file)
style_dict = pyproject_toml.get('tool', {}).get('yapf', None)
if style_dict is not None:
return config_file
return config_file

if (not dirname or not os.path.basename(dirname) or
dirname == os.path.abspath(os.path.sep)):
Expand Down
7 changes: 6 additions & 1 deletion yapf/yapflib/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,12 @@ def _CreateConfigParserFromConfigFile(config_filename):
with open(config_filename) as style_file:
config = py3compat.ConfigParser()
if config_filename.endswith(PYPROJECT_TOML):
import toml
try:
import toml
except ImportError:
raise errors.YapfError(
"toml package is needed for using pyproject.toml as a configuration file"
)

pyproject_toml = toml.load(style_file)
style_dict = pyproject_toml.get("tool", {}).get("yapf", None)
Expand Down

0 comments on commit 04b1111

Please sign in to comment.