3 ms·
I really dislike the Python convention of plonking source code effectively in the root directory. It means literally any random thing in there can get picked up
by zmmmmm 4y ago
I really dislike the Python convention of plonking source code effectively in the root directory. It means literally any random thing in there can get picked up if you put your package in the PYTHONPATH. Is there a reason the Python world did not standardise on putting source code in a "src" directory like every other language?
- pmontra 4y agoI don't have a single src directory in any of the Elixir, JavaScript, Ruby projects I'm currently working on. Python too, obviously. I got src directories in the Elixir dependencies written in Erlang, in about 12% of the node_modules used by a React project and in the few C extensions I'm using for Ruby. May I conclude that src is uncommon at least in scripting languages? (Elixir is compiled.) Maybe the reason is that there is only source code and there is no need for a separate directory for a build / dist.
- dannyboland 4y agoYeah, I adopted the “src” dir layout after reading this post some time back: https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-str... It describes some of the outdated motivations for the other layouts commonly seen with python, as well as the many benefits of the “src” layout.
- bvrmn 4y agoPost doesn't make sense. It clearly states that you only be sure that package is working by actually installing it into clean virtualenv and testing it there. `src` or any other layout doesn't matter.
- iggy_knights 4y agoThe difference is if you're running tests from your root project directory, the package is importable regardless of whether or not it is installed, as python picks up packages in the current working directory by name. src/ prevents this.
- bvrmn 4y agoBut it doesn't prevent package configuration errors and allows to bdist broken package. What's the point then?
- diarrhea 4y agoPython puts source code in a directory with the package's name. That's why the source code is really under `repo_root/package/`, not under `repo_root/` as you seem to imply. It's just that it's not called `src/`, but `package/` in Python (but that's configurable!). So if you have a project called "splitter", your source code really lives under `splitter/splitter/`. I would agree that seems a bit redundant and `splitter/src` look better, but the source code is not in the project root.