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] no lexer for filename 'xxx' found #996

Closed
ewels opened this issue Feb 8, 2021 · 5 comments
Closed

[BUG] no lexer for filename 'xxx' found #996

ewels opened this issue Feb 8, 2021 · 5 comments
Labels
accepted Task was accepted bug Something isn't working

Comments

@ewels
Copy link
Contributor

ewels commented Feb 8, 2021

Describe the bug
At the top of the tracebacks for my tool on exceptions I'm getting the following (see this GitHub Actions workflow):

╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /opt/hostedtoolcache/Python/3.7.9/x64/bin/nf-core:8 in <module>              │
│                                                                              │
│ no lexer for filename 'nf-core' found                                        │

Alternatively, if testing locally:

╭─────────────────────── Traceback (most recent call last) ───────────────────────╮
│ /Users/ewels/miniconda3/envs/py3/bin/nf-core:33 in <module>                     │
│                                                                                 │
│ no lexer for filename 'nf-core' found                                           │

Syntax highlighting in the traceback does work correctly locally.

To Reproduce
Any traceback from https://github.com/nf-core/tools has this warning. To test locally I added an assert False statement here and ran nf-core list.

Platform
Linux (GitHub Actions), Mac OSX (locally).

Diagnose

python -m rich.diagnose
❯ python -m rich.diagnose
╭────────────────────────────────────────────────────────── <class 'rich.console.Console'> ───────────────────────────────────────────────────────────╮
│ A high level console interface.                                                                                                                     │
│                                                                                                                                                     │
│ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=151 ColorSystem.TRUECOLOR>                                                                                                       │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                                                     │
│     color_system = 'truecolor'                                                                                                                      │
│         encoding = 'utf-8'                                                                                                                          │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>                                                                    │
│ is_dumb_terminal = False                                                                                                                            │
│       is_jupyter = False                                                                                                                            │
│      is_terminal = True                                                                                                                             │
│   legacy_windows = False                                                                                                                            │
│         no_color = False                                                                                                                            │
│          options = ConsoleOptions(legacy_windows=False, min_width=1, max_width=151, is_terminal=True, encoding='utf-8', justify=None,               │
│                    overflow=None, no_wrap=False, highlight=None)                                                                                    │
│           record = False                                                                                                                            │
│         safe_box = True                                                                                                                             │
│             size = ConsoleDimensions(width=151, height=43)                                                                                          │
│        soft_wrap = False                                                                                                                            │
│           stderr = False                                                                                                                            │
│            style = None                                                                                                                             │
│         tab_size = 8                                                                                                                                │
│            width = 151                                                                                                                              │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
python -m rich._windows
 ❯ python -m rich._windows
platform="Darwin"
WindowsConsoleFeatures(vt=False, truecolor=False)
pip freeze | grep rich
 ❯ pip freeze | grep rich
rich==9.10.0
@willmcgugan
Copy link
Collaborator

It's because the bin/nf-core file doesn't have a .py extension. I could just assume Python, which will be correct 99.9% of the time.

@willmcgugan willmcgugan added accepted Task was accepted bug Something isn't working and removed Needs triage labels Feb 8, 2021
@ewels
Copy link
Contributor Author

ewels commented Feb 8, 2021

I wondered if that was the case. The file in question is auto-generated due to the console_scripts entry_point:

#!/Users/ewels/miniconda3/envs/py3/bin/python3.7
# EASY-INSTALL-ENTRY-SCRIPT: 'nf-core','console_scripts','nf-core'
import re
import sys

# for compatibility with easy_install; see #2198
__requires__ = 'nf-core'

try:
    from importlib.metadata import distribution
except ImportError:
    try:
        from importlib_metadata import distribution
    except ImportError:
        from pkg_resources import load_entry_point


def importlib_load_entry_point(spec, group, name):
    dist_name, _, _ = spec.partition('==')
    matches = (
        entry_point
        for entry_point in distribution(dist_name).entry_points
        if entry_point.group == group and entry_point.name == name
    )
    return next(matches).load()


globals().setdefault('load_entry_point', importlib_load_entry_point)


if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(load_entry_point('nf-core', 'console_scripts', 'nf-core')())

I guess you could also look at the file hashbang if present? But probably not super precise either.

@willmcgugan
Copy link
Collaborator

I guess you could also look at the file hashbang if present? But probably not super precise either.

True, if the first line starts with hash bang and contains the text "python" assume a Python lexer, otherwise plain text. Seems like a reasonable approach.

@willmcgugan
Copy link
Collaborator

Should be fixed in 9.11.0

@ewels
Copy link
Contributor Author

ewels commented Feb 16, 2021

Tested, working great in my hands too. Brilliant stuff - thank you!

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

No branches or pull requests

2 participants