Open jharrisonSV opened 1 year ago
omnidep pyproject.toml
, poetry run omnidep pyproject.toml
, or whatever? Of course I say this as a heretic who can't even necessarily use git pre-commit hooks at all, since I'm not necessarily running git from an environment that's capable of accessing the project's Python environment (cygwin vs Windows vs WSL).I should add on the commit hooks: currently we can assume the user is using poetry, so poetry run
should always work. But that's just because it's the only kind of data we can read from pyproject.toml. I've tried to leave a route to support other packaging tools in future, though: there's a fuction read_poetry
that's called unconditionally from main.py
, but that could be replaced with a factory that works out what tool you're using from the contents of pyproject and/or the command line. For projects not using poetry, I could add a feature to read the same project data from setup.py
, or a requirements.txt
file and a dev-requirements.txt
file, or whatever. auto-sort would also have to take account of what kind of input file is used.
On auto-sort I was imagining that you could tell people that it will only sort successfully (or as expected) if they are consistent in their use of comments i.e. all comments refer to the line immediately following or all comments appear on the same line as the dependency. That feels like a pretty fair requirement and also encourages people to take up better commenting habits, which is never a bad thing :).
I have found a Poetry plugin for sorting dependencies https://github.com/andrei-shabanski/poetry-plugin-sort. I haven't tried using it but a brief scan shows it uses tomlkit so maybe that's the way to go. You could even tell people to use that plugin and let that do all the hard work!
After a very quick play around with the plugin I can confirm it does seem to move comments with success.
@jharrisonSV: you don't need support for Python 3.7, do you? I'm adding the wildcard feature, but I've also just removed Python 3.7 support so as to use the latest poetry. If you need it, I could do a release that lets you install it on Python 3.7, even though I'm no longer testing it there.
@jharrisonSV The two changes didn't conflict, so I flipped the order. v0.3.7 of omnidep has the wildcard feature, and v0.3.8 removes support for Python 3.7.
This ticket is now two parts done and one left to do:
my/path/**/*test.py
. One thing that might be useful, but that I haven't supported, is my/path/**/tests/*.py
. It would be a bit fiddlier because I'd have to work out how much of the path is supposed to be globbed -- probably from the first component that contains a wildcard, but I haven't thought it through.--sort
option, but I have put a link to poetry-plugin-sort
in the docs for ODEP006.
Awesome stuff! I have a few suggestions for some potential enhancements that I've spotted whilst using omnidep:
local-test-pattern = "*test.py"
. A common, alternative approach to placing all your test files within atests/
directory is to have them sit within your package itself, alongside the corresponding code that it is testing. Currently if you wish to structure my tests in this way you must list them all individually inlocal-test-paths
, which quickly gets tedious for large projects. This doesn't have to be a new config option necessarily, perhaps just expanding the strings thatlocal-test-paths
can handle.omnidep pyproject.toml --sort
I'd be more than happy to contribute any of these if you deem them useful/valuable.