Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration script: warn and do not migrate #3046

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions yt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,13 @@ def get_local_config_file():
removal="4.1.0",
)
else:
# We have an issue here: when calling from the command line,
# we do not want this to exit, as it would prevent `yt config migrate`
# from running. The issue is that yt.config (this file) is imported
# from yt.__init__, which is imported *before* yt.utilities.configure
# is executed, so the latter cannot set some internal variable before
# we arrive here.
# The workaround here relies on inspecting the call stack and hopefully
# detect we were called from the CLI.
import inspect

stack = inspect.stack()
if len(stack) < 2 or stack[-2].function != "importlib_load_entry_point":
issue_deprecation_warning(
f"The configuration file {OLD_CONFIG_FILE} is deprecated. "
f"Please migrate your config to {_global_config_file} by running: "
"'yt config migrate'",
since="4.0.0",
removal="4.1.0",
)
raise SystemExit
issue_deprecation_warning(
Copy link
Member Author

@cphyc cphyc Feb 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason we can simplify this is that there is no circular import issue any more AND no SystemExit being raised. The slight caveat is that now yt config migrate will advise users ... to use yt config migrate!

$ yt config migrate
[…]/yt/yt/utilities/logger.py:4: VisibleDeprecationWarning: The configuration file […]/.config/yt/ytrc is deprecated. Please migrate your config to […]/.config/yt/yt.toml by running: 'yt config migrate'
Deprecated since v4.0.0 . This feature will be removed in v4.1.0
  from yt.config import ytcfg
INFO: using configuration file: […]/.config/yt/yt.toml.
Writing a new config file to: […]/.config/yt/yt.toml
Backing up the old config file: […]/.config/yt/ytrc.bak

Note that this shouldn't be an issue as an subsequent calls to yt config migrate won't show the warning and won't do anything (as the config has already been migrated).

f"The configuration file {OLD_CONFIG_FILE} is deprecated. "
f"Please migrate your config to {_global_config_file} by running: "
"'yt config migrate'",
since="4.0.0",
removal="4.1.0",
)


if not os.path.exists(_global_config_file):
Expand Down