sjjessop / omnidep

Python linter to compare project dependencies against imports in source code
MIT License
6 stars 0 forks source link

Suggestions for minor enhancements #3

Open jharrisonSV opened 1 year ago

jharrisonSV commented 1 year ago

Awesome stuff! I have a few suggestions for some potential enhancements that I've spotted whilst using omnidep:

I'd be more than happy to contribute any of these if you deem them useful/valuable.

sjjessop commented 1 year ago
sjjessop commented 1 year ago

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.

jharrisonSV commented 1 year ago

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!

jharrisonSV commented 1 year ago

After a very quick play around with the plugin I can confirm it does seem to move comments with success.

sjjessop commented 7 months ago

@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.

sjjessop commented 7 months ago

@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: