From a1eb871bb65701ccbf9ff34b1fb07c866de8a5fd Mon Sep 17 00:00:00 2001 From: Vincent Emonet Date: Mon, 10 Jul 2023 08:11:51 +0200 Subject: [PATCH] Edit publish workflow to reuse existing test workflow, and use the build package to build the libretranslate package --- .github/workflows/publish-package.yml | 49 ++++++--------------------- .github/workflows/run-tests.yml | 14 +++----- libretranslate/init.py | 6 ++-- pyproject.toml | 5 +-- setup.cfg | 12 ------- 5 files changed, 20 insertions(+), 66 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 5b752ba..aaa2304 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -9,35 +9,8 @@ on: jobs: tests: - runs-on: ubuntu-latest - strategy: - 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 + uses: LibreTranslate/LibreTranslate/.github/workflows/run-tests.yml@main + secrets: inherit publish: @@ -52,16 +25,16 @@ jobs: python-version: '3.8' - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - python setup.py sdist bdist_wheel + pipx install build - - name: Build and publish to PyPI - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + - name: Build run: | pip install Babel==2.11.0 python scripts/compile_locales.py - python setup.py sdist bdist_wheel - twine upload dist/* + python -m build + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: ${{ secrets.PYPI_USERNAME }} + password: ${{ secrets.PYPI_PASSWORD }} diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a14d001..2703870 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,6 +2,7 @@ name: Run tests # Run test at each push to main, if changes to package or tests files on: workflow_dispatch: + workflow_call: pull_request: branches: [ main ] push: @@ -29,18 +30,11 @@ jobs: - name: Install dependencies run: | - pip install ".[test]" - - - 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 + pipx install hatch + hatch run locales - name: Test with pytest - run: pytest -v + run: hatch run test test_docker_build: diff --git a/libretranslate/init.py b/libretranslate/init.py index 04aa866..eec788d 100644 --- a/libretranslate/init.py +++ b/libretranslate/init.py @@ -45,14 +45,12 @@ def check_and_install_models(force=False, load_only_lang_codes=None): # Download and install all available packages for available_package in available_packages: print( - "Downloading %s (%s) ..." - % (available_package, available_package.package_version) + f"Downloading {available_package} ({available_package.package_version}) ..." ) available_package.install() # reload installed languages libretranslate.language.languages = translate.get_installed_languages() print( - "Loaded support for %s languages (%s models total)!" - % (len(translate.get_installed_languages()), len(available_packages)) + f"Loaded support for {len(translate.get_installed_languages())} languages ({len(available_packages)} models total)!" ) diff --git a/pyproject.toml b/pyproject.toml index 17b9fb1..d7d1252 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,8 +84,10 @@ features = [ "test", ] + [tool.hatch.envs.default.scripts] dev = "python main.py {args}" +locales = "python scripts/compile_locales.py" fmt = [ "ruff libretranslate scripts --fix", ] @@ -145,8 +147,7 @@ select = [ "PLE", # pylint error # "PLR", # pylint refactor # "PLW", # pylint warning - "RUF", # ruff specific - "T", + # "RUF", # ruff specific ] ignore = [ diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index e7ca7e4..0000000 --- a/setup.cfg +++ /dev/null @@ -1,12 +0,0 @@ -[flake8] -exclude = .git, - .vscode, - .gitignore, - README.md, - venv, - test, - setup.py, - libretranslate/__init__.py - -max-line-length = 136 -ignore = E741