1

I am trying to set MYPYPATH to find a library located in another directory. I am importing a function like this:

from my_module import my_function

The file structure:

function
|__lib1
|  |__lib2
|     |__my_module.py
|__function1
   |__src
      |__index.py  <-- this is the file where my_module is imported

The file structure has to be like this because these are AWS Lambdas (lib1 is the Lambda layer here).

I am using the following tox configuration:

skipsdist = True
envlist = mypy

[testenv]
deps = -r requirements.txt

[testenv:mypy]
commands = mypy --namespace-packages -p function -p test

I tried setting:

setenv = MYPYPATH = './function/lib1/lib2'

setenv = MYPYPATH = './function/lib1/lib2/my_module.py'

as well as

mypy_path = 'function/lib1/lib2'

mypy_path = 'function/lib1/lib2/my_module.py'

I tried full path instead of relative path as well.

However, I'm still getting the same error: error: Cannot find implementation or library stub for module named my_module.

This is not a tox issue, as running mypy --namespace-packages -p function -p test alone produces the same error.

Is there a way to make it work?

Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37
dflss
  • 43
  • 5
  • It is always a good idea to add the command that led to an error. For tox related problems please include the output for `tox -rvv`. You have a very special project setup. It would be much easier to help you when you create a dummy repo with above files/folders, so anybody trying to help you can try it locally. – Jürgen Gmach Jul 20 '21 at 10:38
  • I edited the initial post - the issue lies in mypy configuration itself, not tox. – dflss Jul 20 '21 at 11:08
  • maybe you should add `/full/path/to/lib2` instead of relative path – furas Jul 20 '21 at 11:25
  • I tried full path, but it did not help – dflss Jul 20 '21 at 12:14
  • Were you able to solve this issue? – theberzi Jun 17 '22 at 10:48

0 Answers0