blurstudio / hab

A application environment and launcher
GNU Lesser General Public License v3.0
25 stars 3 forks source link

[Bug]: Default for Site.platform_path_map errors out #58

Open MHendricks opened 1 year ago

MHendricks commented 1 year ago

Summary

The default for Site.platform_path_map's platform is None. If you call this it errors out.

Expected Behavior

I think this should use the current platform, or you should be required to pass the platform.

Steps to Reproduce Behavior

The simplest way to reproduce this is to add a missing test where we pass None to platform.

diff --git a/tests/test_site.py b/tests/test_site.py
index 628873d..fb128f2 100644
--- a/tests/test_site.py
+++ b/tests/test_site.py
@@ -318,6 +318,8 @@ class TestPlatformPathMap:
         monkeypatch.setattr(utils, "Platform", utils.LinuxPlatform)
         site = Site([config_root / "site_main.json"])

+        out = site.platform_path_map("/usr/local/host/root", platform=None)
+
         # Check exact path matches are translated
         out = site.platform_path_map("/usr/local/host/root", platform="linux")
         assert out == "/usr/local/host/root"

This error is raised if you run this tox test command: tox -e py37 -- -vv tests/test_site.py --tb native

Traceback (most recent call last):
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\_pytest\runner.py", line 341, in from_call
    result: Optional[TResult] = func()
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\_pytest\runner.py", line 262, in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\pluggy\_hooks.py", line 433, in __call__
    return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\pluggy\_manager.py", line 112, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\pluggy\_callers.py", line 155, in _multicall
    return outcome.get_result()
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\pluggy\_result.py", line 108, in get_result
    raise exc.with_traceback(exc.__traceback__)
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\pluggy\_callers.py", line 80, in _multicall
    res = hook_impl.function(*args)
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\_pytest\runner.py", line 177, in pytest_runtest_call
    raise e
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\_pytest\runner.py", line 169, in pytest_runtest_call
    item.runtest()
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\_pytest\python.py", line 1788, in runtest
    self.ihook.pytest_pyfunc_call(pyfuncitem=self)
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\pluggy\_hooks.py", line 433, in __call__
    return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\pluggy\_manager.py", line 112, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\pluggy\_callers.py", line 116, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\pluggy\_callers.py", line 80, in _multicall
    res = hook_impl.function(*args)
  File "C:\blur\dev\hab_\.tox\py37\lib\site-packages\_pytest\python.py", line 194, in pytest_pyfunc_call
    result = testfunction(**testargs)
  File "C:\blur\dev\hab_\tests\test_site.py", line 321, in test_linux
    out = site.platform_path_map("/usr/local/host/root", platform=None)
  File "C:\blur\dev\hab_\hab\site.py", line 142, in platform_path_map
    relative = path.relative_to(src)
AttributeError: 'NoneType' object has no attribute 'relative_to'

Environment