5 ms·
The headline is pretty misleading, as the mentioned "best practices" are highly opinionated, as the author also states: > This is my very opinionated attempt t
by Dunedan 5y ago
The headline is pretty misleading, as the mentioned "best practices" are highly opinionated, as the author also states:
> This is my very opinionated attempt to compile some of the best practices on setting up a new Python environment for local development.
- EamonnMR 5y agoThese are fairly close to our working environment (we're using pylint instead of Flake8, haven't switched most of our projects to poetry yet, and we use Pedantic but not MyPy yet.)
- tlocke 5y agoI think you mean Flake8 rather than Sense8? Anyway, gives me a chance to plug Flake8 Alphabetize, a Flake8 plugin for import ordering https://github.com/tlocke/flake8-alphabetize https://github.com/tlocke/flake8-alphabetize
- claytonjy 5y agoHow does this compare/contrast with isort?
- tlocke 5y agoFlake8 Alphabetize will just give you warnings about import order, whereas isort will actually change the code itself. So as I see it there are two types of tool, formatters and checkers. A formatter doesn't alter the Abstract Syntax Tree (AST). In other words it doesn't alter the meaning of the code, just how it looks (eg. the formatter Black). A checker on the other hand looks only at the AST and just gives warnings in your editor, and then it's up to you to change it or not. The import order is fixed in the AST, so it falls outside the scope of Black (which never changes the AST). So I felt there was a need for a tool that worked as a checker that just gives warnings in your editor if your imports don't conform to PEP8, and hence Flake8 Alphabetize. It's worth mentioning that Flake8 Alphabetize follows Black's philosophy of having only one way of doing things, so a project can standardise on Flake8 Alphabetize and everyone's imports will look the same. Anyway, any feedback is welcomed:-)
- claytonjy 5y agoThe checker/formatter distinction makes a lot of sense. Given the choice between the two for a given goal or set of operations, e.g. alphabetize/isort, I'm not sure why I'd settle for a checker. If the fix is deterministic and objective, why would I want to make the fix myself, rather than let the tool handle it?
- tlocke 5y agoMy feeling is that I want anything that could change the meaning of the code to be down to me making a manual edit. So I'm quite happy for the Black formatter to automatically rewrite my code as it never changes its meaning. For anything else I like to be in the driving seat. Anyway, that's just my feeling at the moment, I'm sure others have a different take.
- u678u 5y agoThis is how the internet works now. If you ask a question its rare to get a good answer. If you post a faulty opinion as advice you're more likely get a good answer.
- pjmorris 5y ago"the best way to get the right answer on the internet is not to ask a question; it's to post the wrong answer." - Cunningham's Law [0] [0] https://meta.wikimedia.org/wiki/Cunningham%27s_Law https://meta.wikimedia.org/wiki/Cunningham%27s_Law
- formerly_proven 5y agoThese are pretty solid recommendations overall (pytest, poetry, pyenv). I'd guess the most controversial things would be pre-commit hooks (please no) and using a force-fed autoformatter (DEAR GOD NO).
- uranusjr 5y agopre-commit is actually a very solid linter task runner framework, I would still recommend it even if you don’t like Git pre-commit hooks (just omit the `pre-commit install` part); the `pre-commit run` command is still very useful invoked directly (optionally with --all-files and passing a specific hook id to run).
- niyikiza 5y agoSaying "this marble is red" implicitly communicates that "my opinion is: this marble is red".