From 147173e9401a08f5fe20ac1a3ef50c5d55e9d8ec Mon Sep 17 00:00:00 2001 From: Jonas Renault Date: Fri, 8 Mar 2024 15:42:26 +0100 Subject: [PATCH] add workflows --- .github/workflows/pre_publish.yml | 38 ++++++++++++++++++++++ .github/workflows/publish.yml | 39 ++++++++++++++++++++++ .github/workflows/test.yml | 54 +++++++++++++++++++++++++++++++ README.md | 10 +++--- poetry.lock | 48 ++++++++++++++++++++++++++- pyproject.toml | 3 ++ 6 files changed, 185 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/pre_publish.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/pre_publish.yml b/.github/workflows/pre_publish.yml new file mode 100644 index 0000000..7da3936 --- /dev/null +++ b/.github/workflows/pre_publish.yml @@ -0,0 +1,38 @@ +name: Publish to Test PyPI + +on: + push: + tags: + - "v*.*.*" + +env: # environment variables (available in any part of the action) + PYTHON_VERSION: 3.11 + +jobs: + pre-publish: + name: Publish to Test PyPI + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v4 + + - name: Install poetry + run: pipx install poetry + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: "poetry" + + - name: Install dependencies + run: poetry install --no-interaction --no-root + + - name: Config Repository + run: poetry config repositories.testpypi https://test.pypi.org/legacy/ + + - name: Login to PyPI Test + run: poetry config pypi-token.testpypi ${{ secrets.TEST_PYPI_API_KEY }} + + - name: Publish package + run: poetry publish --build -r testpypi diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..363bd57 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,39 @@ +name: Test + +on: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - main + pull_request: + branches: + - main + +env: # environment variables (available in any part of the action) + PYTHON_VERSION: 3.11 + +jobs: + test: + name: Run tests + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v4 + + - name: Install poetry + run: pipx install poetry + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: "poetry" + + # Install dependencies. `--no-root` means "install all dependencies but not the project + # itself", which is what you want to avoid caching _your_ code. + - name: Install dependencies + run: poetry install --no-interaction --no-root --with dev + + - name: Test with pytest + run: poetry run pytest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..494c5eb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,54 @@ +name: Test + +on: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - main + pull_request: + branches: + - main + +env: # environment variables (available in any part of the action) + PYTHON_VERSION: 3.11 + +jobs: + lint-test: + name: Run tests + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v4 + + - name: Install poetry + run: pipx install poetry + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: "poetry" + + - name: Check Poetry File + run: poetry check + + - name: Check lock file + run: poetry lock --check + + # Install dependencies. `--no-root` means "install all dependencies but not the project + # itself", which is what you want to avoid caching _your_ code. + - name: Install dependencies + run: poetry install --no-interaction --no-root --with dev --with stubs + + - name: Test with pytest + run: poetry run pytest + + - name: Run black + run: poetry run black --check --config ./pyproject.toml . + + - name: Run mypy + run: poetry run mypy + + - name: Run ruff + run: poetry run ruff check diff --git a/README.md b/README.md index b6dc6a6..e8b0eb8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # CPREx - Chemical Properties Relation Extraction [![License](https://img.shields.io/badge/License-MIT-yellow)](LICENSE) -![python_version](https://img.shields.io/badge/Python-%3E=3.10-blue) +![python_version](https://img.shields.io/badge/Python-%3E=3.11-blue) CPREx is an end to end tool for Named Entity Recognition (NER) and Relation Extraction (RE) specifically designed for chemical compounds and their properties. The goal of the tool is to identify, extract and link chemical compounds and their properties from scientific literature. For ease of use, CPREx provides a custom [spacy](https://spacy.io/) pipeline to perform NER and RE. @@ -69,9 +69,7 @@ Any modifications you make to the cprex codebase will be immediatly reflected th #### Installing and running grobid -CPREx depends on [GROBID](https://github.com/kermitt2/grobid) and its extension [grobid-quantities](https://github.com/lfoppiano/grobid-quantities) for parsing PDF documents and extracting quantities from their text. - -For convenience, CPREx provides a command line interface (CLI) to install grobid and start a grobid server. +CPREx depends on [GROBID](https://github.com/kermitt2/grobid) and its extension [grobid-quantities](https://github.com/lfoppiano/grobid-quantities) for parsing PDF documents and extracting quantities from their text. For convenience, CPREx provides a command line interface (CLI) to install grobid and start a grobid server. Run @@ -91,10 +89,10 @@ to start a grobid server and enable parsing of PDF documents from CPREx. #### Installing NER et REL models -To perform Named Entity Recognition of chemical compounds and Relation Extraction, CPREx requires some pretrained models. These models can be installed by running +To perform Named Entity Recognition (NER) of chemical compounds and Relation Extraction (RE), CPREx requires some pretrained models. These models can be installed by running ```console cprex install-models ``` -This will install a PubmedBert model finetuned on the NLM-CHEM corpus for extraction of chemical named entities. This model was finetuned by the [BioCreative VII track](https://biocreative.bioinformatics.udel.edu/tasks/biocreative-vii/track-2/). +This will install a [PubmedBert model](https://ftp.ncbi.nlm.nih.gov/pub/lu/BC7-NLM-Chem-track/) finetuned on the NLM-CHEM corpus for extraction of chemical named entities. This model was finetuned by the [BioCreative VII track](https://biocreative.bioinformatics.udel.edu/tasks/biocreative-vii/track-2/). diff --git a/poetry.lock b/poetry.lock index 3ff1096..269376b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -960,6 +960,17 @@ files = [ {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, ] +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + [[package]] name = "ipykernel" version = "6.29.3" @@ -2224,6 +2235,21 @@ files = [ docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"] test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"] +[[package]] +name = "pluggy" +version = "1.4.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pluggy-1.4.0-py3-none-any.whl", hash = "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981"}, + {file = "pluggy-1.4.0.tar.gz", hash = "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + [[package]] name = "pre-commit" version = "3.6.2" @@ -2505,6 +2531,26 @@ files = [ plugins = ["importlib-metadata"] windows-terminal = ["colorama (>=0.4.6)"] +[[package]] +name = "pytest" +version = "8.0.2" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-8.0.2-py3-none-any.whl", hash = "sha256:edfaaef32ce5172d5466b5127b42e0d6d35ebbe4453f0e3505d96afd93f6b096"}, + {file = "pytest-8.0.2.tar.gz", hash = "sha256:d4051d623a2e0b7e51960ba963193b09ce6daeb9759a451844a21e4ddedfc1bd"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=1.3.0,<2.0" + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + [[package]] name = "python-dateutil" version = "2.9.0.post0" @@ -4401,4 +4447,4 @@ colorlog = "*" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "0eb150695cd97356e4214abb1298832f7cb1fc17b88186606ecebd8b1abe9477" +content-hash = "fabdc34c928b5574723816e8a6cb5f0f8f98d582ccc5713189e2a94f7a3f923f" diff --git a/pyproject.toml b/pyproject.toml index 9f56f89..8ea6387 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,8 +4,10 @@ version = "0.2.0" description = "Chemical Properties Relation Extraction" authors = ["Jonas Renault ", "Lucie Chasseur "] readme = "README.md" +license = "MIT" homepage = "https://github.com/jonasrenault/cprex#readme" repository = "https://github.com/jonasrenault/cprex" +keywords = ["pubchem", "crawler", "chemistry", "machine-learning", "relation-extraction", "named-entity-extraction", "deep-learning", "transformers", "spacy", "scientific-articles"] [tool.poetry.dependencies] python = "^3.11" @@ -32,6 +34,7 @@ black = "^24.2.0" mypy = "^1.8.0" bandit = "^1.7.7" jupyterlab = "^4.1.3" +pytest = "^8.0.2" [tool.poetry.group.stubs]