Skip to content

Commit 90fd62d

Browse files
authored
Merge pull request #93 from PyThaiNLP/copilot/check-github-workflows
[nlpo3-python]: Prepare for 1.4.0 release: Fix artifact publishing to PyPI, update GitHub Actions, add type stubs, and multi-implementation Python support
2 parents db361d9 + 5d3cb2c commit 90fd62d

13 files changed

Lines changed: 247 additions & 147 deletions

File tree

.github/workflows/build-python-wheels.yml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Checkout source code
4545
uses: actions/checkout@v6
4646
with:
47-
ref: ${{ github.event.pull_request.head.sha }}
47+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
4848
- id: check_build_trigger
4949
name: Check build trigger
5050
run: bash build_tools/github/check_build_trigger.sh
@@ -56,13 +56,11 @@ jobs:
5656
needs: check_build_trigger
5757
if: needs.check_build_trigger.outputs.build
5858
strategy:
59-
# Ensure that a wheel builder finishes even if another fails
60-
fail-fast: false
59+
fail-fast: false # If false, all jobs continue even if one fails
6160
matrix:
6261
os: [macos-latest, ubuntu-latest, windows-latest]
6362
python-version: ["3.14"] # Check with PyO3's maximum supported version
64-
env:
65-
CIBW_BUILD: "" # blank, let cibuildwheel build all supported platforms
63+
# cibuildwheel will manage multiple Python versions internally
6664

6765
steps:
6866
- name: Checkout source code
@@ -92,17 +90,19 @@ jobs:
9290
package-dir: nlpo3-python
9391
output-dir: wheelhouse
9492
env:
95-
CIBW_BUILD_VERBOSITY: 1
9693
# See CIBW_BUILD, CIBW_SKIP, CIBW_ARCHS and other build selectors at:
9794
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
98-
CIBW_SKIP: "*-musllinux_i686"
95+
CIBW_ENABLE: "graalpy pypy" # Enable GraalPy and PyPy builds
96+
CIBW_BUILD: "cp* gp* pp*" # Build for CPython, GraalPy and PyPy
97+
CIBW_BUILD_VERBOSITY: 1
98+
CIBW_SKIP: "*-musllinux_i686 gp*-win_*"
9999
CIBW_ARCHS_MACOS: "x86_64 arm64"
100100
CIBW_ENVIRONMENT_MACOS: |
101101
MACOSX_DEPLOYMENT_TARGET=10.12
102102
PATH="$HOME/.cargo/bin:$PATH"
103103
CC=/usr/bin/clang
104104
CXX=/usr/bin/clang++
105-
CIBW_ARCHS_LINUX: "auto"
105+
CIBW_ARCHS_LINUX: "x86_64 i686"
106106
CIBW_ENVIRONMENT_LINUX: PATH="$HOME/.cargo/bin:$PATH"
107107
CIBW_BEFORE_BUILD_LINUX: |
108108
pip install --upgrade setuptools-rust
@@ -112,13 +112,20 @@ jobs:
112112
# and the container does not have Rust.
113113
CIBW_ARCHS_WINDOWS: "AMD64 x86"
114114

115+
- name: List wheel files
116+
run: |
117+
echo "Files to upload (binary wheels):"
118+
find ./wheelhouse -maxdepth 1 -type f -name '*.whl' -print | sort || true
119+
echo "Count: $(find ./wheelhouse -maxdepth 1 -type f -name '*.whl' -print | wc -l || true)"
120+
shell: bash
115121
- name: Store artifacts
116122
uses: actions/upload-artifact@v6
117123
with:
118124
path: ./wheelhouse/*.whl
119-
name: wheelhouse-${{ matrix.os }}-${{ matrix.python-version }}
125+
name: ${{ github.job }}-wheelhouse-${{ matrix.os }}-${{ github.run_id }}
120126
if-no-files-found: warn
121127
overwrite: true
128+
retention-days: 1
122129

123130
build_sdist:
124131
name: Build source distribution
@@ -131,16 +138,25 @@ jobs:
131138
- name: Setup Python
132139
uses: actions/setup-python@v6
133140
with:
134-
python-version: "3.14" # Check with PyO3's maximum supported version
141+
python-version: "3.14" # Ideally matches with the python-version in build_wheels
135142
cache: "pip"
136143
- name: Build source distribution
137144
run: |
138145
cd nlpo3-python
139146
bash ../build_tools/github/build_source.sh
147+
- name: List sdist files
148+
run: |
149+
echo "Files to upload (sdist):"
150+
find nlpo3-python/dist -maxdepth 1 -type f -name '*.tar.gz' -print | sort || true
151+
echo "Count: $(find nlpo3-python/dist -maxdepth 1 -type f -name '*.tar.gz' -print | wc -l || true)"
152+
shell: bash
140153
- name: Store artifacts
141154
uses: actions/upload-artifact@v6
142155
with:
143156
path: nlpo3-python/dist/*.tar.gz
157+
name: sdist
158+
overwrite: true
159+
retention-days: 1
144160

145161
publish_pypi:
146162
name: Publish to PyPI
@@ -151,11 +167,11 @@ jobs:
151167
# Alternatively, upload to PyPI on every tag starting with 'v':
152168
#if: github.event_name == 'push' && startsWith(github.event.ref, 'v')
153169
steps:
154-
- name: Retrieve artifacts
170+
- name: Retrieve all artifacts
155171
uses: actions/download-artifact@v6
156172
with:
157-
name: artifact
158173
path: dist
174+
merge-multiple: true
159175
- name: Publish package
160176
uses: pypa/gh-action-pypi-publish@v1.13.0
161177
with:

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ jobs:
4343

4444
steps:
4545
- name: Checkout repository
46-
uses: actions/checkout@v2
46+
uses: actions/checkout@v6
4747

4848
# Initializes the CodeQL tools for scanning.
4949
- name: Initialize CodeQL
50-
uses: github/codeql-action/init@v1
50+
uses: github/codeql-action/init@v3
5151
with:
5252
languages: ${{ matrix.language }}
5353
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -58,7 +58,7 @@ jobs:
5858
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5959
# If this step fails, then you should remove it and run the build manually (see below)
6060
- name: Autobuild
61-
uses: github/codeql-action/autobuild@v1
61+
uses: github/codeql-action/autobuild@v3
6262

6363
# ℹ️ Command-line programs to run using the OS shell.
6464
# 📚 https://git.io/JvXDl
@@ -72,4 +72,4 @@ jobs:
7272
# make release
7373

7474
- name: Perform CodeQL Analysis
75-
uses: github/codeql-action/analyze@v1
75+
uses: github/codeql-action/analyze@v3

.github/workflows/test-nlpo3-cli.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,19 @@ jobs:
3333
uses: actions/checkout@v6
3434

3535
- name: Setup Rust toolchain - non-win32
36-
uses: actions-rs/toolchain@v1
37-
with:
38-
override: true
39-
profile: minimal
40-
toolchain: stable
41-
if: ${{ !startsWith(matrix.os, 'windows') || matrix.bitness != '32' }}
36+
uses: actions-rust-lang/setup-rust-toolchain@v1
37+
if: "!startsWith(matrix.os, 'windows') || matrix.bitness != '32'"
4238

4339
- name: Setup Rust toolchain - win32
44-
uses: actions-rs/toolchain@v1
40+
uses: actions-rust-lang/setup-rust-toolchain@v1
4541
with:
46-
override: true
47-
profile: minimal
48-
toolchain: stable
4942
target: i686-pc-windows-msvc
5043
if: startsWith(matrix.os, 'windows') && matrix.bitness == '32'
5144

52-
- name: Setup Rust dependencies
53-
uses: actions-rs/cargo@v1
54-
with:
55-
command: check
45+
- name: Test - non-win32
46+
run: cargo test
47+
if: "!startsWith(matrix.os, 'windows') || matrix.bitness != '32'"
5648

57-
- name: Test
58-
uses: actions-rs/cargo@v1
59-
with:
60-
command: test
49+
- name: Test - win32
50+
run: cargo test --target i686-pc-windows-msvc
51+
if: startsWith(matrix.os, 'windows') && matrix.bitness == '32'

.github/workflows/test-nlpo3-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defaults:
2424
jobs:
2525
test:
2626
strategy:
27-
fail-fast: false
27+
fail-fast: true
2828
matrix:
2929
os: [macos-latest, ubuntu-latest, windows-latest]
3030
python-version: ["3.14", "3.13", "3.12", "3.11", "3.10", "3.9"]

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ SPDX-License-Identifier: Apache-2.0
99
[![Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg "Apache-2.0")](https://opensource.org/license/apache-2-0)
1010
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14082448.svg)](https://doi.org/10.5281/zenodo.14082448)
1111

12-
A Thai natural language processing library written in Rust,
13-
with optional Python and Node.js bindings. Formerly known as `oxidized-thainlp`.
12+
A Thai natural language processing library written in Rust with optional
13+
Python and Node.js bindings. Formerly known as `oxidized-thainlp`.
1414

15-
To use as a library in a Rust project:
15+
Using in a Rust project
1616

1717
```shell
1818
cargo add nlpo3
1919
```
2020

21-
To use as a library in a Python project:
21+
Using in a Python project
2222

2323
```shell
2424
pip install nlpo3
@@ -75,26 +75,25 @@ See more at [nlpo3-python](./nlpo3-python/).
7575

7676
[![crates.io](https://img.shields.io/crates/v/nlpo3.svg "crates.io")](https://crates.io/crates/nlpo3/)
7777

78-
#### Add to dependency
78+
#### Add as a dependency
7979

80-
To use as a library in a Rust project:
80+
To add `nlpo3` to your project's dependencies:
8181

8282
```shell
8383
cargo add nlpo3
8484
```
8585

86-
It will add "nlpo3" to `Cargo.toml`:
86+
This updates `Cargo.toml` with:
8787

8888
```toml
8989
[dependencies]
90-
# ...
9190
nlpo3 = "1.4.0"
9291
```
9392

9493
#### Example
9594

96-
Create a tokenizer using a dictionary from file,
97-
then use it to tokenize a string (safe mode = true, and parallel mode = false):
95+
Create a tokenizer from a dictionary file and use it to tokenize a string
96+
(safe mode = true, parallel mode = false):
9897

9998
```rust
10099
use nlpo3::tokenizer::newmm::NewmmTokenizer;
@@ -104,7 +103,7 @@ let tokenizer = NewmmTokenizer::new("path/to/dict.file");
104103
let tokens = tokenizer.segment("ห้องสมุดประชาชน", true, false).unwrap();
105104
```
106105

107-
Create a tokenizer using a dictionary from a vector of Strings:
106+
Create a tokenizer from a vector of strings:
108107

109108
```rust
110109
let words = vec!["ปาลิเมนต์".to_string(), "คอนสติติวชั่น".to_string()];

nlpo3-nodejs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ For now, copy the whole `nlpo3/` directory after build to your project.
5757

5858
### npm (experitmental)
5959

60-
npm is still experimental and may not work on all platforms. Please report issues at <https://github.com/PyThaiNLP/nlpo3/issues>
60+
npm is still experimental and may not work on all platforms.
61+
Please report issues at <https://github.com/PyThaiNLP/nlpo3/issues>
6162

6263
```shell
6364
npm i nlpo3

nlpo3-python/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ authors = [
1010
]
1111
description = "Python binding for nlpO3 Thai language processing library"
1212
categories = ["text-processing"]
13-
keywords = ["thai", "tokenizer", "nlp", "word-segmentation", "python"]
13+
keywords = [
14+
"thai",
15+
"tokenizer",
16+
"tokenization",
17+
"text-processing",
18+
"nlp",
19+
"word-segmentation",
20+
"pythainlp",
21+
]
1422
homepage = "https://github.com/PyThaiNLP/nlpo3/tree/main/nlpo3-python"
1523
repository = "https://github.com/PyThaiNLP/nlpo3/"
1624
documentation = "https://github.com/PyThaiNLP/nlpo3/blob/main/nlpo3-python/README.md"

nlpo3-python/MANIFEST.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
include LICENSE README.md pyproject.toml Cargo.toml
22
recursive-include src *
3+
4+
# Ensure the Python package files are included in the sdist
5+
graft nlpo3
6+
7+
# Include PEP 561 marker and type stubs for compiled extension
8+
include nlpo3/py.typed
9+
recursive-include nlpo3 *.pyi
10+
11+
# Exclude test notebooks and tests from the sdist to keep it small
12+
prune tests
13+
prune notebooks

0 commit comments

Comments
 (0)