Skip to content

Commit 153da30

Browse files
authored
GH-46544: [CI][Dev][Python] Use pre-commit for autopep8 (#46552)
### Rationale for this change We want to migrate to pre-commit from `archery lint`. ### What changes are included in this PR? Use pre-commit for `autoepep8`. The current `archery lint` configuration limits only the following patterns: https://github.com/apache/arrow/blob/197afc02026d6ded3c45f25dcee15a94294cc5ca/dev/archery/archery/utils/lint.py#L190-L198 ```python patterns = ["python/benchmarks/**/*.py", "python/examples/**/*.py", "python/pyarrow/**/*.py", "python/pyarrow/**/*.pyx", "python/pyarrow/**/*.pxd", "python/pyarrow/**/*.pxi", "dev/*.py", "dev/archery/**/*.py", "dev/release/**/*.py"] ``` But this configuration targets all Python and Cython files under `c_glib/`, `dev/` and `python/` except `python/pyarrow/vendored/**`. So this includes some format fixes. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * GitHub Issue: #46544 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 8afaf95 commit 153da30

File tree

4 files changed

+91
-65
lines changed

4 files changed

+91
-65
lines changed

.pre-commit-config.yaml

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,6 @@ repos:
4848
?^ci/docker/python-.*-wheel-windows-test-vs2022.*\.dockerfile$|
4949
)
5050
types: []
51-
- repo: https://github.com/pycqa/flake8
52-
rev: 6.1.0
53-
hooks:
54-
- id: flake8
55-
name: Python Format
56-
files: ^(python|dev|c_glib|integration)/
57-
types:
58-
- file
59-
- python
60-
exclude: vendored
61-
args: [--config, python/setup.cfg]
6251
- repo: https://github.com/MarcoGorelli/cython-lint
6352
rev: v0.12.5
6453
hooks:
@@ -121,6 +110,43 @@ repos:
121110
alias: matlab-cpp-format
122111
files: >-
123112
^matlab/src/cpp/
113+
- repo: https://github.com/hhatto/autopep8
114+
rev: v2.3.2
115+
hooks:
116+
- id: autopep8
117+
name: Python Format
118+
alias: python-format
119+
args:
120+
- "--global-config"
121+
- "python/setup.cfg"
122+
- "--ignore-local-config"
123+
- "--in-place"
124+
files: >-
125+
^(c_glib|dev|python)/
126+
types:
127+
- file
128+
types_or:
129+
- cython
130+
- python
131+
exclude: >-
132+
(
133+
?^python/pyarrow/vendored/|
134+
)
135+
- repo: https://github.com/pycqa/flake8
136+
rev: 6.1.0
137+
hooks:
138+
- id: flake8
139+
name: Python Lint
140+
alias: python-lint
141+
args:
142+
- "--config"
143+
- "python/setup.cfg"
144+
files: >-
145+
^(c_glib|dev|python)/
146+
exclude: >-
147+
(
148+
?^python/pyarrow/vendored/|
149+
)
124150
- repo: https://github.com/pre-commit/mirrors-clang-format
125151
rev: v14.0.6
126152
hooks:

c_glib/tool/generate-version-header.py

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,32 @@
2626

2727
def main():
2828
parser = argparse.ArgumentParser(
29-
description="Generate C header with version macros")
29+
description="Generate C header with version macros")
3030
parser.add_argument(
31-
"--library",
32-
required=True,
33-
help="The library name to use in macro prefixes")
31+
"--library",
32+
required=True,
33+
help="The library name to use in macro prefixes")
3434
parser.add_argument(
35-
"--version",
36-
required=True,
37-
help="The library version number")
35+
"--version",
36+
required=True,
37+
help="The library version number")
3838
parser.add_argument(
39-
"--input",
40-
type=Path,
41-
required=True,
42-
help="Path to the input template file")
39+
"--input",
40+
type=Path,
41+
required=True,
42+
help="Path to the input template file")
4343
parser.add_argument(
44-
"--output",
45-
type=Path,
46-
required=True,
47-
help="Path to the output file to generate")
44+
"--output",
45+
type=Path,
46+
required=True,
47+
help="Path to the output file to generate")
4848

4949
args = parser.parse_args()
5050

5151
with open(args.input, "r", encoding="utf-8") as input_file, \
5252
open(args.output, "w", encoding="utf-8") as output_file:
5353
write_header(
54-
input_file, output_file, args.library, args.version)
54+
input_file, output_file, args.library, args.version)
5555

5656

5757
def write_header(
@@ -70,13 +70,13 @@ def write_header(
7070
availability_macros = generate_availability_macros(library_name)
7171

7272
replacements = {
73-
"VERSION_MAJOR": str(version_major),
74-
"VERSION_MINOR": str(version_minor),
75-
"VERSION_MICRO": str(version_micro),
76-
"VERSION_TAG": version_tag,
77-
"ENCODED_VERSIONS": encoded_versions,
78-
"VISIBILITY_MACROS": visibility_macros,
79-
"AVAILABILITY_MACROS": availability_macros,
73+
"VERSION_MAJOR": str(version_major),
74+
"VERSION_MINOR": str(version_minor),
75+
"VERSION_MICRO": str(version_micro),
76+
"VERSION_TAG": version_tag,
77+
"ENCODED_VERSIONS": encoded_versions,
78+
"VISIBILITY_MACROS": visibility_macros,
79+
"AVAILABILITY_MACROS": availability_macros,
8080
}
8181

8282
output_file.write(re.sub(
@@ -140,35 +140,35 @@ def generate_availability_macros(library: str) -> str:
140140

141141

142142
ALL_VERSIONS = [
143-
(21, 0),
144-
(20, 0),
145-
(19, 0),
146-
(18, 0),
147-
(17, 0),
148-
(16, 0),
149-
(15, 0),
150-
(14, 0),
151-
(13, 0),
152-
(12, 0),
153-
(11, 0),
154-
(10, 0),
155-
(9, 0),
156-
(8, 0),
157-
(7, 0),
158-
(6, 0),
159-
(5, 0),
160-
(4, 0),
161-
(3, 0),
162-
(2, 0),
163-
(1, 0),
164-
(0, 17),
165-
(0, 16),
166-
(0, 15),
167-
(0, 14),
168-
(0, 13),
169-
(0, 12),
170-
(0, 11),
171-
(0, 10),
143+
(21, 0),
144+
(20, 0),
145+
(19, 0),
146+
(18, 0),
147+
(17, 0),
148+
(16, 0),
149+
(15, 0),
150+
(14, 0),
151+
(13, 0),
152+
(12, 0),
153+
(11, 0),
154+
(10, 0),
155+
(9, 0),
156+
(8, 0),
157+
(7, 0),
158+
(6, 0),
159+
(5, 0),
160+
(4, 0),
161+
(3, 0),
162+
(2, 0),
163+
(1, 0),
164+
(0, 17),
165+
(0, 16),
166+
(0, 15),
167+
(0, 14),
168+
(0, 13),
169+
(0, 12),
170+
(0, 11),
171+
(0, 10),
172172
]
173173

174174

python/pyarrow/_parquet.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ cdef class SortingColumn:
827827

828828
def __repr__(self):
829829
return f"{self.__class__.__name__}(column_index={self.column_index}, " \
830-
f"descending={self.descending}, nulls_first={self.nulls_first})"
830+
f"descending={self.descending}, nulls_first={self.nulls_first})"
831831

832832
def __eq__(self, SortingColumn other):
833833
return (self.column_index == other.column_index and

python/pyarrow/tests/test_fs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ def test_filesystem_from_uri_s3(s3_server):
15971597
host, port, access_key, secret_key = s3_server['connection']
15981598

15991599
uri = f"s3://{access_key}:{secret_key}@mybucket/foo/bar?scheme=http&" \
1600-
f"endpoint_override={host}:{port}&allow_bucket_creation=True"
1600+
f"endpoint_override={host}:{port}&allow_bucket_creation=True"
16011601

16021602
fs, path = FileSystem.from_uri(uri)
16031603
assert isinstance(fs, S3FileSystem)

0 commit comments

Comments
 (0)