Skip to content

Commit b0bf30e

Browse files
chore: Replace black formatter with ruff format (#2568)
* reformat files using ruff format * replace black with ruff format * remove pydocstyle * update static checking * intentionally mess up imports * fix import
1 parent 3507fda commit b0bf30e

Some content is hidden

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

43 files changed

+603
-985
lines changed

.github/workflows/static-checking.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ jobs:
3232
python -m pip install poetry
3333
poetry config virtualenvs.create false --local
3434
poetry install --all-extras -vvv
35-
- name: Black style
36-
run: black --check .
37-
- name: ruff check
38-
run: |
39-
ruff . --ignore "PL" --ignore "D"
40-
ruff awswrangler
35+
- name: Run ruff format
36+
run: ruff format --check .
37+
- name: Run ruff check on source code
38+
run: ruff awswrangler --output-format=github
39+
- name: Run ruff check on tests and tutorials
40+
run: ruff . --ignore "PL" --ignore "D" --output-format=github
4141
- name: mypy check
4242
run: mypy --install-types --non-interactive awswrangler
4343
- name: Pylint Lint

awswrangler/s3/_write.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ def _sanitize(
122122
df = catalog.sanitize_dataframe_columns_names(df=df)
123123
partition_cols = [catalog.sanitize_column_name(p) for p in partition_cols]
124124
if bucketing_info:
125-
bucketing_info = [
126-
catalog.sanitize_column_name(bucketing_col) for bucketing_col in bucketing_info[0]
127-
], bucketing_info[1]
125+
bucketing_info = (
126+
[catalog.sanitize_column_name(bucketing_col) for bucketing_col in bucketing_info[0]],
127+
bucketing_info[1],
128+
)
128129
dtype = {catalog.sanitize_column_name(k): v for k, v in dtype.items()}
129130
_utils.check_duplicated_columns(df=df)
130131
return _SanitizeResult(df, dtype, partition_cols, bucketing_info)
@@ -380,9 +381,7 @@ def write( # pylint: disable=too-many-arguments,too-many-locals,too-many-branch
380381

381382
if (catalog_table_input is None) and (table_type == "GOVERNED"):
382383
self._create_glue_table(**create_table_args) # pylint: disable=protected-access
383-
create_table_args[
384-
"catalog_table_input"
385-
] = catalog._get_table_input( # pylint: disable=protected-access
384+
create_table_args["catalog_table_input"] = catalog._get_table_input( # pylint: disable=protected-access
386385
database=database,
387386
table=table,
388387
boto3_session=boto3_session,

awswrangler/s3/_write_dataset.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def _get_bucketing_series(df: pd.DataFrame, bucketing_info: typing.BucketingInfo
2020
bucket_number_series = (
2121
df[bucketing_info[0]]
2222
# Prevent "upcasting" mixed types by casting to object
23-
.astype("O").apply(
23+
.astype("O")
24+
.apply(
2425
lambda row: _get_bucket_number(bucketing_info[1], [row[col_name] for col_name in bucketing_info[0]]),
2526
axis="columns",
2627
)
@@ -329,9 +330,7 @@ def _to_dataset(
329330
_logger.debug("Wrote %s paths", len(paths))
330331
_logger.debug("Created partitions_values: %s", partitions_values)
331332
if (table_type == "GOVERNED") and (table is not None) and (database is not None):
332-
list_add_objects: List[
333-
List[Dict[str, Any]]
334-
] = lakeformation._build_table_objects( # pylint: disable=protected-access
333+
list_add_objects: List[List[Dict[str, Any]]] = lakeformation._build_table_objects( # pylint: disable=protected-access
335334
paths, partitions_values, use_threads=use_threads, boto3_session=boto3_session
336335
)
337336
try:

fix.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
black .
5-
ruff --fix --select "I001" --select "I002" awswrangler
4+
ruff format .
5+
ruff --fix awswrangler

poetry.lock

Lines changed: 2 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,11 @@ wheel = "^0.38.1"
9797
msgpack = "*"
9898

9999
# Lint
100-
black = "^23.12.0"
101100
boto3-stubs = {version = "^1.26.151", extras = ["athena", "cleanrooms", "chime", "cloudwatch", "dynamodb", "ec2", "emr", "emr-serverless", "glue", "kms", "lakeformation", "logs", "neptune", "opensearch", "opensearchserverless", "quicksight", "rds", "rds-data", "redshift", "redshift-data", "s3", "secretsmanager", "ssm", "sts", "timestream-query", "timestream-write"]}
102101
doc8 = "^1.0"
103102
mypy = "^1.0"
104103
pylint = "^2.17"
105104
ruff = "^0.1.8"
106-
isort = "^5.9.2"
107-
flake8 = "^5.0.1"
108-
pydocstyle = "^6.1.1"
109105

110106
# Test
111107
moto = "^4.1"
@@ -135,32 +131,11 @@ myst-parser = "^1.0.0"
135131
requires = ["poetry-core>=1.0.0"]
136132
build-backend = "poetry.core.masonry.api"
137133

138-
[tool.black]
139-
line-length = 120
140-
target-version = ["py38", "py39", "py310", "py311", "py312"]
141-
extend_exclude = '''
142-
/(
143-
\.eggs
144-
| \.git
145-
| \.hg
146-
| \.mypy_cache
147-
| \.tox
148-
| \.venv
149-
| \.env
150-
| _build
151-
| buck-out
152-
| build
153-
| dist
154-
| .vscode
155-
| dev
156-
| .coverage
157-
)/
158-
'''
159-
160134
[tool.ruff]
161135
select = ["D", "E", "F", "I001", "I002", "PL", "W"]
162136
ignore = ["E501", "PLR2004", "PLR0911", "PLR0912", "PLR0913", "PLR0915"]
163-
fixable = ["I001"]
137+
fixable = ["I001", "I002", "W291"]
138+
extend-include = ["*.ipynb"]
164139
exclude = [
165140
".eggs",
166141
".git",
@@ -177,6 +152,9 @@ exclude = [
177152
line-length = 120
178153
target-version = "py38"
179154

155+
[tool.ruff.lint]
156+
exclude = ["*.ipynb"]
157+
180158
[tool.ruff.pydocstyle]
181159
convention = "numpy"
182160

tests/unit/test_moto.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,13 @@ def moto_subnet_id() -> str:
4141

4242
vpc_id = ec2_client.create_vpc(
4343
CidrBlock="10.0.0.0/16",
44-
)[
45-
"Vpc"
46-
]["VpcId"]
44+
)["Vpc"]["VpcId"]
4745

4846
subnet_id = ec2_client.create_subnet(
4947
VpcId=vpc_id,
5048
CidrBlock="10.0.0.0/24",
5149
AvailabilityZone="us-west-1a",
52-
)[
53-
"Subnet"
54-
]["SubnetId"]
50+
)["Subnet"]["SubnetId"]
5551

5652
yield subnet_id
5753

tutorials/002 - Sessions.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
"metadata": {},
2929
"outputs": [],
3030
"source": [
31-
"import awswrangler as wr\n",
32-
"import boto3"
31+
"import boto3\n",
32+
"\n",
33+
"import awswrangler as wr"
3334
]
3435
},
3536
{

0 commit comments

Comments
 (0)