openlawlibrary / taf

The Archive Framework
GNU Affero General Public License v3.0
10 stars 10 forks source link

docs: Development Setup should include yubikey dependency #501

Open lukpueh opened 2 months ago

lukpueh commented 2 months ago

I'd expect that running the installation instructions from "Development Setup" would allow to run pytest. This is not the case:

$ pip install -e .[dev]
$ pip install -e .[test]
$ pytest

=================================================================== ERRORS ====================================================================
___________________________________ ERROR collecting taf/tests/test_repository_tool/test_repository_tool.py ___________________________________
ImportError while importing test module '/Users/lukp/tuf/taf/taf/tests/test_repository_tool/test_repository_tool.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.12.4/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
taf/tests/test_repository_tool/test_repository_tool.py:9: in <module>
    import taf.yubikey as yk
taf/yubikey.py:17: in <module>
    from ykman.device import list_all_devices
E   ModuleNotFoundError: No module named 'ykman'

Installing with yubikey extra does the trick: pip install -e .[dev,test,yubikey] (although the yubikey dependency should probably be part of the test extras, if tests need it)

renatav commented 1 month ago

Handle the import similarly to how we handle it in other modules. That should do the trick

renatav commented 1 week ago

So what we need to do here is update taf\taf\tests\test_repository_tool\test_repository_tool.py. If you install yubikey-manager dependency, (install taf by running pip install -e .[yubikey] from the root of the repository), you should be able to run this test using pytest. Then, uninstall yubikey-manager: pip uninstall yubikey-manager. You see this error:

ImportError while loading conftest 'D:\oll\taf\taf\tests\test_repository_tool\conftest.py'. conftest.py:8: in from taf.tools.yubikey.yubikey_utils import ( ....\tools\yubikey__init__.py:3: in from taf.api.yubikey import export_yk_certificate, export_yk_public_pem, get_yk_roles, setup_signing_yubikey, setup_test_yubikey ....\api\yubikey.py:14: in import taf.yubikey as yk ....\yubikey.py:17: in from ykman.device import list_all_devices E ModuleNotFoundError: No module named 'ykman' If you take a closer look at it, there is a import taf.yubikey as yk in this module, but also there are imports from taf.tools.yubikey.yubikey_utils in that conftests (conftest in the same package). The easiest way to fix this would be to create a new package, say test_repository_tool_w_yubikey or something like that. Create a conftest inside that package and then move everything that requires a yubukey to that conftest. E.g. fixtures like

@fixture def targets_yk(pytestconfig): """Targets YubiKey.""" return TargetYubiKey(KEYSTORE_PATH, pytestconfig.option.signature_scheme) Move everything from test_repository_tool to that a module inside this new package. Then skip the whole module if the dependency is not installed.