overhangio / tutor

The Docker-based Open edX distribution designed for peace of mind
https://docs.tutor.overhang.io/
GNU Affero General Public License v3.0
939 stars 443 forks source link

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

Open regisb opened 12 months ago

regisb commented 12 months ago

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 .
Abdul-Muqadim-Arbisoft commented 11 months ago

Looking into it

regisb commented 11 months ago

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 commented 10 months ago

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

rohan-saeed commented 8 months ago

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

hinakhadim commented 7 months ago

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

regisb commented 7 months ago

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.