Skip to content

Commit beb3d1f

Browse files
committed
Build with Go 1.24.x and upgrade build tool chains
- Lint Python code and update functions comments - Upgrade the dependencies package version
1 parent f64ad99 commit beb3d1f

File tree

5 files changed

+83
-63
lines changed

5 files changed

+83
-63
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
test:
77
strategy:
88
matrix:
9-
go-version: [1.23.x]
9+
go-version: [1.24.x]
1010
os: [ubuntu-24.04, macos-latest, windows-latest]
1111
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1212
targetplatform: [x64]
@@ -73,7 +73,7 @@ jobs:
7373
- name: Install Go
7474
uses: actions/setup-go@v5
7575
with:
76-
go-version: 1.23.x
76+
go-version: 1.24.x
7777
cache: false
7878

7979
- name: Install Python
@@ -96,9 +96,9 @@ jobs:
9696
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
9797
brew tap messense/macos-cross-toolchains
9898
brew install FiloSottile/musl-cross/musl-cross i686-unknown-linux-gnu mingw-w64
99-
wget https://github.com/mstorsjo/llvm-mingw/releases/download/20241203/llvm-mingw-20241203-ucrt-macos-universal.tar.xz
100-
tar -xzf llvm-mingw-20241203-ucrt-macos-universal.tar.xz
101-
export PATH="$(pwd)/llvm-mingw-20241203-ucrt-macos-universal/bin:$PATH"
99+
wget https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-macos-universal.tar.xz
100+
tar -xzf llvm-mingw-20250114-ucrt-macos-universal.tar.xz
101+
export PATH="$(pwd)/llvm-mingw-20250114-ucrt-macos-universal/bin:$PATH"
102102
CC=i686-linux-gnu-gcc GOOS=linux GOARCH=386 go build -ldflags "-s -w" -buildmode=c-shared -o libexcelize.386.linux.so main.go
103103
CC=x86_64-linux-musl-gcc GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -buildmode=c-shared -o libexcelize.amd64.linux.so main.go
104104
CC=aarch64-linux-musl-gcc GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -buildmode=c-shared -o libexcelize.arm64.linux.so main.go

excelize.py

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from datetime import datetime, date, time
1515
from enum import Enum
1616
from typing import Tuple, get_args, get_origin, List, Optional, Union
17-
import types_go
18-
from types_py import *
1917
from ctypes import (
2018
byref,
2119
c_bool,
@@ -33,9 +31,15 @@
3331
)
3432
import os
3533
import platform
34+
import sys
35+
import types_go
36+
from types_py import *
3637

3738

38-
def load_lib():
39+
def load_lib() -> Optional[str]:
40+
"""
41+
Load the shared library based on the current platform and architecture.
42+
"""
3943
system = platform.system().lower()
4044
arch = platform.architecture()[0]
4145
machine = platform.machine().lower()
@@ -79,7 +83,7 @@ def load_lib():
7983
return f"libexcelize.{arch_name}.{system}{ext_map[system]}"
8084

8185
print("This platform or architecture is not supported.")
82-
exit(1)
86+
sys.exit(1)
8387

8488

8589
lib = CDLL(os.path.join(os.path.dirname(__file__), load_lib()))
@@ -265,7 +269,7 @@ def get_c_field_type(struct, field_name):
265269
Returns:
266270
type: The type of the specified field if found, otherwise None.
267271
"""
268-
for field in struct._fields_:
272+
for field in getattr(struct, "_fields_", None):
269273
if field[0] == field_name:
270274
return field[1]
271275

@@ -319,7 +323,9 @@ def py_value_to_c(py_instance, ctypes_instance):
319323
if get_origin(arg_type) is not list and arg_type is not bytes:
320324
# Pointer of the Go data type, for example: *excelize.Options or *string
321325
value = getattr(py_instance, py_field_name)
322-
c_type = get_c_field_type(ctypes_instance, c_field_name)._type_
326+
c_type = getattr(
327+
get_c_field_type(ctypes_instance, c_field_name), "_type_", None
328+
)
323329
if value is not None:
324330
if any(is_py_primitive_type(arg) for arg in py_field_args):
325331
# Pointer of the Go basic data type, for example: *string
@@ -339,17 +345,21 @@ def py_value_to_c(py_instance, ctypes_instance):
339345
# The Go data type array, for example:
340346
# []*excelize.Options, []excelize.Options, []string, []*string
341347
if arg_type is bytes: # []byte
342-
c_type = get_c_field_type(ctypes_instance, c_field_name)._type_
348+
c_type = getattr(
349+
get_c_field_type(ctypes_instance, c_field_name), "_type_", None
350+
)
343351
value = getattr(py_instance, py_field_name)
344-
ctypes_instance.__setattr__(
345-
c_field_name, cast(value, POINTER(c_ubyte))
352+
setattr(
353+
ctypes_instance, c_field_name, cast(value, POINTER(c_ubyte))
346354
)
347-
ctypes_instance.__setattr__(c_field_name + "Len", c_int(len(value)))
355+
setattr(ctypes_instance, c_field_name + "Len", c_int(len(value)))
348356
continue
349357
py_field_type = get_args(arg_type)[0]
350358
if type(None) not in get_args(py_field_type):
351359
# The Go data type array, for example: []excelize.Options or []string
352-
c_type = get_c_field_type(ctypes_instance, c_field_name)._type_
360+
c_type = getattr(
361+
get_c_field_type(ctypes_instance, c_field_name), "_type_", None
362+
)
353363
py_list = getattr(py_instance, py_field_name)
354364
if py_list:
355365
l = len(py_list)
@@ -358,7 +368,8 @@ def py_value_to_c(py_instance, ctypes_instance):
358368
# The Go basic data type array, for example: []string
359369
if str is py_field_type:
360370
c_array_type = POINTER(c_char) * l
361-
ctypes_instance.__setattr__(
371+
setattr(
372+
ctypes_instance,
362373
c_field_name,
363374
c_array_type(
364375
*[
@@ -369,44 +380,44 @@ def py_value_to_c(py_instance, ctypes_instance):
369380
)
370381
else:
371382
for i in range(l):
372-
c_array.__setitem__(
373-
i, py_to_base_ctype(py_list[i], c_type)
374-
)
375-
ctypes_instance.__setattr__(c_field_name, c_array)
383+
c_array[i] = py_to_base_ctype(py_list[i], c_type)
384+
setattr(ctypes_instance, c_field_name, c_array)
376385
else:
377386
# The Go struct array, for example: []excelize.Options
378387
for i in range(l):
379-
c_array.__setitem__(
380-
i, py_value_to_c(py_list[i], c_type())
381-
)
382-
ctypes_instance.__setattr__(c_field_name, c_array)
383-
ctypes_instance.__setattr__(c_field_name + "Len", c_int(l))
388+
c_array[i] = py_value_to_c(py_list[i], c_type())
389+
setattr(ctypes_instance, c_field_name, c_array)
390+
setattr(ctypes_instance, c_field_name + "Len", c_int(l))
384391

385392
else:
386393
# Pointer array of the Go data type, for example: []*excelize.Options or []*string
387-
c_type = get_c_field_type(
388-
ctypes_instance, c_field_name
389-
)._type_._type_
394+
c_type = getattr(
395+
getattr(
396+
get_c_field_type(ctypes_instance, c_field_name),
397+
"_type_",
398+
None,
399+
),
400+
"_type_",
401+
None,
402+
)
390403
py_list = getattr(py_instance, py_field_name)
391404
if py_list:
392405
l = len(py_list)
393406
c_array = (POINTER(c_type) * l)()
394407
if is_py_primitive_type(get_args(py_field_type)[0]):
395408
# Pointer array of the Go basic data type, for example: []*string
396409
for i in range(l):
397-
c_array.__setitem__(
398-
i,
399-
pointer(py_to_base_ctype(py_list[i], c_type)),
410+
c_array[i] = pointer(
411+
py_to_base_ctype(py_list[i], c_type)
400412
)
401413
else:
402414
# Pointer array of the Go struct, for example: []*excelize.Options
403415
for i in range(l):
404-
c_array.__setitem__(
405-
i,
406-
pointer(py_value_to_c(py_list[i], c_type())),
416+
c_array[i] = pointer(
417+
py_value_to_c(py_list[i], c_type())
407418
)
408-
ctypes_instance.__setattr__(c_field_name + "Len", c_int(l))
409-
ctypes_instance.__setattr__(c_field_name, c_array)
419+
setattr(ctypes_instance, c_field_name + "Len", c_int(l))
420+
setattr(ctypes_instance, c_field_name, c_array)
410421
return ctypes_instance
411422

412423

@@ -439,6 +450,11 @@ def py_value_to_c_interface(py_value):
439450

440451

441452
class StreamWriter:
453+
"""
454+
StreamWriter is a streaming writer for writing large amounts of data to a
455+
worksheet.
456+
"""
457+
442458
sw_index: int
443459

444460
def __init__(self, sw_index: int):
@@ -609,6 +625,10 @@ def flush(self) -> Optional[Exception]:
609625

610626

611627
class File:
628+
"""
629+
File is a representation of an workbook.
630+
"""
631+
612632
file_index: int
613633

614634
def __init__(self, file_index: int):
@@ -1542,7 +1562,7 @@ def get_col_outline_level(
15421562
"""
15431563
Get outline level of a single column by given worksheet name and column
15441564
name.
1545-
1565+
15461566
Args:
15471567
sheet (str): The worksheet name
15481568
col (str): The column name
@@ -1556,7 +1576,7 @@ def get_col_outline_level(
15561576
15571577
.. code-block:: python
15581578
1559-
level, err = f.get_col_outline_level("Sheet1", "D")
1579+
level, err = f.get_col_outline_level("Sheet1", "D")
15601580
"""
15611581
lib.GetColOutlineLevel.restype = types_go._IntErrorResult
15621582
res = lib.GetColOutlineLevel(

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ module github.com/xuri/excelize-py
33
go 1.20
44

55
require (
6-
github.com/xuri/excelize/v2 v2.9.1-0.20250207010127-05ed940040c1
7-
golang.org/x/image v0.23.0
6+
github.com/xuri/excelize/v2 v2.9.1-0.20250208014036-718417e15ed6
7+
golang.org/x/image v0.24.0
88
)
99

1010
require (
1111
github.com/richardlehane/mscfb v1.0.4 // indirect
1212
github.com/richardlehane/msoleps v1.0.4 // indirect
13-
github.com/tiendc/go-deepcopy v1.2.2 // indirect
13+
github.com/tiendc/go-deepcopy v1.5.0 // indirect
1414
github.com/xuri/efp v0.0.0-20241211021726-c4e992084aa6 // indirect
1515
github.com/xuri/nfp v0.0.0-20250111060730-82a408b9aa71 // indirect
16-
golang.org/x/crypto v0.32.0 // indirect
17-
golang.org/x/net v0.34.0 // indirect
16+
golang.org/x/crypto v0.33.0 // indirect
17+
golang.org/x/net v0.35.0 // indirect
1818
golang.org/x/text v0.22.0 // indirect
1919
)

go.sum

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,20 @@ github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTK
66
github.com/richardlehane/msoleps v1.0.4 h1:WuESlvhX3gH2IHcd8UqyCuFY5yiq/GR/yqaSM/9/g00=
77
github.com/richardlehane/msoleps v1.0.4/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
88
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
9-
github.com/tiendc/go-deepcopy v1.2.0 h1:6vCCs+qdLQHzFqY1fcPirsAWOmrLbuccilfp8UzD1Qo=
10-
github.com/tiendc/go-deepcopy v1.2.0/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I=
11-
github.com/tiendc/go-deepcopy v1.2.2 h1:UxMUNHTh2lWbnfic8asYI3YtE5e85XGZYUgl2pZKsVY=
12-
github.com/tiendc/go-deepcopy v1.2.2/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I=
9+
github.com/tiendc/go-deepcopy v1.5.0 h1:TbtS9hclrKZcF1AHby8evDm4mIQU36i6tSYuvx/TstY=
10+
github.com/tiendc/go-deepcopy v1.5.0/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I=
1311
github.com/xuri/efp v0.0.0-20241211021726-c4e992084aa6 h1:8m6DWBG+dlFNbx5ynvrE7NgI+Y7OlZVMVTpayoW+rCc=
1412
github.com/xuri/efp v0.0.0-20241211021726-c4e992084aa6/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
15-
github.com/xuri/excelize/v2 v2.9.1-0.20250125020127-b19e5940b84e h1:5V9lcKkqTSO66lJhwYeANB9GJkSEGosawlR5cMpvmQY=
16-
github.com/xuri/excelize/v2 v2.9.1-0.20250125020127-b19e5940b84e/go.mod h1:QPDLfWgowGnzIqBhd8g4iNoymgms2UL7Ok/Qm/NSPsg=
17-
github.com/xuri/excelize/v2 v2.9.1-0.20250207010127-05ed940040c1 h1:K+zyRkNaXhO7LeXDSG/v1QtKZvc/wa+Q944zjSDFfRs=
18-
github.com/xuri/excelize/v2 v2.9.1-0.20250207010127-05ed940040c1/go.mod h1:QPDLfWgowGnzIqBhd8g4iNoymgms2UL7Ok/Qm/NSPsg=
13+
github.com/xuri/excelize/v2 v2.9.1-0.20250208014036-718417e15ed6 h1:fT911cTvmhbFNfEhUjz5hY0tcXEedJyx1HkwhOQcm3s=
14+
github.com/xuri/excelize/v2 v2.9.1-0.20250208014036-718417e15ed6/go.mod h1:QPDLfWgowGnzIqBhd8g4iNoymgms2UL7Ok/Qm/NSPsg=
1915
github.com/xuri/nfp v0.0.0-20250111060730-82a408b9aa71 h1:hOh7aVDrvGJRxzXrQbDY8E+02oaI//5cHL+97oYpEPw=
2016
github.com/xuri/nfp v0.0.0-20250111060730-82a408b9aa71/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
21-
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
22-
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
23-
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
24-
golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY=
25-
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
26-
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
27-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
28-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
17+
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
18+
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
19+
golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ=
20+
golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8=
21+
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
22+
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
2923
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
3024
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
3125
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

test_excelize.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
amounts of data. This library needs Python version 3.9 or later.
1111
"""
1212

13-
import excelize
1413
import unittest
1514
from dataclasses import dataclass
1615
from unittest.mock import patch
@@ -23,9 +22,16 @@
2322
POINTER,
2423
)
2524
import os
25+
import excelize
2626

2727

2828
class TestExcelize(unittest.TestCase):
29+
"""
30+
TestExcelize tests excelize library.
31+
32+
Args:
33+
unittest (unittest.TestCase): unittest class.
34+
"""
2935

3036
@patch("platform.architecture")
3137
def test_platform_architecture(self, mock_architecture):
@@ -1033,7 +1039,7 @@ def test_cell_rich_text(self):
10331039

10341040
def test_conditional_format(self):
10351041
f = excelize.new_file()
1036-
format, err = f.new_conditional_style(
1042+
fmt, err = f.new_conditional_style(
10371043
excelize.Style(
10381044
font=excelize.Font(color="9A0511"),
10391045
fill=excelize.Fill(type="pattern", color=["FEC7CE"], pattern=1),
@@ -1048,7 +1054,7 @@ def test_conditional_format(self):
10481054
excelize.ConditionalFormatOptions(
10491055
type="cell",
10501056
criteria="between",
1051-
format=format,
1057+
format=fmt,
10521058
min_value="6",
10531059
max_value="8",
10541060
)

0 commit comments

Comments
 (0)