Skip to content

Commit

Permalink
Use more linters, better (#250)
Browse files Browse the repository at this point in the history
* Use more linters, better

* Rely on Ruff during CI only due to the outdated Python versions

* Run on Python 3.12, too, and fix typing on Windows

* Do not test on Python 3.12 as mecab-python3 is not available yet

* Build (but not publish) during CI

* Add wheel

* Update check-build.yml

* Update the dataset URLs to use HTTPS
  • Loading branch information
dustalov authored Nov 28, 2023
1 parent 275e292 commit 9e57a51
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 110 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/check-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
- os: ubuntu-20.04
python-version: '3.6' # test Python 3.6 on older Ubuntu instead
steps:
# - name: update
# run: sudo apt-get -y update
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
Expand All @@ -44,12 +42,18 @@ jobs:
run: choco install wget unzip
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install .[ja]
pip install .[ko]
python3 -m pip install --upgrade pip
pip3 install .[dev]
pip3 install .[ja]
pip3 install .[ko]
- name: Lint with Mypy
run: mypy sacrebleu scripts test
- name: Lint with Ruff
uses: chartboost/ruff-action@v1
- name: Python pytest test suite
run: python3 -m pytest
- name: CLI bash test suite
shell: bash
run: ./test.sh
- name: Build
run: python3 setup.py sdist bdist_wheel
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ __pycache__
sacrebleu.egg-info
.sacrebleu
*~
.DS_Store
.DS_Store
.idea/
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.PHONY: test
test:
mypy sacrebleu scripts test
python3 -m pytest
bash test.sh

Expand Down
9 changes: 9 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ ignore_missing_imports = True

[mypy-MeCab.*]
ignore_missing_imports = True

[mypy-mecab_ko.*]
ignore_missing_imports = True

[mypy-mecab_ko_dic.*]
ignore_missing_imports = True

[mypy-sentencepiece.*]
ignore_missing_imports = True
18 changes: 9 additions & 9 deletions sacrebleu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
__description__ = 'Hassle-free computation of shareable, comparable, and reproducible BLEU, chrF, and TER scores'


from .utils import smart_open, SACREBLEU_DIR, download_test_set # noqa: F401
from .utils import get_source_file, get_reference_files # noqa: F401
from .utils import get_available_testsets, get_langpairs_for_testset # noqa: F401
from .metrics.helpers import extract_word_ngrams, extract_char_ngrams # noqa: F401
from .dataset import DATASETS # noqa: F401
from .metrics import BLEU, CHRF, TER # noqa: F401
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
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 # noqa: F401
from .compat import corpus_chrf, sentence_chrf # noqa: F401
from .compat import corpus_ter, sentence_ter # noqa: F401
from .compat import corpus_bleu, raw_corpus_bleu, sentence_bleu
from .compat import corpus_chrf, sentence_chrf
from .compat import corpus_ter, sentence_ter

__all__ = [
'smart_open', 'SACREBLEU_DIR', 'download_test_set',
Expand Down
2 changes: 1 addition & 1 deletion sacrebleu/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def raw_corpus_bleu(hypotheses: Sequence[str],
def sentence_bleu(hypothesis: str,
references: Sequence[str],
smooth_method: str = 'exp',
smooth_value: float = None,
smooth_value: Optional[float] = None,
lowercase: bool = False,
tokenize=BLEU.TOKENIZER_DEFAULT,
use_effective_order: bool = True) -> BLEUScore:
Expand Down
Loading

0 comments on commit 9e57a51

Please sign in to comment.