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

Attempt to fix XManager cli #494

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion etils/epath/gpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
@functools.cache
def _is_tf_installed() -> bool:
"""Checks whether TensorFlow is installed."""
if os.environ.get('EPATH_USE_TF', '').lower() in ['false', 'no', 'f', '0']:
if os.environ['EPATH_USE_TF'].lower() in ['false', 'no', 'f', '0']:
return False
return importlib.util.find_spec('tensorflow') is not None

Expand Down
15 changes: 4 additions & 11 deletions etils/epy/binary_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,17 @@
import sys
from typing import Any

import __main__ # pylint: disable=g-bad-import-order
from etils.epy import py_utils


@functools.cache
def _is_ipython_terminal() -> bool:
"""Returns True if running in a IPython terminal/XManager CLI environment."""
# XManager CLI trigger binary imports

# `epy` is imported before the `runpy.run_module(`, so main is still the
# XManager binary
if __main__.__file__.endswith('xmanager2/client/cli/xm_cli.py'):
return True

# In case `epy` is imported after the XManager CLI, detecting we're in
# `xmanager launch` is non-trivial because the script is launched with
# `runpy.run_module(`, hiding some XManager internals and overwriting
# `__main__`.
# Detecting we're in `xmanager launch` is non-trivial because the script
# is launched with `runpy.run_module(`, hiding some XManager internals.
# Otherwise we could have checked if `__main__.__file__.endswith('xm_cli')`,
# but `__main__` get overwritten here.
if any(flag.startswith('--xm_launch_script=') for flag in sys.argv):
return True

Expand Down
Loading