[18:42:48] <mrquincy> I'm restructuring a project and referencing this sample implementation: https://github.com/pypa/sampleproject. I'm particularly curious about the decision to include an "src" directory. The commit notes mention "Per the discussions at the PyPA packaging mini-summit at PyCon US 2019, we decided to switch to the safer src/ layout". Can someone offer a bit more explanation on why this safer?
[18:53:45] <ngoldbaum> it means that you can’t import it directly from
[18:54:15] <ngoldbaum> so the tests can’t run based on the version of the code in the repo, you need to actually install it somehow
[18:54:51] <ngoldbaum> (perhaps as an editable install, making the version in the repo the “live” version but you need to explicitly opt into that with the src/ layout)
[18:55:37] <ngoldbaum> there are a whole class of packaging issues caused by people running the version in the repo instead of installing from packaging artifacts in development
[18:55:59] <ngoldbaum> that they only notice when they upload to pypi
[19:15:55] <mrquincy> What is the mechanic of that safety mechanism? How does it prevent us from running tests against an un-versioned package?
[19:17:08] <ngoldbaum> it’s not about the pckage being unversioned, it’s about forcing your test automation software to do something like “pip install .” before running the tests, to make sure that all if the packaging details are actually working correctly
[19:19:01] <mrquincy> I think I understand the intent for testing, thank you. I may be missing something more basic. Why does "src/" solve the problem?
[19:21:46] <ngoldbaum> let’s say you’re working on a module foo, if it lives in a foo/ folder then you (or pytest) can do “import foo” in the root of your repo
[19:22:06] <ngoldbaum> if it’s in src/ you need to explicitly move into that folder for that to work
[19:22:44] <ngoldbaum> so to get pytest to work you need to install the module with pip first
[19:24:44] <ngoldbaum> tox is a good way to make sure this is all working separately from this idiom, but that’s a lot more heavyweight than just promoting this src/ convention
[19:25:36] <ngoldbaum> tox sets up a matrix of python versions and dependency sets and runs tests for each in a virtualenv just for that test environment
[19:33:13] <mrquincy> Thanks for the info on tox, I'll keep that in mind as we make progress.
[19:38:15] <mrquincy> To check my understanding, I assume "src/" solves the problem provided we have the discipline not to import relative to "src" in the pytests, is that right?
[19:44:51] <ngoldbaum> that would be kinda weird and non-idiomatic but yeah
[19:45:05] <ngoldbaum> whereas “import foo” is a kinda natural thing to do
[19:45:21] <ngoldbaum> and you might not realize where exactly foo is being imported from
[19:57:46] <mrquincy> I think I understand now. Thanks for takign the time
[21:17:50] <tos9> mrquincy: FWIW I think the "official position" inasmuch as there is one, is still "both are fine"
[21:18:08] <tos9> mrquincy: (I don't use src/ layout myself, and solve the above problem in another, in my opinion easier, way)
[21:19:29] <tos9> mrquincy: (namely I tell tox to `changedir = {envtmpdir}`, so when it runs, none of the commands it uses think they're alongside the package -- I think that's a thing people should do anyhow, since src/ layout doesn't necessarily prevent depending on repo root directory either, so yeah)
[21:35:01] <mrquincy> Thanks, I'll pitch both methods to our dev group and see what the consensus for us is