Skip to content

Commit 5af5a3a

Browse files
authored
modernize packaging and add release automation (#270)
* add a tox environment for testing package builds * replace setup.py with static pyproject.toml Use setuptools to package in the same way, but use pyproject.toml for compatibility with tools relying on PEP 517. * dynamically generate version from tags Use setuptools-scm to get a version from the tag when released instead of looking for the contents of a file. Generate a version.py file to replace the static value in __init__.py. * add github action to publish releases for tags This action responds when a tag is pushed to the main repository to build and upload both sdist and wheels to pypi.org. More details in https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
1 parent dc301a5 commit 5af5a3a

File tree

10 files changed

+264
-263
lines changed

10 files changed

+264
-263
lines changed

.github/workflows/check-build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ jobs:
5454
shell: bash
5555
run: ./test.sh
5656
- name: Build
57-
run: python setup.py sdist bdist_wheel
57+
run: |
58+
pip install build
59+
python -m build .

.github/workflows/python-publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This workflows will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Upload Python Package
5+
6+
on:
7+
- push
8+
9+
jobs:
10+
build-n-publish:
11+
name: Build and publish Python distributions to PyPI
12+
if: ${{ github.repository_owner == 'mjpost' }}
13+
14+
runs-on: ubuntu-latest
15+
environment: release
16+
17+
permissions:
18+
# IMPORTANT: this permission is mandatory for trusted publishing
19+
id-token: write
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
# with:
24+
# fetch-depth: 0
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.11'
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install .[build]
33+
- name: Build sdist and wheel
34+
run: |
35+
python -m build
36+
- name: Publish distribution to PyPI
37+
if: startsWith(github.ref, 'refs/tags')
38+
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ sacrebleu.egg-info
88
*~
99
.DS_Store
1010
.idea/
11+
sacrebleu/version.py

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test:
55
bash test.sh
66

77
pip:
8-
python3 setup.py sdist bdist_wheel
8+
python3 -m build .
99

1010
publish: pip
1111
twine upload dist/*

pyproject.toml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "setuptools_scm>=8"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "sacrebleu"
7+
dynamic = ["version"]
8+
authors = [{ name = "Matt Post", email = "[email protected]" }]
9+
maintainers = [{ name = "Matt Post", email = "[email protected]" }]
10+
description = "Hassle-free computation of shareable, comparable, and reproducible BLEU, chrF, and TER scores"
11+
readme = "README.md"
12+
license = { file = "LICENSE.txt" }
13+
classifiers = [
14+
# How mature is this project? Common values are
15+
# 3 - Alpha
16+
# 4 - Beta
17+
# 5 - Production/Stable
18+
"Development Status :: 5 - Production/Stable",
19+
20+
# Indicate who your project is intended for
21+
"Intended Audience :: Developers",
22+
"Intended Audience :: Science/Research",
23+
"Topic :: Scientific/Engineering",
24+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
25+
"Topic :: Text Processing",
26+
27+
# Pick your license as you wish (should match "license" above)
28+
"License :: OSI Approved :: Apache Software License",
29+
30+
# List operating systems
31+
"Operating System :: POSIX",
32+
"Operating System :: MacOS :: MacOS X",
33+
"Operating System :: Microsoft :: Windows",
34+
35+
# Specify the Python versions you support here. In particular, ensure
36+
# that you indicate whether you support Python 2, Python 3 or both.
37+
"Programming Language :: Python :: 3 :: Only",
38+
39+
# Indicate that type hints are provided
40+
"Typing :: Typed",
41+
]
42+
43+
requires-python = ">=3.8"
44+
45+
keywords = [
46+
"machine translation",
47+
"evaluation",
48+
"NLP",
49+
"natural language processing",
50+
"computational linguistics",
51+
]
52+
53+
dependencies = [
54+
"portalocker",
55+
"regex",
56+
"tabulate>=0.8.9",
57+
"numpy>=1.17",
58+
"colorama",
59+
"lxml",
60+
]
61+
62+
[project.optional-dependencies]
63+
dev = ["wheel", "pytest", "mypy", "types-tabulate", "lxml-stubs", "setuptools"]
64+
ja = ["mecab-python3>=1.0.9,<2.0.0", "ipadic>=1.0,<2.0"]
65+
ko = ["mecab-ko>=1.0.0,<=1.0.1", "mecab-ko-dic>=1.0,<2.0"]
66+
67+
[project.scripts]
68+
sacrebleu = "sacrebleu.sacrebleu:main"
69+
70+
[project.urls]
71+
Repository = "https://github.com/mjpost/sacrebleu"
72+
73+
[tool.setuptools.packages.find]
74+
include = ["sacrebleu*"]
75+
76+
[tool.setuptools.package-data]
77+
sacrebleu = ["py.typed"]
78+
79+
[tool.setuptools_scm]
80+
version_file = "sacrebleu/version.py"

sacrebleu/__init__.py

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,53 @@
1414
# express or implied. See the License for the specific language governing
1515
# permissions and limitations under the License.
1616

17-
__version__ = '2.4.1'
18-
__description__ = 'Hassle-free computation of shareable, comparable, and reproducible BLEU, chrF, and TER scores'
17+
__description__ = "Hassle-free computation of shareable, comparable, and reproducible BLEU, chrF, and TER scores"
1918

2019

21-
from .utils import smart_open, SACREBLEU_DIR, download_test_set
22-
from .utils import get_source_file, get_reference_files
23-
from .utils import get_available_testsets, get_langpairs_for_testset
24-
from .metrics.helpers import extract_word_ngrams, extract_char_ngrams
20+
# Backward compatibility functions for old style API access (<= 1.4.10)
21+
from .compat import (
22+
corpus_bleu,
23+
corpus_chrf,
24+
corpus_ter,
25+
raw_corpus_bleu,
26+
sentence_bleu,
27+
sentence_chrf,
28+
sentence_ter,
29+
)
2530
from .dataset import DATASETS
2631
from .metrics import BLEU, CHRF, TER
27-
28-
# Backward compatibility functions for old style API access (<= 1.4.10)
29-
from .compat import corpus_bleu, raw_corpus_bleu, sentence_bleu
30-
from .compat import corpus_chrf, sentence_chrf
31-
from .compat import corpus_ter, sentence_ter
32+
from .metrics.helpers import extract_char_ngrams, extract_word_ngrams
33+
from .utils import (
34+
SACREBLEU_DIR,
35+
download_test_set,
36+
get_available_testsets,
37+
get_langpairs_for_testset,
38+
get_reference_files,
39+
get_source_file,
40+
smart_open,
41+
)
42+
from .version import __version__
3243

3344
__all__ = [
34-
'smart_open', 'SACREBLEU_DIR', 'download_test_set',
35-
'get_source_file', 'get_reference_files',
36-
'get_available_testsets', 'get_langpairs_for_testset',
37-
'extract_word_ngrams', 'extract_char_ngrams',
38-
'DATASETS',
39-
'BLEU', 'CHRF', 'TER',
40-
'corpus_bleu', 'raw_corpus_bleu', 'sentence_bleu',
41-
'corpus_chrf', 'sentence_chrf',
42-
'corpus_ter', 'sentence_ter'
45+
"smart_open",
46+
"SACREBLEU_DIR",
47+
"download_test_set",
48+
"get_source_file",
49+
"get_reference_files",
50+
"get_available_testsets",
51+
"get_langpairs_for_testset",
52+
"extract_word_ngrams",
53+
"extract_char_ngrams",
54+
"DATASETS",
55+
"BLEU",
56+
"CHRF",
57+
"TER",
58+
"corpus_bleu",
59+
"raw_corpus_bleu",
60+
"sentence_bleu",
61+
"corpus_chrf",
62+
"sentence_chrf",
63+
"corpus_ter",
64+
"sentence_ter",
65+
"__version__",
4366
]

0 commit comments

Comments
 (0)