Skip to content

Commit

Permalink
closing handles (#1424)
Browse files Browse the repository at this point in the history
  • Loading branch information
roeybc authored Jul 29, 2024
1 parent cd7e547 commit 2fe6ad7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions presidio-analyzer/presidio_analyzer/analyzer_engine_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,28 @@ def get_configuration(

if not conf_file:
default_conf_file = self._get_full_conf_path()
configuration = yaml.safe_load(open(default_conf_file))
with open(default_conf_file) as file:
configuration = yaml.safe_load(file)
logger.info(
f"Analyzer Engine configuration file "
f"not provided. Using {default_conf_file}."
)
else:
try:
logger.info(f"Reading analyzer configuration from {conf_file}")
configuration = yaml.safe_load(open(conf_file))
with open(conf_file) as file:
configuration = yaml.safe_load(file)
except OSError:
logger.warning(
f"configuration file {conf_file} not found. "
f"Using default config."
)
configuration = yaml.safe_load(open(self._get_full_conf_path()))
with open(self._get_full_conf_path()) as file:
configuration = yaml.safe_load(file)
except Exception:
print(f"Failed to parse file {conf_file}, resorting to default")
configuration = yaml.safe_load(open(self._get_full_conf_path()))
with open(self._get_full_conf_path()) as file:
configuration = yaml.safe_load(file)

return configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def _read_nlp_conf(conf_file: Union[Path, str]) -> dict:
)

else:
nlp_configuration = yaml.safe_load(open(conf_file))
with open(conf_file) as file:
nlp_configuration = yaml.safe_load(file)

if "ner_model_configuration" not in nlp_configuration:
logger.warning(
Expand Down

0 comments on commit 2fe6ad7

Please sign in to comment.