Edit publish workflow to reuse existing test workflow, and use the build package to build the libretranslate package

This commit is contained in:
Vincent Emonet 2023-07-10 08:11:51 +02:00
parent 1c0fb597fb
commit a1eb871bb6
5 changed files with 20 additions and 66 deletions

View file

@ -9,35 +9,8 @@ on:
jobs: jobs:
tests: tests:
runs-on: ubuntu-latest uses: LibreTranslate/LibreTranslate/.github/workflows/run-tests.yml@main
strategy: secrets: inherit
matrix:
python-version: ['3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest flake8
pip install .
python scripts/compile_locales.py
- name: Check code style with flake8 (lint)
run: |
# warnings if there are Python syntax errors or undefined names
# (remove --exit-zero to fail when syntax error)
flake8 . --count --exit-zero --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: pytest
publish: publish:
@ -52,16 +25,16 @@ jobs:
python-version: '3.8' python-version: '3.8'
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip pipx install build
pip install setuptools wheel twine
python setup.py sdist bdist_wheel
- name: Build and publish to PyPI - name: Build
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: | run: |
pip install Babel==2.11.0 pip install Babel==2.11.0
python scripts/compile_locales.py python scripts/compile_locales.py
python setup.py sdist bdist_wheel python -m build
twine upload dist/*
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: ${{ secrets.PYPI_USERNAME }}
password: ${{ secrets.PYPI_PASSWORD }}

View file

@ -2,6 +2,7 @@ name: Run tests
# Run test at each push to main, if changes to package or tests files # Run test at each push to main, if changes to package or tests files
on: on:
workflow_dispatch: workflow_dispatch:
workflow_call:
pull_request: pull_request:
branches: [ main ] branches: [ main ]
push: push:
@ -29,18 +30,11 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
pip install ".[test]" pipx install hatch
hatch run locales
- name: Check code style with flake8 (lint)
run: |
# warnings if there are Python syntax errors or undefined names
# (remove --exit-zero to fail when syntax error)
flake8 . --count --exit-zero --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest - name: Test with pytest
run: pytest -v run: hatch run test
test_docker_build: test_docker_build:

View file

@ -45,14 +45,12 @@ def check_and_install_models(force=False, load_only_lang_codes=None):
# Download and install all available packages # Download and install all available packages
for available_package in available_packages: for available_package in available_packages:
print( print(
"Downloading %s (%s) ..." f"Downloading {available_package} ({available_package.package_version}) ..."
% (available_package, available_package.package_version)
) )
available_package.install() available_package.install()
# reload installed languages # reload installed languages
libretranslate.language.languages = translate.get_installed_languages() libretranslate.language.languages = translate.get_installed_languages()
print( print(
"Loaded support for %s languages (%s models total)!" f"Loaded support for {len(translate.get_installed_languages())} languages ({len(available_packages)} models total)!"
% (len(translate.get_installed_languages()), len(available_packages))
) )

View file

@ -84,8 +84,10 @@ features = [
"test", "test",
] ]
[tool.hatch.envs.default.scripts] [tool.hatch.envs.default.scripts]
dev = "python main.py {args}" dev = "python main.py {args}"
locales = "python scripts/compile_locales.py"
fmt = [ fmt = [
"ruff libretranslate scripts --fix", "ruff libretranslate scripts --fix",
] ]
@ -145,8 +147,7 @@ select = [
"PLE", # pylint error "PLE", # pylint error
# "PLR", # pylint refactor # "PLR", # pylint refactor
# "PLW", # pylint warning # "PLW", # pylint warning
"RUF", # ruff specific # "RUF", # ruff specific
"T",
] ]
ignore = [ ignore = [

View file

@ -1,12 +0,0 @@
[flake8]
exclude = .git,
.vscode,
.gitignore,
README.md,
venv,
test,
setup.py,
libretranslate/__init__.py
max-line-length = 136
ignore = E741