Skip to content

Commit

Permalink
Packaging update (#22)
Browse files Browse the repository at this point in the history
* Update __init__.py

* Update pyproject.toml

* fmt with black

* add poetry

* update checkout

* update poetry lock

* update: release pipeline

* add setup

* rm setup

* rm 3.10

* update: release pipeline
  • Loading branch information
michaelfeil authored Jun 20, 2024
1 parent f62bdd2 commit da370f3
Show file tree
Hide file tree
Showing 8 changed files with 2,518 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
39 changes: 17 additions & 22 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.7','3.8','3.9','3.10']
python: ['3.8','3.9','3.10']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'

- name: Install dependencies
run: |
pip install -r requirements_dev.txt
pip install -e .[sentence_transformers]
pip install poetry==1.8.3
poetry config virtualenvs.create false
poetry check --lock
poetry install --extras sentence_transformers --with test
- name: Lint with flake8
run: |
Expand All @@ -54,10 +55,10 @@ jobs:
- name: Generate Report
run: |
coverage run -m --source=./hf_hub_ctranslate2 pytest tests
coverage run -m --source=hf_hub_ctranslate2 pytest tests
coverage xml
- name: Upload coverage to Codecov for python 3.8
if: ${{ matrix.python == '3.8' }}
if: ${{ matrix.python == '3.10' }}
uses: codecov/codecov-action@v2

deploy_docs:
Expand All @@ -67,28 +68,22 @@ jobs:
# only run if pytest successfull
steps:
- name: Checkout current branch
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: 'branch-dir'

- name: Checkout gh-pages branch
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: 'gh-pages'
path: 'gh-pages-dir'

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'

- name: Install dependencies from current branch
run: |
cd branch-dir
pip install -r requirements_dev.txt
pip install -e .[sentence_transformers]
pip install poetry==1.8.3
poetry config virtualenvs.create false
poetry install --extras sentence_transformers --with test
- name: create shinx docs from current branch
# create shpinx api autodocs of opensentiment and move them to docs
# makefile: make html build the the docs/_build/html/
Expand Down Expand Up @@ -131,11 +126,11 @@ jobs:
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.10

- name: Install pypa/build
run: |
Expand Down
4 changes: 3 additions & 1 deletion hf_hub_ctranslate2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
"""Compatability between Huggingface and Ctranslate2."""
# __all__ = ["__version__", "TranslatorCT2fromHfHub", "GeneratorCT2fromHfHub", "MultiLingualTranslatorCT2fromHfHub"]
import importlib.metadata
import os
from hf_hub_ctranslate2.translate import (
TranslatorCT2fromHfHub,
GeneratorCT2fromHfHub,
Expand All @@ -9,4 +11,4 @@
)
from hf_hub_ctranslate2.ct2_sentence_transformers import CT2SentenceTransformer

__version__ = "2.13.0"
__version__ = importlib.metadata.version("hf_hub_ctranslate2")
2,461 changes: 2,461 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

40 changes: 35 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
[tool.poetry]
name = "hf_hub_ctranslate2"
version = "2.13.0"
description = "Connecting Transfromers on HuggingfaceHub with Ctranslate2."
authors = ["michaelfeil <mail at michaelfeil.eu>"]
license = "MIT"
readme = "README.md"
packages = [{include = "hf_hub_ctranslate2"}]

[tool.poetry.dependencies]
python = ">=3.8,<3.13"
numpy = "*"
ctranslate2 = ">=3.16.0"
transformers = ">=4.28.0"
huggingface-hub = "*"
sentence_transformers = {version="2.2.2", optional=true}

[tool.poetry.group.test.dependencies]
pytest= "6.2.5"
pytest-ordering = "0.6"
Sphinx = "5.*"
sphinx-rtd-theme = "1.0.0"
coverage = "6.2"
flake8 = "*"
pre-commit = "*"
myst-parser = {version="1.*",extras=["sphinx"]}
mkdocs = "*"
sentencepiece = "*"
typing_extensions = "*"

[tool.poetry.extras]
sentence_transformers=["sentence_transformers"]

[build-system]
requires = [
"setuptools>=60",
"wheel"
]
build-backend = "setuptools.build_meta"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
11 changes: 0 additions & 11 deletions requirements_dev.txt

This file was deleted.

46 changes: 0 additions & 46 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from hf_hub_ctranslate2.util import utils as _utils
from transformers import AutoTokenizer
import numpy as np


def test_encoder(model_name="michaelfeil/ct2fast-e5-small-v2"):
Expand All @@ -19,7 +20,6 @@ def test_encoder(model_name="michaelfeil/ct2fast-e5-small-v2"):
)["pooler_output"]
assert len(embeddings) == 3
assert len(embeddings[0]) == len(embeddings[1])
import numpy as np

assert isinstance(embeddings, np.ndarray)
embeddings_norm = embeddings / (embeddings**2).sum(axis=1, keepdims=True) ** 0.5
Expand Down

0 comments on commit da370f3

Please sign in to comment.