Skip to content

Commit

Permalink
add GA to publish to pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
louisguitton committed Sep 22, 2024
1 parent ea26d83 commit e97650b
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 19 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# ref: https://johnfraney.ca/blog/how-to-publish-a-python-package-with-poetry-and-github-actions/
name: Upload Python Package to PyPI when a Release is Created

on:
release:
types: [created]

permissions:
contents: read

jobs:
pypi-publish:
name: Publish release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/spacy-lancedb-linker
permissions:
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y
- name: Update PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Update Poetry configuration
run: poetry config virtualenvs.create false

- name: Install dependencies
run: poetry install --sync --no-interaction

- name: Package project
run: poetry build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
75 changes: 57 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,71 @@
## Installation

```python
poetry install
```sh
pip install spacy-lancedb-linker
```

## Usage

```python
poetry shell
poetry run ...
```
import spacy

## test
from spacy_lancedb_linker.kb import AnnKnowledgeBase
from spacy_lancedb_linker.linker import AnnLinker # noqa
from spacy_lancedb_linker.types import Alias, Entity

```python
poetry run pytest
```
nlp = spacy.load("en_core_web_md")
kb = AnnKnowledgeBase(uri="data/sample-lancedb")
kb.add_entities(
[
Entity(**entity)
for entity in [
{
"entity_id": "a3",
"name": "Natural language processing",
"description": "Natural language processing (NLP) is a subfield of linguistics, computer science, information engineering, and artificial intelligence concerned with the interactions between computers and human (natural) languages, in particular how to program computers to process and analyze large amounts of natural language data.",
},
{
"entity_id": "a4",
"name": "Neuro-linguistic programming",
"description": "Neuro-linguistic programming (NLP) is a pseudoscientific approach to communication, personal development, and psychotherapy created by Richard Bandler and John Grinder in California, United States in the 1970s.",
},
]
]
)
kb.add_aliases(
[
Alias(**alias)
for alias in [
{"alias": "NLP", "entities": ["a3", "a4"], "probabilities": [0.5, 0.5]},
{
"alias": "Natural language processing",
"entities": ["a3"],
"probabilities": [1.0],
},
{
"alias": "Neuro-linguistic programming",
"entities": ["a4"],
"probabilities": [1.0],
},
]
]
)

## TODO
ann_linker = nlp.add_pipe("ann_linker", last=True)
ann_linker.set_kb(kb)

- setup trusted publisher github action https://medium.com/@blackary/publishing-a-python-package-from-github-to-pypi-in-2024-a6fb8635d45d
doc = nlp("NLP is a subset of machine learn.")

Other
print(doc.ents[0].kb_id_)
print(doc.ents[0]._.alias_candidates)
print(doc.ents[0]._.kb_candidates)
```

## Test

- docs?
- more Github actions?
- add docker https://matt.sh/python-project-structure-2024#_living-with-pyproject.toml
- test coverage
- test across python versions
- use collections, itertools, more-itertools, boltons, sortedcontainers, diskcache, peewee, httpx, loguru, orjson
```sh
poetry install
poetry shell
poetry run pytest
```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
homepage = "https://guitton.co/"
repository = "https://github.com/louisguitton/spacy-lancedb-linker"
documentation = "https://guitton.co/"
keywords = ["spacy", "entity-linking", "ann", "lancedb"]
keywords = ["spacy", "spacy-pipeline", "entity-linking", "ann", "lancedb"]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
Expand Down

0 comments on commit e97650b

Please sign in to comment.