Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize packaging and add release automation #270

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "post@cs.jhu.edu" }]
maintainers = [{ name = "Matt Post", email = "post@cs.jhu.edu" }]
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have my editor configured to auto-format using ruff, and that has introduced a lot more change in these files than is truly needed.

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__
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import replaces the old static definition.


__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__",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding __version__ here was needed.

]
Loading
Loading