Erotemic / ubelt

A Python utility library with a stdlib like feel and extra batteries. Paths, Progress, Dicts, Downloads, Caching, Hashing: ubelt makes it easy!
Apache License 2.0
719 stars 43 forks source link

Test ubelt/util_platform.py::find_exe:0 fails if which(1) is not installed #113

Closed mgorny closed 2 years ago

mgorny commented 2 years ago

Describe the bug Contrary to the popular belief, which(1) is not part of POSIX base system and it is entirely possible not to have it installed at all. However, ubelt's tests assume that it is always present and fail when it isn't:

________________________________________________________ [xdoctest] find_exe:0 ________________________________________________________
* REASON: TypeError
DOCTEST DEBUG INFO
  XDoc "/tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py::find_exe:0", line 3 <- wrt doctest
  File "/tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py", line 288, <- wrt source file
DOCTEST PART BREAKDOWN
Failed Part:
    1 >>> find_exe('ls')
    2 >>> find_exe('ping')
    3 >>> assert find_exe('which') == find_exe(find_exe('which'))
    4 >>> find_exe('which', multi=True)
    5 >>> find_exe('ping', multi=True)
    6 >>> find_exe('cmake', multi=True)
    7 >>> find_exe('nvcc', multi=True)
    8 >>> find_exe('noexist', multi=True)
DOCTEST TRACEBACK
Traceback (most recent call last):

  File "/usr/lib/python3.8/site-packages/xdoctest/doctest_example.py", line 653, in run
    exec(code, test_globals)

  File "<doctest:/tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py::find_exe:0>", line rel: 3, abs: 288, in <module>
    >>> assert find_exe('which') == find_exe(find_exe('which'))

  File "/tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py", line 318, in find_exe
    for fpath in results:

  File "/tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py", line 315, in <genexpr>
    results = (fpath for fpath in candidates

  File "/tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py", line 386, in find_path
    for candidate in candidates:

  File "/tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py", line 373, in <genexpr>
    candidates = (join(dpath, name) for dpath in dpaths)

  File "/usr/lib/python3.8/posixpath.py", line 90, in join
    genericpath._check_arg_types('join', a, *p)

  File "/usr/lib/python3.8/genericpath.py", line 152, in _check_arg_types
    raise TypeError(f'{funcname}() argument must be str, bytes, or '

TypeError: join() argument must be str, bytes, or os.PathLike object, not 'NoneType'

DOCTEST REPRODUCTION
CommandLine:
    pytest /tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py::find_exe:0
/tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py:288: TypeError
-------------------------------------------------------- Captured stdout call ---------------------------------------------------------
====== <exec> ======
* DOCTEST : /tmp/portage/dev-python/ubelt-1.1.0/work/ubelt-1.1.0/ubelt/util_platform.py::find_exe:0, line 286 <- wrt source file

To Reproduce

  1. Uninstall which(1).
  2. pytest ubelt/util_platform.py::find_exe

Expected behavior Tests passing.

Desktop (please complete the following information):

Erotemic commented 2 years ago

Thanks for the report. This should be fairly easy to fix.

Is this the only place where this happens? (I'd be surprised if it is)

Can I ask the context you are running the tests in? Would it be helpful to have this patched on pypi quickly? Or do you just need the patch merged into main?

mgorny commented 2 years ago

Is this the only place where this happens? (I'd be surprised if it is)

Well, it's the only one that I've noticed. After skipping this one test, everything else passes.

Can I ask the context you are running the tests in? Would it be helpful to have this patched on pypi quickly? Or do you just need the patch merged into main?

I'm packaging ubelt for Gentoo. In this case, I've just decided to deselect this one test, so I don't think there's any hurry to have a new release.

Erotemic commented 2 years ago

Got it. #114 is now merged, so the next release will resolve the issue completely.

mgorny commented 2 years ago

Thanks!

Erotemic commented 2 years ago

@mgorny FYI the patched version 1.1.1 is out now.