Skip to content

Commit 0d18769

Browse files
committed
Rename package and migrate to uv (#2)
* Rename Package to `torchTextClassifiers` and use uv to build and publish
1 parent 71b0f99 commit 0d18769

26 files changed

+1640
-101
lines changed
Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
33

4-
name: Python package
4+
name: Python Tests
55

66
on:
77
push:
8-
branches: [ "main" ]
8+
branches: [ "main", "rename-package" ]
99
pull_request:
1010
branches: [ "main" ]
1111

@@ -16,25 +16,20 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: [ "3.10", "3.11", "3.12"]
19+
python-version: ["3.11", "3.12", "3.13"]
2020

2121
steps:
2222
- uses: actions/checkout@v4
23-
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v5
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v5
2525
with:
2626
python-version: ${{ matrix.python-version }}
27-
- name: Install dependencies
28-
run: |
29-
python -m pip install --upgrade pip
30-
python -m pip install flake8 pytest
31-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32-
- name: Lint with flake8
33-
run: |
34-
# stop the build if there are Python syntax errors or undefined names
35-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
36-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38-
- name: Test with pytest
39-
run: |
40-
pytest
27+
version: 0.7.8
28+
enable-cache: true
29+
cache-dependency-glob: "uv.lock"
30+
- name: Install the project
31+
run: uv sync --locked --all-extras --dev
32+
33+
- name: Run tests
34+
# For example, using `pytest`
35+
run: uv run pytest tests

.github/workflows/python-publish.yml

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,8 @@ permissions:
1616
contents: read
1717

1818
jobs:
19-
release-build:
20-
runs-on: ubuntu-latest
21-
22-
steps:
23-
- uses: actions/checkout@v4
24-
25-
- uses: actions/setup-python@v5
26-
with:
27-
python-version: "3.x"
28-
29-
- name: Build release distributions
30-
run: |
31-
# NOTE: put your own distribution build steps here.
32-
python -m pip install build poetry
33-
poetry install
34-
poetry build
35-
36-
- name: Upload distributions
37-
uses: actions/upload-artifact@v4
38-
with:
39-
name: release-dists
40-
path: dist/
41-
4219
pypi-publish:
4320
runs-on: ubuntu-latest
44-
needs:
45-
- release-build
4621
permissions:
4722
# IMPORTANT: this permission is mandatory for trusted publishing
4823
id-token: write
@@ -59,13 +34,32 @@ jobs:
5934
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
6035

6136
steps:
62-
- name: Retrieve release distributions
63-
uses: actions/download-artifact@v4
64-
with:
65-
name: release-dists
66-
path: dist/
37+
- uses: actions/checkout@v4
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v5
40+
with:
41+
enable-cache: true
42+
cache-dependency-glob: "uv.lock"
43+
version: 0.7.8
44+
45+
- name: Change Package Version
46+
run: |
47+
# Extract the tag name and remove the leading 'v'
48+
TAG_NAME=${GITHUB_REF#refs/tags/v}
49+
echo "Tag name: $TAG_NAME"
50+
51+
# Update the version in pyproject.toml
52+
sed -i "s/\"0.0.0-dev\"/\"$TAG_NAME\"/" pyproject.toml
53+
54+
# Print the updated pyproject.toml file
55+
cat pyproject.toml
56+
57+
58+
- name: Install build dependencies
59+
run: uv sync --all-extras
60+
61+
- name: Build the project
62+
run: uv build
6763

68-
- name: Publish release distributions to PyPI
69-
uses: pypa/gh-action-pypi-publish@release/v1
70-
with:
71-
packages-dir: dist/
64+
- name: Publish to PyPI
65+
run: uv publish

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# torchFastText : Efficient text classification with PyTorch
1+
# torchTextClassifiers : Efficient text classification with PyTorch
22

3-
A flexible PyTorch implementation of FastText for text classification with support for categorical features.
3+
A flexible PyTorch implementation of models for text classification with support for categorical features.
44

55
## Features
66

@@ -14,8 +14,17 @@ A flexible PyTorch implementation of FastText for text classification with suppo
1414

1515
## Installation
1616

17+
- With `pip`:
18+
19+
```bash
20+
pip install torchTextClassifiers
21+
```
22+
23+
- with `uv`:
24+
25+
1726
```bash
18-
pip install torchFastText
27+
uv add torchTextClassifiers
1928
```
2029

2130
## Key Components
@@ -30,16 +39,16 @@ pip install torchFastText
3039
- `preprocess`: To preprocess text input, using `nltk` and `unidecode` libraries.
3140
- `explainability`: Simple methods to visualize feature attributions at word and letter levels, using `captum`library.
3241

33-
Run `pip install torchFastText[preprocess]` or `pip install torchFastText[explainability]` to download these optional dependencies.
42+
Run `pip install torchTextClassifiers[preprocess]` or `pip install torchTextClassifiers[explainability]` to download these optional dependencies.
3443

3544

3645
## Quick Start
3746

3847
```python
39-
from torchFastText import torchFastText
48+
from torchTextClassifiers import torchTextClassifiers
4049

4150
# Initialize the model
42-
model = torchFastText(
51+
model = torchTextclassifiers(
4352
num_tokens=1000000,
4453
embedding_dim=100,
4554
min_count=5,

pyproject.toml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[project]
2-
name = "torchFastText"
2+
name = "torchtextclassifiers"
33
description = "An implementation of the https://github.com/facebookresearch/fastText supervised learning algorithm for text classification using Pytorch."
44
authors = [
55
{ name = "Tom Seimandi", email = "tom.seimandi@gmail.com" },
@@ -8,7 +8,7 @@ authors = [
88
{ name = "Cédric Couralet", email = "cedric.couralet@insee.fr" },
99
]
1010
readme = "README.md"
11-
repository = "https://github.com/InseeFrLab/torch-fastText"
11+
repository = "https://github.com/InseeFrLab/torchTextClassifiers"
1212
classifiers = [
1313
"Programming Language :: Python :: 3",
1414
"License :: OSI Approved :: MIT License",
@@ -19,29 +19,35 @@ dependencies = [
1919
"numpy>=1.26.4",
2020
"pytorch-lightning>=2.4.0"
2121
]
22-
requires-python = ">=3.10"
23-
dynamic = ["version"]
22+
requires-python = ">=3.11"
23+
version="0.0.0-dev"
2424

2525

26+
[dependency-groups]
27+
dev = [
28+
"pytest >=8.1.1,<9",
29+
"pandas",
30+
"scikit-learn",
31+
"nltk",
32+
"unidecode",
33+
"captum"
34+
]
35+
2636
[project.optional-dependencies]
2737
explainability = ["unidecode", "nltk", "captum"]
2838
preprocess = ["unidecode", "nltk"]
2939

3040
[build-system]
31-
requires = ["poetry-core>=2.0.0"]
32-
build-backend = "poetry.core.masonry.api"
41+
requires = ["uv_build>=0.7.8,<0.8.0"]
42+
build-backend = "uv_build"
3343

3444
[tool.ruff]
3545
line-length = 100
3646

37-
[tool.poetry]
38-
version = "0.0.1-dev" # base version
39-
packages = [{include = "torchFastText"}]
4047

41-
[tool.poetry.requires-plugins]
42-
poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }
48+
[tool.uv.build-backend]
49+
module-name="torchTextClassifiers"
50+
module-root = ""
51+
52+
4353

44-
[tool.poetry-dynamic-versioning]
45-
enable = true
46-
vcs = "git"
47-
style = "semver"

requirements.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/test_all.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from sklearn.model_selection import train_test_split
88
from sklearn.preprocessing import LabelEncoder
99

10-
from torchFastText import torchFastText
11-
from torchFastText.preprocess import clean_text_feature
12-
from torchFastText.datasets import NGramTokenizer
10+
from torchTextClassifiers import torchTextClassifiers
11+
from torchTextClassifiers.preprocess import clean_text_feature
12+
from torchTextClassifiers.datasets import NGramTokenizer
1313

1414
source_path = Path(__file__).resolve()
1515
source_dir = source_path.parent
@@ -111,7 +111,7 @@ def test_building(data):
111111
for vocab, cat_embedding_dim, num_cat in product(
112112
vocab_possible_values, cat_embedding_dim_possible_values, num_cat_possible_values
113113
):
114-
model = torchFastText(
114+
model = torchTextClassifiers(
115115
num_tokens=num_tokens,
116116
num_rows=num_tokens,
117117
embedding_dim=embedding_dim,
@@ -152,7 +152,7 @@ def test_training(data):
152152
vocab_possible_values, cat_embedding_dim_possible_values, num_cat_possible_values
153153
):
154154
print(vocab, cat_embedding_dim, num_cat)
155-
model = torchFastText(
155+
model = torchTextClassifiers(
156156
num_tokens=num_tokens,
157157
embedding_dim=embedding_dim,
158158
min_count=min_count,

tests/test_fasttext_model_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
2-
from torchFastText.datasets.dataset import FastTextModelDataset
3-
from torchFastText.datasets.tokenizer import NGramTokenizer
2+
from torchTextClassifiers.datasets.dataset import FastTextModelDataset
3+
from torchTextClassifiers.datasets.tokenizer import NGramTokenizer
44

55

66
@pytest.fixture

tests/test_ngramtokenizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from torchFastText.datasets.tokenizer import NGramTokenizer
2+
from torchTextClassifiers.datasets.tokenizer import NGramTokenizer
33

44

55
def test_ngramtokenizer_init_valid():

torchFastText/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

torchTextClassifiers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .torchTextClassifiers import torchTextClassifiers as torchTextClassifiers

0 commit comments

Comments
 (0)