Skip to content

Commit

Permalink
Emit warning for deprecated behavior since 2014.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Aug 13, 2024
1 parent c508269 commit 6c42a36
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions lib/python/pyflyby/_importdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import re
import sys
import warnigns

from pathlib import Path

Expand All @@ -27,6 +28,7 @@
else:
from typing import Self

SUPPORT_DEPRECATED_BEHAVIOR = True

@memoize
def _find_etc_dirs():
Expand Down Expand Up @@ -344,7 +346,7 @@ def get_default(cls, target_filename: Union[Filename, str], /):
filenames = _get_python_path("PYFLYBY_PATH", DEFAULT_PYFLYBY_PATH,
target_dirname)
mandatory_imports_filenames = ()
if "SUPPORT DEPRECATED BEHAVIOR":
if SUPPORT_DEPRECATED_BEHAVIOR:
PYFLYBY_PATH = _get_env_var("PYFLYBY_PATH", DEFAULT_PYFLYBY_PATH)
# If the old deprecated environment variables are set, then heed
# them.
Expand All @@ -371,7 +373,15 @@ def get_default(cls, target_filename: Union[Filename, str], /):
default_path = PYFLYBY_PATH
# Expand $PYFLYBY_KNOWN_IMPORTS_PATH.
filenames = _get_python_path(
"PYFLYBY_KNOWN_IMPORTS_PATH", default_path, target_dirname)
"PYFLYBY_KNOWN_IMPORTS_PATH", default_path, target_dirname
)
warnigns.warn(
"The environment variable PYFLYBY_KNOWN_IMPORTS_PATH was"
" deprecated since 2014. But never emitted a warning,"
" please use PYFLYBY_PATH or open an issue"
" if you are still requiring PYFLYBY_KNOWN_IMPORTS_PATH",
DeprecationWarning,
)
logger.debug(
"The environment variable PYFLYBY_KNOWN_IMPORTS_PATH is deprecated. "
"Use PYFLYBY_PATH.")
Expand All @@ -384,8 +394,15 @@ def get_default(cls, target_filename: Union[Filename, str], /):
os.path.join(d,"mandatory_imports") for d in PYFLYBY_PATH]
# Expand $PYFLYBY_MANDATORY_IMPORTS_PATH.
mandatory_imports_filenames = _get_python_path(
"PYFLYBY_MANDATORY_IMPORTS_PATH",
default_path, target_dirname)
"PYFLYBY_MANDATORY_IMPORTS_PATH", default_path, target_dirname
)
warnigns.warn(
"The environment variable PYFLYBY_MANDATORY_IMPORTS_PATH was"
" deprecated since 2014 but never emitted a warning."
" Use PYFLYBY_PATH and write __mandatory_imports__=['...']"
" in your files.",
DeprecationWarning,
)
logger.debug(
"The environment variable PYFLYBY_MANDATORY_IMPORTS_PATH is deprecated. "
"Use PYFLYBY_PATH and write __mandatory_imports__=['...'] in your files.")
Expand Down Expand Up @@ -530,6 +547,13 @@ def _from_filenames(cls, filenames, _mandatory_filenames_deprecated=[]):
:rtype:
`ImportDB`
"""
if _mandatory_filenames_deprecated:
warnigns.warn(
"_mandatory_filenames_deprecated has been deprecated in Pyflyby"
" 1.9.4 and will removed in future versions",
DeprecationWarning,
stacklevel=1,
)
if not isinstance(filenames, (tuple, list)):
# TODO DeprecationWarning July 2024,
# this is internal deprecate not passing a list;
Expand All @@ -539,7 +563,7 @@ def _from_filenames(cls, filenames, _mandatory_filenames_deprecated=[]):
logger.debug("ImportDB: loading [%s], mandatory=[%s]",
', '.join(map(str, filenames)),
', '.join(map(str, _mandatory_filenames_deprecated)))
if "SUPPORT DEPRECATED BEHAVIOR":
if SUPPORT_DEPRECATED_BEHAVIOR:
# Before 2014-10, pyflyby read the following:
# * known_imports from $PYFLYBY_PATH/known_imports/**/*.py or
# $PYFLYBY_KNOWN_IMPORTS_PATH/**/*.py,
Expand Down

0 comments on commit 6c42a36

Please sign in to comment.