tutor icon indicating copy to clipboard operation
tutor copied to clipboard

`make test-types` fails for plugins when tutor is installed in editable mode

Open regisb opened this issue 2 years ago • 6 comments

Bug description

Type tests fail when tutor is installed in editable mode. This is inconvenient when testing plugins locally.

How to reproduce

Install tutor in editable mode:

cd tutor/
pip install -e .[dev]

Run type tests for a plugin:

cd tutorcairn/
make test-types
mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ./tutorcairn
tutorcairn/plugin.py:122: error: Untyped decorator makes function "_print_superset_host" untyped  [misc]
Found 1 error in 1 file (checked 3 source files)
make: *** [Makefile:16: test-types] Error 1

That error is caused by the fact that mypy does not find the tutor module, has the following attests:

$ mypy -m tutor
mypy: can't find module 'tutor'

Additional context

This is a known issue. See the upstream tickets in mypy and setuptools:

https://github.com/python/mypy/issues/13392 https://github.com/pypa/setuptools/issues/3518

The issue can be bypassed by installing tutor in legacy mode:

pip install -e . --config-settings editable_mode=compat

Or by installing in non-editable mode:

pip install .

regisb avatar Dec 06 '23 14:12 regisb

Looking into it

Abdul-Muqadim-Arbisoft avatar Dec 13 '23 11:12 Abdul-Muqadim-Arbisoft

Here's a Dockerfile to reproduce the issue:

# syntax=docker/dockerfile:1
FROM python:3.10

RUN mkdir -p /test

ADD --keep-git-dir=true https://github.com/overhangio/tutor.git#master /test/tutor
ADD --keep-git-dir=true https://github.com/overhangio/tutor-cairn.git#master /test/tutor-cairn

RUN python -m venv /test/venv
ENV PATH /test/venv/bin:${PATH}
RUN pip install --upgrade pip setuptools
RUN pip install -e '/test/tutor[dev]'

WORKDIR /test/tutor-cairn
RUN make test-types
$ docker build .
...
 => ERROR [9/9] RUN make test-types                                                                                                                                                                    2.7s 
------                                                                                                                                                                                                      
 > [9/9] RUN make test-types:                                                                                                                                                                               
0.271 mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ./tutorcairn                                                                                                           
2.636 tutorcairn/plugin.py:120: error: Untyped decorator makes function "_print_superset_host" untyped  [misc]                                                                                              
2.638 Found 1 error in 1 file (checked 3 source files)
2.644 make: *** [Makefile:16: test-types] Error 1
------
Dockerfile:15
--------------------
  13 |     
  14 |     WORKDIR /test/tutor-cairn
  15 | >>> RUN make test-types
  16 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c make test-types" did not complete successfully: exit code: 2

Building the image succeeds when we replace pip install -e by pip install.

regisb avatar Dec 14 '23 09:12 regisb

See this issue in practice in this failed test run: https://github.com/overhangio/tutor-credentials/actions/runs/7568050350/job/20608428713

regisb avatar Jan 23 '24 08:01 regisb

The strict mode also seems to does the trick. It can be acheived through: pip install -e . --config-settings editable_mode=strict

rohan-saeed avatar Mar 29 '24 02:03 rohan-saeed

@regisb Can you please provide insights on it? If there is no more discussion on it, we can close this.

hinakhadim avatar Apr 09 '24 09:04 hinakhadim

This issue is still open. For instance, consider the case of nightly. We are telling people to install tutor with pip install -e ., as they are used to. But that means that they won't be able to run make test-types on their plugins, which is a shame. It's an upstream issue, and I don't know if we can address it in Tutor, but I don't think it should be closed.

regisb avatar Apr 09 '24 09:04 regisb