Skip to content

Commit 31a76bd

Browse files
authored
Add black and ruff to fix lint/pep/ and other issues automatically (#634)
Add black and ruff to fix lint/pep/ and other issues automatically Summary This PR modernizes and stabilizes the linting and formatting pipeline while keeping OpenStack standards. What Was Done Integrated Ruff for: Import sorting Unused import removal General lint auto-fixes (E, F, I rules) Integrated Black as the canonical code formatter (default line length = 88) Kept flake8 + hacking to enforce OpenStack-specific standards Kept doc8 for documentation validation Updated tox configuration: pep8 environment → CI check-only (no file modifications) fix-pep8 environment → local auto-fix (modifies files) Disabled E501 and E203 in flake8 to avoid conflicts with Black formatting (as recommended by Black documentation) Why to much files changed The large diff is intentional. Black reformatted the entire codebase to a consistent style: Normalized indentation Adjusted line wrapping (88 characters) Standardized slice spacing Reformatted long imports Removed trailing whitespace Applied consistent multiline formatting Ruff additionally: Removed unused imports Sorted imports Cleaned up minor style inconsistencies No functional or behavioral changes were introduced. All changes are formatting and lint normalization only. Why This Is Beneficial Eliminates inconsistent formatting across the repository Reduces CI noise caused by minor style differences Aligns with modern Python tooling practices Provides a single command to auto-fix issues locally CI Behavior CI now runs linting in read-only mode. If formatting is incorrect, CI fails without modifying files. Impact No runtime changes No API changes No test logic changes Formatting and lint normalization only Reviewed-by: Anton Sidelnikov
1 parent ec4ed0d commit 31a76bd

2,054 files changed

Lines changed: 51285 additions & 55721 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/source/conf.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,25 @@
1212
# limitations under the License.
1313

1414
import os
15-
import sys
1615
import warnings
1716

1817
# -- General configuration ----------------------------------------------------
1918

2019
# Add any Sphinx extension module names here, as strings. They can be
2120
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
2221
extensions = [
23-
'sphinx.ext.autodoc',
24-
'otcdocstheme',
25-
'cliff.sphinxext',
22+
"sphinx.ext.autodoc",
23+
"otcdocstheme",
24+
"cliff.sphinxext",
2625
]
2726

2827
# Analytics app name
29-
otcdocs_analytics_app = 'otcextensions'
28+
otcdocs_analytics_app = "otcextensions"
3029

3130
# openstackdocstheme options
32-
#otcdocs_repo_name = 'opentelekomcloud/python-otcextensions'
33-
html_last_updated_fmt = '%Y-%m-%d %H:%M'
34-
html_theme = 'otcdocs'
31+
# otcdocs_repo_name = 'opentelekomcloud/python-otcextensions'
32+
html_last_updated_fmt = "%Y-%m-%d %H:%M"
33+
html_theme = "otcdocs"
3534

3635
# TODO(shade) Set this to true once the build-openstack-sphinx-docs job is
3736
# updated to use sphinx-build.
@@ -43,14 +42,14 @@
4342
# execute "export SPHINX_DEBUG=1" in your terminal to disable
4443

4544
# The suffix of source filenames.
46-
source_suffix = '.rst'
45+
source_suffix = ".rst"
4746

4847
# The master toctree document.
49-
master_doc = 'index'
48+
master_doc = "index"
5049

5150
# General information about the project.
52-
project = u'python-otcextensions'
53-
copyright = u'2021, Various members of the OpenTelekomCloud'
51+
project = "python-otcextensions"
52+
copyright = "2021, Various members of the OpenTelekomCloud"
5453

5554
# A few variables have to be set for the log-a-bug feature.
5655
# gitsha: The SHA checksum of the bug description. Extracted from git log.
@@ -59,16 +58,15 @@
5958
# These variables are passed to the logabug code via html_context.
6059
git_cmd = "/usr/bin/git log | head -n1 | cut -f2 -d' '"
6160
try:
62-
gitsha = os.popen(git_cmd).read().strip('\n')
61+
gitsha = os.popen(git_cmd).read().strip("\n")
6362
except Exception:
6463
warnings.warn("Can not get git sha.")
6564
gitsha = "unknown"
6665

6766
otcdocs_bug_tag = "docs"
6867
pwd = os.getcwd()
6968
# html_context allows us to pass arbitrary values into the html template
70-
html_context = {"pwd": pwd,
71-
"gitsha": gitsha}
69+
html_context = {"pwd": pwd, "gitsha": gitsha}
7270

7371
# If true, '()' will be appended to :func: etc. cross-reference text.
7472
add_function_parentheses = True
@@ -78,7 +76,7 @@
7876
add_module_names = True
7977

8078
# The name of the Pygments (syntax highlighting) style to use.
81-
pygments_style = 'native'
79+
pygments_style = "native"
8280

8381
autodoc_member_order = "bysource"
8482

@@ -91,25 +89,36 @@
9189
theme_include_auto_toc = False
9290

9391
# Output file base name for HTML help builder.
94-
htmlhelp_basename = '%sdoc' % project
92+
htmlhelp_basename = "%sdoc" % project
9593

9694
# Grouping the document tree into LaTeX files. List of tuples
9795
# (source start file, target name, title, author, documentclass
9896
# [howto/manual]).
9997
latex_documents = [
100-
('index',
101-
'%s.tex' % project,
102-
u'%s Documentation' % project,
103-
u'OpenTelekomCloud', 'manual'),
98+
(
99+
"index",
100+
"%s.tex" % project,
101+
"%s Documentation" % project,
102+
"OpenTelekomCloud",
103+
"manual",
104+
),
104105
]
105106

106107
# Include both the class and __init__ docstrings when describing the class
107108
autoclass_content = "both"
108109

109110
# -- Options for cliff.sphinxext plugin ---------------------------------------
110111

111-
autoprogram_cliff_application = 'openstack'
112+
autoprogram_cliff_application = "openstack"
112113

113114
autoprogram_cliff_ignored = [
114-
'--help', '--format', '--column', '--max-width', '--fit-width',
115-
'--print-empty', '--prefix', '--noindent', '--quote']
115+
"--help",
116+
"--format",
117+
"--column",
118+
"--max-width",
119+
"--fit-width",
120+
"--print-empty",
121+
"--prefix",
122+
"--noindent",
123+
"--quote",
124+
]
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Apache 2 header omitted for brevity
22

3-
from openstack import service_description
43
from openstack.fake.v2 import _proxy as _proxy_v2
54

5+
from openstack import service_description
6+
67

78
class FakeService(service_description.ServiceDescription):
89
"""The fake service."""
910

1011
supported_versions = {
11-
'2': _proxy_v2.Proxy,
12+
"2": _proxy_v2.Proxy,
1213
}

doc/source/enforcer.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,27 @@
3434

3535
class EnforcementError(errors.SphinxError):
3636
"""A mismatch between what exists and what's documented"""
37+
3738
category = "Enforcer"
3839

3940

4041
def get_proxy_methods():
4142
"""Return a set of public names on all proxies"""
42-
names = ["otcextensions.sdk.anti_ddos.v1._proxy",
43-
"otcextensions.sdk.auto_scaling.v1._proxy",
44-
"otcextensions.sdk.cce.v1._proxy",
45-
"otcextensions.sdk.ces.v1._proxy",
46-
"otcextensions.sdk.cts.v1._proxy",
47-
"otcextensions.sdk.dcs.v1._proxy",
48-
"otcextensions.sdk.dms.v1._proxy",
49-
"otcextensions.sdk.dns.v2._proxy",
50-
"otcextensions.sdk.kms.v1._proxy",
51-
"otcextensions.sdk.obs.v1._proxy",
52-
"otcextensions.sdk.rds.v1._proxy",
53-
"otcextensions.sdk.rds.v3._proxy",
54-
"otcextensions.sdk.volume_backup.v2._proxy"
55-
]
43+
names = [
44+
"otcextensions.sdk.anti_ddos.v1._proxy",
45+
"otcextensions.sdk.auto_scaling.v1._proxy",
46+
"otcextensions.sdk.cce.v1._proxy",
47+
"otcextensions.sdk.ces.v1._proxy",
48+
"otcextensions.sdk.cts.v1._proxy",
49+
"otcextensions.sdk.dcs.v1._proxy",
50+
"otcextensions.sdk.dms.v1._proxy",
51+
"otcextensions.sdk.dns.v2._proxy",
52+
"otcextensions.sdk.kms.v1._proxy",
53+
"otcextensions.sdk.obs.v1._proxy",
54+
"otcextensions.sdk.rds.v1._proxy",
55+
"otcextensions.sdk.rds.v3._proxy",
56+
"otcextensions.sdk.volume_backup.v2._proxy",
57+
]
5658

5759
modules = (importlib.import_module(name) for name in names)
5860

@@ -92,8 +94,7 @@ def page_context(app, pagename, templatename, context, doctree):
9294
written += 1
9395

9496
if DEBUG:
95-
LOG.info("ENFORCER: Wrote %d proxy methods for %s" % (
96-
written, pagename))
97+
LOG.info("ENFORCER: Wrote %d proxy methods for %s" % (written, pagename))
9798

9899

99100
def build_finished(app, exception):
@@ -113,8 +114,9 @@ def build_finished(app, exception):
113114
missing = all_methods - WRITTEN_METHODS
114115

115116
missing_count = len(missing)
116-
LOG.info("ENFORCER: Found %d missing proxy methods "
117-
"in the output" % missing_count)
117+
LOG.info(
118+
"ENFORCER: Found %d missing proxy methods " "in the output" % missing_count
119+
)
118120

119121
# TODO(shade) This is spewing a bunch of content for missing thing that
120122
# are not actually missing. Leave it as info rather than warn so that the
@@ -128,7 +130,8 @@ def build_finished(app, exception):
128130

129131
if app.config.enforcer_warnings_as_errors and missing_count > 0:
130132
raise EnforcementError(
131-
"There are %d undocumented proxy methods" % missing_count)
133+
"There are %d undocumented proxy methods" % missing_count
134+
)
132135

133136

134137
def setup(app):

0 commit comments

Comments
 (0)