8000 enable preview mode for ruff by Neradoc · Pull Request #243 · adafruit/cookiecutter-adafruit-circuitpython · GitHub
[go: up one dir, main page]

Skip to content

enable preview mode for ruff #243

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

Merged
merged 2 commits into from
Jan 13, 2025
Merged

Conversation

Neradoc
Copy link
Contributor
@Neradoc Neradoc commented Jan 8, 2025

The following warnings appear when runnig pre-commit:

warning: Selection `PLC2401` has no effect because preview is not enabled.
warning: Selection `PLC2801` has no effect because preview is not enabled.
warning: Selection `PLE0643` has no effect because preview is not enabled.
warning: Selection `PLE0704` has no effect because preview is not enabled.
warning: Selection `PLE1141` has no effect because preview is not enabled.
warning: Selection `PLR0202` has no effect because preview is not enabled.
warning: Selection `PLR0203` has no effect because preview is not enabled.
warning: Selection `PLR0904` has no effect because preview is not enabled.
warning: Selection `PLR0914` has no effect because preview is not enabled.
warning: Selection `PLR0916` has no effect because preview is not enabled.
warning: Selection `PLR1702` has no effect because preview is not enabled.
warning: Selection `PLR1704` has no effect because preview is not enabled.
warning: Selection `PLR1733` has no effect because preview is not enabled.
warning: Selection `PLR1736` has no effect because preview is not enabled.
warning: Selection `PLW0108` has no effect because preview is not enabled.
warning: Selection `PLW0245` has no effect because preview is not enabled.
warning: Selection `PLW0604` has no effect because preview is not enabled.
warning: Selection `PLW1501` has no effect because preview is not enabled.
warning: Selection `PLW2101` has no effect because preview is not enabled.

As mentioned in #240 these are a bunch of rules that were added in extend-select that don't do anything because they are only available in preview mode. Preview is a mode that enables additional rules meant to allow testing them before they are added (or not) to the main rules.

If I understand correctly those rules come from converting from pylint, so I assume we want them actually enabled by enabling preview mode. Alternatively to this PR we can remove the rules.

@Neradoc
Copy link
Contributor Author
Neradoc commented Jan 8, 2025

Oh actually I get new errors, because of the new rules I assume, in docs/conf.py

@@ -1,12 +1,10 @@
-# -*- coding: utf-8 -*-
-
+import datetime
 import os
 import sys
-import datetime
 year_duration = (
-    current_year
-    if current_year == creation_year
-    else creation_year + " - " + current_year
+    current_year if current_year == creation_year else creation_year + " - " + current_year
 )

New lines missing in the intersphinx_mapping dictionary. Maybe because the template system does not keep new lines when applying if blocs ? I get this in my library using bus_device.

 intersphinx_mapping = {
-    "python": ("https://docs.python.org/3", None),"BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
-    
+    "python": ("https://docs.python.org/3", None),
+    "BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
     "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
 }

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
{%- if cookiecutter.requires_bus_device in ["y", "yes"] -%}
"BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
{% endif %}
{%- if cookiecutter.requires_register in ["y", "yes"] -%}
"Register": ("https://docs.circuitpython.org/projects/register/en/latest/", None),
{%- endif %}
"CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
}

@Neradoc Neradoc marked this pull request as draft January 8, 2025 02:01
@FoamyGuy
Copy link
Contributor
FoamyGuy commented Jan 8, 2025

The hyphens in the opening / closing tags {%- and -%} control the spacing to some extent.

I believe this diff of the cookiecutter template file should make the resulting generated conf file acceptable to ruff. It inlcudes the changes you mentioned above as well as tweaks to these hyphens to fix the intersphinx_mapping list. Also a few other comments removed that it was flagging on.

ruff_fixes.diff

diff --git a/{{ cookiecutter.__dirname }}/docs/{% if cookiecutter.sphinx_docs in ['y', 'yes'] %}conf.py{% endif %} b/{{ cookiecutter.__dirname }}/docs/{% if cookiecutter.sphinx_docs in ['y', 'yes'] %}conf.py{% endif %}
index fbc00ea..670f368 100644
--- a/{{ cookiecutter.__dirname }}/docs/{% if cookiecutter.sphinx_docs in ['y', 'yes'] %}conf.py{% endif %}	
+++ b/{{ cookiecutter.__dirname }}/docs/{% if cookiecutter.sphinx_docs in ['y', 'yes'] %}conf.py{% endif %}	
@@ -4,9 +4,9 @@
 #
 # SPDX-License-Identifier: MIT
 
+import datetime
 import os
 import sys
-import datetime
 
 sys.path.insert(0, os.path.abspath(".."))
 
@@ -34,10 +34,10 @@ autodoc_preserve_defaults = True
 
 intersphinx_mapping = {
     "python": ("https://docs.python.org/3", None),
-    {%- if cookiecutter.requires_bus_device in ["y", "y
8000
es"] -%}
+    {% if cookiecutter.requires_bus_device in ["y", "yes"] -%}
     "BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
-    {% endif %}
-    {%- if cookiecutter.requires_register in ["y", "yes"] -%}
+    {%- endif %}
+    {% if cookiecutter.requires_register in ["y", "yes"] -%}
     "Register": ("https://docs.circuitpython.org/projects/register/en/latest/", None),
     {%- endif %}
     "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
@@ -59,9 +59,7 @@ project = "{% if cookiecutter.target_bundle != 'CircuitPython Org' %}{% if cooki
 creation_year = "{% now 'utc', '%Y' %}"
 current_year = str(datetime.datetime.now().year)
 year_duration = (
-    current_year
-    if current_year == creation_year
-    else creation_year + " - " + current_year
+    current_year if current_year == creation_year else creation_year + " - " + current_year
 )
 copyright = year_duration + " {{ cookiecutter.author_name }}"
 author = "{{ cookiecutter.author_name }}"
diff --git a/{{ cookiecutter.__dirname }}/docs/{% if cookiecutter.sphinx_docs in ['y', 'yes'] %}conf.py{% endif %} b/{{ cookiecutter.__dirname }}/docs/{% if cookiecutter.sphinx_docs in ['y', 'yes'] %}conf.py{% endif %}
index fbc00ea..cadb1e9 100644
--- a/{{ cookiecutter.__dirname }}/docs/{% if cookiecutter.sphinx_docs in ['y', 'yes'] %}conf.py{% endif %}	
+++ b/{{ cookiecutter.__dirname }}/docs/{% if cookiecutter.sphinx_docs in ['y', 'yes'] %}conf.py{% endif %}	
@@ -1,12 +1,10 @@
-# -*- coding: utf-8 -*-
-
 # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 #
 # SPDX-License-Identifier: MIT
 
+import datetime
 import os
 import sys
-import datetime
 
 sys.path.insert(0, os.path.abspath(".."))
 
@@ -34,10 +32,10 @@ autodoc_preserve_defaults = True
 
 intersphinx_mapping = {
     "python": ("https://docs.python.org/3", None),
-    {%- if cookiecutter.requires_bus_device in ["y", "yes"] -%}
+    {% if cookiecutter.requires_bus_device in ["y", "yes"] -%}
     "BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
-    {% endif %}
-    {%- if cookiecutter.requires_register in ["y", "yes"] -%}
+    {%- endif %}
+    {% if cookiecutter.requires_register in ["y", "yes"] -%}
     "Register": ("https://docs.circuitpython.org/projects/register/en/latest/", None),
     {%- endif %}
     "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
@@ -59,9 +57,7 @@ project = "{% if cookiecutter.target_bundle != 'CircuitPython Org' %}{% if cooki
 creation_year = "{% now 'utc', '%Y' %}"
 current_year = str(datetime.datetime.now().year)
 year_duration = (
-    current_year
-    if current_year == creation_year
-    else creation_year + " - " + current_year
+    current_year if current_year == creation_year else creation_year + " - " + current_year
 )
 copyright = year_duration + " {{ cookiecutter.author_name }}"
 author = "{{ cookiecutter.author_name }}"

I could PR this against your branch if it's easier to get the changes that way, let me know.

@Neradoc
Copy link
Contributor Author
Neradoc commented Jan 12, 2025

Thanks, I think that works, committed it and tested it locally.

@Neradoc Neradoc marked this pull request as ready for review January 12, 2025 21:31
@jepler
Copy link
Contributor
jepler commented Jan 13, 2025

[not saying this needs to be added to this PR:] we should make sure the resulting repo is pre-commit clean during CI.

@jepler jepler requested a review from FoamyGuy January 13, 2025 15:21
Copy link
Contributor
@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

I will address any remaining issues that prevent pre-commit from passing on a freshly generated project in #244

@FoamyGuy FoamyGuy merged commit 788309c into adafruit:main Jan 13, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0