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

[BUG] Importing rich fails with FileNotFoundError if current working directory does not exist #2197

Closed
pradyunsg opened this issue Apr 17, 2022 · 1 comment · Fixed by #2212
Labels
accepted Task was accepted bug Something isn't working

Comments

@pradyunsg
Copy link

Describe the bug

See pypa/pip#11036 (comment) for the original report and reproducer.

Broadly, importing rich fails with a FileNotFoundError since it tries to lookup cwd unconditionally, but it is possible to cwd to not exist.

❯ mkdir y
❯ cd y
❯ rm -rf ../y
❯ python -c "import rich"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/rich-cwd-issue/.venv/lib/python3.9/site-packages/rich/__init__.py", line 16, in <module>
    _IMPORT_CWD = os.path.abspath(os.getcwd())
FileNotFoundError: [Errno 2] No such file or directory

Platform

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?

This is not relevant, but MacOS and VSCode's integrated terminal. :)

❯ python -m rich.diagnose
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=180 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 26                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = True                                                          │
│       is_jupyter = False                                                         │
│      is_terminal = True                                                          │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=180, height=26),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=180,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=26,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=180, height=26)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 180                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-256color',      │
│     'COLORTERM': 'truecolor',      │
│     'CLICOLOR': '1',               │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': 'vscode',      │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Darwin"
❯ pip freeze | grep rich       
rich==12.2.0
@willmcgugan willmcgugan added bug Something isn't working accepted Task was accepted and removed Needs triage labels Apr 17, 2022
@github-actions
Copy link

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Task was accepted bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants