Skip to content

Commit 7ee89c2

Browse files
martin-gRyanSkraba
andauthored
AVRO-4232: [Python] Modernize the Python tooling (#3658)
* AVRO-4232: [Python] Modernize the Python tooling Use `uv` for management and `ruff` for linting and formatting * Ignore uv.lock for ASFv2 licence check * Add librt as a dev dependency * Drop librt as dev-dep. It fails at CI with another error * Do not test Python 3.9 since it is not supported Test 3.14 instead * Try with mypy<1.19 python/mypy#20454 * Use uv for the Java interop tests too * Remove the flake8 settings. Now we use ruff * Update uv.lock * Set cwd to lang/py for `uv sync`. Do not use uv for C# scripts * Update the usage. Wrap variables in quotes * Move more entries from setup.cfg to pyproject.toml * Remove typechecks dependency. It seems to be tox specific * Do not shadow Python built-in `type` * Use `--frozen` for `uv sync` in CI * Update setup-uv Github action to v7 * Fix the package name for AvroException * First declare the local variable and then assign it a value * Use Python 3.10 for mypy * Move "scripts" from setup.cfg to pyproject.toml * Re-add the optional dependencies from setup.cfg to pyproject.toml * Re-add the package-data from setup.cfg to pyproject.toml * Use SHA for the external actions Policy by Infra: https://infra.apache.org/github-actions-policy.html > External actions Last allowed version: 7.1.6 (https://github.com/apache/infrastructure-actions/blob/2943971f47fadefa6d86af85c2c24c2cee262ee1/actions.yml#L25-L26) Co-authored-by: Ryan Skraba <ryan@skraba.com> * No need to call `build.sh` thru `uv run` --------- Co-authored-by: Ryan Skraba <ryan@skraba.com>
1 parent 22e76d6 commit 7ee89c2

17 files changed

Lines changed: 1282 additions & 321 deletions

.github/workflows/test-lang-java.yml

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
name: 'Test Java'
16+
name: "Test Java"
1717
on:
1818
workflow_dispatch:
1919
push:
20-
branches: [ main ]
20+
branches: [main]
2121
pull_request:
22-
branches: [ main ]
22+
branches: [main]
2323
paths:
24-
- .github/workflows/test-lang-java.yml
25-
- lang/java/**
26-
- pom.xml
24+
- .github/workflows/test-lang-java.yml
25+
- lang/java/**
26+
- pom.xml
2727

2828
defaults:
2929
run:
@@ -35,137 +35,139 @@ concurrency:
3535

3636
jobs:
3737
test:
38-
name: 'Java Test'
38+
name: "Java Test"
3939
runs-on: ${{ matrix.os }}
4040
strategy:
4141
matrix:
42-
os:
42+
os:
4343
- ubuntu-latest
4444
- ubuntu-24.04-arm
4545
steps:
46-
- name: 'Checkout sourcecode'
46+
- name: "Checkout sourcecode"
4747
uses: actions/checkout@v6
4848

49-
- name: 'Cache Local Maven Repository'
49+
- name: "Cache Local Maven Repository"
5050
uses: actions/cache@v5
5151
with:
5252
path: ~/.m2/repository
5353
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
5454
restore-keys: |
5555
${{ runner.os }}-maven-
5656
57-
- name: 'Setup Temurin JDK 11, 17 & 21'
57+
- name: "Setup Temurin JDK 11, 17 & 21"
5858
uses: actions/setup-java@v5
5959
with:
60-
distribution: 'temurin'
60+
distribution: "temurin"
6161
java-version: |
6262
11
6363
17
6464
21
6565
66-
- name: 'Setup Maven 3.9.11'
66+
- name: "Setup Maven 3.9.11"
6767
uses: stCarolas/setup-maven@d6af6abeda15e98926a57b5aa970a96bb37f97d1 # v5
6868
with:
6969
maven-version: 3.9.11
7070

71-
- name: 'Install Java Avro Toplevel'
71+
- name: "Install Java Avro Toplevel"
7272
working-directory: ./
7373
run: mvn -B install -PskipQuality -DskipTests
7474

75-
- name: 'Java Lint'
75+
- name: "Java Lint"
7676
run: ./build.sh lint
7777

78-
- name: 'Java Test'
78+
- name: "Java Test"
7979
run: ./build.sh test
8080

81-
- name: 'Install Java Avro'
81+
- name: "Install Java Avro"
8282
working-directory: .
8383
run: mvn -B clean install -PskipQuality -DskipTests
8484

85-
- name: 'Test Reproducible Build'
85+
- name: "Test Reproducible Build"
8686
working-directory: .
8787
run: mvn clean verify -PskipQuality artifact:compare
8888

8989
interop:
90-
name: 'Java Interop'
90+
name: "Java Interop"
9191
runs-on: ${{ matrix.os }}
9292
strategy:
9393
matrix:
94-
os:
94+
os:
9595
- ubuntu-latest
9696
- ubuntu-24.04-arm
9797

9898
steps:
9999
- uses: actions/checkout@v6
100100

101-
- name: 'Cache Local Maven Repository'
101+
- name: "Cache Local Maven Repository"
102102
uses: actions/cache@v5
103103
with:
104104
path: ~/.m2/repository
105105
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
106106
restore-keys: |
107107
${{ runner.os }}-maven-
108108
109-
- name: 'Setup Temurin JDK 11, 17 & 21'
109+
- name: "Setup Temurin JDK 11, 17 & 21"
110110
uses: actions/setup-java@v5
111111
with:
112-
distribution: 'temurin'
112+
distribution: "temurin"
113113
java-version: |
114114
11
115115
17
116116
21
117117
118-
- name: 'Setup Maven 3.9.11'
118+
- name: "Setup Maven 3.9.11"
119119
uses: stCarolas/setup-maven@d6af6abeda15e98926a57b5aa970a96bb37f97d1 # v5
120120
with:
121121
maven-version: 3.9.11
122122

123-
- name: 'Setup Python for Generating Input Data'
123+
- name: "Setup Python for Generating Input Data"
124124
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
125125
with:
126-
python-version: '3.12'
126+
python-version: "3.12"
127127

128-
- name: 'Apt Install Compression Libs Required by Python'
128+
- name: Setup uv
129+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867
130+
131+
- name: "Apt Install Compression Libs Required by Python"
129132
run: |
130133
sudo apt-get update && \
131134
sudo apt-get install -qqy --no-install-recommends libbz2-dev \
132135
liblzma-dev \
133136
libsnappy-dev \
134137
libzstd-dev
135138
136-
- name: 'Install Python Dependencies'
137-
run: |
138-
python3 -m pip install --break-system-packages --upgrade pip setuptools tox
139-
python3 -m pip install --break-system-packages python-snappy zstandard
139+
- name: "Install Python Dependencies"
140+
working-directory: lang/py
141+
run: uv sync --frozen
140142

141-
- name: 'Setup C# for Generating Interop Data'
143+
- name: "Setup C# for Generating Interop Data"
142144
uses: actions/setup-dotnet@v5
143145
with:
144146
dotnet-version: |
145147
6.0.x
146148
7.0.x
147149
8.0.x
148150
149-
- name: 'Create Interop Data Directory'
151+
- name: "Create Interop Data Directory"
150152
working-directory: .
151153
run: mkdir -p build/interop/data
152154

153-
- name: 'Generate Interop Data using Python'
155+
- name: "Generate Interop Data using Python"
154156
working-directory: lang/py
155157
run: ./build.sh interop-data-generate
156158

157-
- name: 'Generate Interop Data using C#'
159+
- name: "Generate Interop Data using C#"
158160
working-directory: lang/csharp
159161
run: ./build.sh interop-data-generate
160162

161-
- name: 'Install Java Avro for other tests'
163+
- name: "Install Java Avro for other tests"
162164
working-directory: .
163165
run: mvn -B install -PskipQuality
164166

165-
- name: 'Generate Interop Data using Java 11, 17 & 21'
167+
- name: "Generate Interop Data using Java 11, 17 & 21"
166168
working-directory: lang/java/interop-data-test
167169
run: mvn -B verify -Pgenerate-test-data
168170

169-
- name: 'Run Interop Tests using Java 11, 17 & 21'
171+
- name: "Run Interop Tests using Java 11, 17 & 21"
170172
working-directory: lang/java/interop-data-test
171173
run: mvn -B verify -Pcheck-test-data

.github/workflows/test-lang-py.yml

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
name: 'Test Python'
16+
name: "Test Python"
1717
on:
1818
workflow_dispatch:
1919
push:
20-
branches: [ main ]
20+
branches: [main]
2121
pull_request:
22-
branches: [ main ]
22+
branches: [main]
2323
paths:
24-
- .github/workflows/test-lang-py.yml
25-
- lang/py/**
24+
- .github/workflows/test-lang-py.yml
25+
- lang/py/**
2626

2727
defaults:
2828
run:
@@ -38,16 +38,17 @@ jobs:
3838
strategy:
3939
fail-fast: false
4040
matrix:
41-
os:
41+
os:
4242
- ubuntu-latest
4343
- ubuntu-24.04-arm
4444
python:
45-
- '3.13'
46-
- '3.12'
47-
- '3.11'
48-
- '3.10'
49-
- 'pypy-3.11'
50-
- 'pypy-3.10'
45+
- "3.14"
46+
- "3.13"
47+
- "3.12"
48+
- "3.11"
49+
- "3.10"
50+
- "pypy-3.11"
51+
- "pypy-3.10"
5152

5253
steps:
5354
- uses: actions/checkout@v6
@@ -57,6 +58,9 @@ jobs:
5758
with:
5859
python-version: ${{ matrix.python }}
5960

61+
- name: Setup uv
62+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867
63+
6064
- name: Apt Install Compression Libs
6165
run: |
6266
sudo apt-get update && \
@@ -67,33 +71,30 @@ jobs:
6771
libzstd-dev
6872
6973
- name: Install Dependencies
70-
run: |
71-
python3 -m pip install --upgrade pip setuptools tox
74+
run: uv sync --frozen
7275

7376
- name: Lint
7477
if: ${{ matrix.python == '3.10' }}
75-
run: python3 -m tox -e lint
78+
run: ./build.sh lint
7679

7780
- name: Typechecks
7881
if: ${{ matrix.python == '3.10' }}
79-
run: python3 -m tox -e typechecks
82+
run: ./build.sh typechecks
8083

8184
- name: Test
82-
run: python3 -m tox -e py
85+
run: ./build.sh test
8386

8487
interop:
8588
runs-on: ${{ matrix.os }}
8689
strategy:
8790
fail-fast: false
8891
matrix:
89-
os:
92+
os:
9093
- ubuntu-latest
9194
- ubuntu-24.04-arm
9295
python:
93-
- '3.11'
94-
- '3.10'
95-
- '3.9'
96-
- 'pypy-3.10'
96+
- "3.13"
97+
- "3.12"
9798

9899
steps:
99100
- uses: actions/checkout@v6
@@ -103,6 +104,9 @@ jobs:
103104
with:
104105
python-version: ${{ matrix.python }}
105106

107+
- name: Setup uv
108+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867
109+
106110
- name: Apt Install Compression Libs
107111
run: |
108112
sudo apt-get update && \
@@ -113,9 +117,7 @@ jobs:
113117
libzstd-dev
114118
115119
- name: Install Dependencies
116-
run: |
117-
python3 -m pip install --upgrade pip setuptools tox
118-
python3 -m pip install python-snappy zstandard
120+
run: uv sync --frozen
119121

120122
- name: Cache Local Maven Repository
121123
uses: actions/cache@v5
@@ -125,17 +127,17 @@ jobs:
125127
restore-keys: |
126128
${{ runner.os }}-maven-
127129
128-
- name: 'Setup Temurin JDK 8, 11, 17 & 21'
130+
- name: "Setup Temurin JDK 8, 11, 17 & 21"
129131
uses: actions/setup-java@v5
130132
with:
131-
distribution: 'temurin'
133+
distribution: "temurin"
132134
java-version: |
133135
8
134136
11
135137
17
136138
21
137139
138-
- name: 'Setup Maven 3.9.11'
140+
- name: "Setup Maven 3.9.11"
139141
uses: stCarolas/setup-maven@d6af6abeda15e98926a57b5aa970a96bb37f97d1 # v5
140142
with:
141143
maven-version: 3.9.11

lang/py/avro/ipc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def respond(self, call_request):
322322
else:
323323
writers_schema = local_message.errors
324324
self.write_error(writers_schema, error, buffer_encoder)
325-
except schema.AvroException as e:
325+
except avro.errors.AvroException as e:
326326
error = avro.errors.AvroRemoteException(str(e))
327327
buffer_encoder = avro.io.BinaryEncoder(io.BytesIO())
328328
META_WRITER.write(response_metadata, buffer_encoder)

lang/py/avro/test/sample_http_server.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@
3232
{
3333
"name": "Message",
3434
"type": "record",
35-
"fields": [{"name": "to", "type": "string"}, {"name": "from", "type": "string"}, {"name": "body", "type": "string"}],
35+
"fields": [
36+
{"name": "to", "type": "string"},
37+
{"name": "from", "type": "string"},
38+
{"name": "body", "type": "string"},
39+
],
3640
}
3741
],
3842
"messages": {
39-
"send": {"request": [{"name": "message", "type": "Message"}], "response": "string"},
43+
"send": {
44+
"request": [{"name": "message", "type": "Message"}],
45+
"response": "string",
46+
},
4047
"replay": {"request": [], "response": "string"},
4148
},
4249
}
@@ -71,7 +78,7 @@ def do_POST(self) -> None:
7178

7279

7380
def main():
74-
mail_server = http_server.HTTPServer(SERVER_ADDRESS, MailHandler)
81+
mail_server = http.server.HTTPServer(SERVER_ADDRESS, MailHandler)
7582
mail_server.allow_reuse_address = True
7683
mail_server.serve_forever()
7784

0 commit comments

Comments
 (0)