-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make styles able to be extended by users #103
Make styles able to be extended by users #103
Conversation
3bc1a6f
to
bc364c0
Compare
The build was broken due to
|
tox.ini
Outdated
deps = docutils | ||
deps = | ||
docutils | ||
Pygments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is Pygments here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sigmavirus24 Because I added .. code-block:: python
directive to README.rst. Docutils warns if Pygments is not installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think PyPI supports .. code-block:: python
so I'm not sure it should be used in the readme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sigmavirus24 PyPI supports .. code-block::
directive and it's even colored. 😄 GitHub also supports it and it's colored too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So pkg_resources
as well as iter_entry_points
are expensive. Calling them more times than is necessary seems wasteful. I think what you should do is retrieve all of them once and store away the style entry-point before running any checks.
help=("Style to follow. Available: " | ||
"cryptography, google, smarkets, appnexus, pep8"), | ||
help=("Style to follow. Available: " + | ||
", ".join(cls.list_available_styles())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be sorted otherwise they'll never be displayed the same way twice.
flake8_import_order/checker.py
Outdated
style = Edited(imports) | ||
else: | ||
try: | ||
style_entry_point = next( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably pass the entry-point through to here on the options object so you don't have to delay style loading until here. This also means you're not loading it for each and every file.
flake8_import_order/flake8_linter.py
Outdated
) | ||
for entry_point in entry_points: | ||
yield entry_point.name | ||
|
||
@classmethod | ||
def parse_options(cls, options): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be finding the entry-point here and passing it through on the options
object.
Adjusted a way to load style entry points, and made available style names (in --import-order-style help) sorted. PyCQA#103 (review)
@sigmavirus24 I made it to load a style entry point before |
What things would there be to change more? |
Do you have a use case in mind for this? I'm not sure what the potential uptake is, and how to weigh it against the extra complexity. (I can't take a detailed look until next week, sorry). |
My motivation was to implement some private rules of my work without changing flake8-import-order's code or maintaining its fork. I believe there would be other companies than my work which have their own modified rules of PEP 8 for some rationale. |
Adding onto the This would mean that new styles need not be added directly to this plugin. People can write other plugins that they distribute separately and which can be installed. Someone could then |
https://travis-ci.org/PyCQA/flake8-import-order/builds/196644226 Failure of setuppy build is due to a bug of distutils.command.check [1] which fixed at CPython 2.7.10 [2]. Since Travis CI provides CPython 2.7.9, I changed setuppy build to use Python 3.5 instead to workaround CPython 2.7.9's bug. [1] https://bugs.python.org/issue23063 [2] https://hg.python.org/cpython/rev/38826e21f0db
Failure of |
Ok, I'm convinced and this looks good to me. I'll merge and make a few tweaks before releasing. |
Adjusted a way to load style entry points, and made available style names (in --import-order-style help) sorted. #103 (review)
Thanks for merging! 🙏 |
This patch replaces hardcoded style names with setuptools' entry points.
The group name of extensible entry points is
flake8_import_order.styles
(which follows the convention). Built-in styles also become discovered using entry points so that style names don't have to be hardcoded.Also wrote some docs about extending styles into README.rst, but I'm unsure that my English is fine. If anyone reviews my code and docs I would adjust the patch.
Thanks for the very useful program! 👍