1

The default PyBuilder layout looks like this:

build.py
\ src
  \ main
    \ python
        \ <python packages, etc.. >
  \ unittest 
    \ python
        \ <python unittests, etc.. >

(If you don't understand what PyBuilder is what why the layout looks like this, please go read the PyBuilder documentation.)

How do I make VS Code open the whole project and then recognize only src/main/python and src/unittest/python as source folders?

In other words, if I have a package pete in src/main/python/pete and a module dog in pete, then I want to be able to have a file (e.g. test_pete.py) in src/unittest/python and use import pete.dog in that file.

Marco
  • 8,958
  • 1
  • 36
  • 56
  • What about starting a project and use 'add folder to workspace' on these two folders? – olinox14 Feb 06 '19 at 16:26
  • @olinox14 You haven't actually tried that, have you? ;) – Marco Feb 07 '19 at 11:47
  • You're right, I did'nt tried. I did now, but I'm not sure to understand your need. What do you mean when you say 'recognize as source folders'? – olinox14 Feb 07 '19 at 13:24
  • 1
    I suppose this is a reference to the JetBrains products where you can easily include any folder as a root folder for source code (or tests). – JanRavn May 16 '20 at 17:22

1 Answers1

1

Start by creating a .env file right in the root project. Then add these lines to it:

PYTHONPATH="./src/main/python;./src/unittest/python;${PYTHONPATH}"

For Linux / MacOS, replace ; with :.

More details here: https://code.visualstudio.com/docs/python/environments#_use-of-the-pythonpath-variable

Saba
  • 81
  • 1
  • 4
  • This assumes that I want to use `venv` -- which I don't. Don't get me wrong, `venv` is great, but not part of the answer here. – Marco Jan 08 '21 at 16:13
  • Right. Meant to write `.env` and ended up with `.venv`. The answer should be better now. – Saba Jan 11 '21 at 13:35