Skip to content

Commit

Permalink
modernize packaging and add release automation (#270)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dhellmann authored Jul 29, 2024
1 parent dc301a5 commit 5af5a3a
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 263 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/check-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ jobs:
shell: bash
run: ./test.sh
- name: Build
run: python setup.py sdist bdist_wheel
run: |
pip install build
python -m build .
38 changes: 38 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
- push

jobs:
build-n-publish:
name: Build and publish Python distributions to PyPI
if: ${{ github.repository_owner == 'mjpost' }}

runs-on: ubuntu-latest
environment: release

permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

steps:
- uses: actions/checkout@v4
# with:
# fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[build]
- name: Build sdist and wheel
run: |
python -m build
- name: Publish distribution to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ sacrebleu.egg-info
*~
.DS_Store
.idea/
sacrebleu/version.py
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test:
bash test.sh

pip:
python3 setup.py sdist bdist_wheel
python3 -m build .

publish: pip
twine upload dist/*
80 changes: 80 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[project]
name = "sacrebleu"
dynamic = ["version"]
authors = [{ name = "Matt Post", email = "[email protected]" }]
maintainers = [{ name = "Matt Post", email = "[email protected]" }]
description = "Hassle-free computation of shareable, comparable, and reproducible BLEU, chrF, and TER scores"
readme = "README.md"
license = { file = "LICENSE.txt" }
classifiers = [
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
"Development Status :: 5 - Production/Stable",

# Indicate who your project is intended for
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Text Processing",

# Pick your license as you wish (should match "license" above)
"License :: OSI Approved :: Apache Software License",

# List operating systems
"Operating System :: POSIX",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",

# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
"Programming Language :: Python :: 3 :: Only",

# Indicate that type hints are provided
"Typing :: Typed",
]

requires-python = ">=3.8"

keywords = [
"machine translation",
"evaluation",
"NLP",
"natural language processing",
"computational linguistics",
]

dependencies = [
"portalocker",
"regex",
"tabulate>=0.8.9",
"numpy>=1.17",
"colorama",
"lxml",
]

[project.optional-dependencies]
dev = ["wheel", "pytest", "mypy", "types-tabulate", "lxml-stubs", "setuptools"]
ja = ["mecab-python3>=1.0.9,<2.0.0", "ipadic>=1.0,<2.0"]
ko = ["mecab-ko>=1.0.0,<=1.0.1", "mecab-ko-dic>=1.0,<2.0"]

[project.scripts]
sacrebleu = "sacrebleu.sacrebleu:main"

[project.urls]
Repository = "https://github.com/mjpost/sacrebleu"

[tool.setuptools.packages.find]
include = ["sacrebleu*"]

[tool.setuptools.package-data]
sacrebleu = ["py.typed"]

[tool.setuptools_scm]
version_file = "sacrebleu/version.py"
63 changes: 43 additions & 20 deletions sacrebleu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,53 @@
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

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


from .utils import smart_open, SACREBLEU_DIR, download_test_set
from .utils import get_source_file, get_reference_files
from .utils import get_available_testsets, get_langpairs_for_testset
from .metrics.helpers import extract_word_ngrams, extract_char_ngrams
# Backward compatibility functions for old style API access (<= 1.4.10)
from .compat import (
corpus_bleu,
corpus_chrf,
corpus_ter,
raw_corpus_bleu,
sentence_bleu,
sentence_chrf,
sentence_ter,
)
from .dataset import DATASETS
from .metrics import BLEU, CHRF, TER

# Backward compatibility functions for old style API access (<= 1.4.10)
from .compat import corpus_bleu, raw_corpus_bleu, sentence_bleu
from .compat import corpus_chrf, sentence_chrf
from .compat import corpus_ter, sentence_ter
from .metrics.helpers import extract_char_ngrams, extract_word_ngrams
from .utils import (
SACREBLEU_DIR,
download_test_set,
get_available_testsets,
get_langpairs_for_testset,
get_reference_files,
get_source_file,
smart_open,
)
from .version import __version__

__all__ = [
'smart_open', 'SACREBLEU_DIR', 'download_test_set',
'get_source_file', 'get_reference_files',
'get_available_testsets', 'get_langpairs_for_testset',
'extract_word_ngrams', 'extract_char_ngrams',
'DATASETS',
'BLEU', 'CHRF', 'TER',
'corpus_bleu', 'raw_corpus_bleu', 'sentence_bleu',
'corpus_chrf', 'sentence_chrf',
'corpus_ter', 'sentence_ter'
"smart_open",
"SACREBLEU_DIR",
"download_test_set",
"get_source_file",
"get_reference_files",
"get_available_testsets",
"get_langpairs_for_testset",
"extract_word_ngrams",
"extract_char_ngrams",
"DATASETS",
"BLEU",
"CHRF",
"TER",
"corpus_bleu",
"raw_corpus_bleu",
"sentence_bleu",
"corpus_chrf",
"sentence_chrf",
"corpus_ter",
"sentence_ter",
"__version__",
]
Loading

0 comments on commit 5af5a3a

Please sign in to comment.