From b99faf776a5e5a4ad04631dba782b56763267da4 Mon Sep 17 00:00:00 2001 From: xhluca Date: Wed, 9 Aug 2023 17:34:05 -0400 Subject: [PATCH 1/8] Add files necessary for pypi publishing --- .github/scripts/update_version.py | 35 +++++++++++++++++++++++++ .github/workflows/publish-python.yml | 38 ++++++++++++++++++++++++++++ instruct_qa/version.py | 5 ++++ setup.py | 23 ++++++++++++++--- 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/update_version.py create mode 100644 .github/workflows/publish-python.yml create mode 100644 instruct_qa/version.py diff --git a/.github/scripts/update_version.py b/.github/scripts/update_version.py new file mode 100644 index 0000000..33baec2 --- /dev/null +++ b/.github/scripts/update_version.py @@ -0,0 +1,35 @@ +""" +This CLI script is used to update the version of the package. It is used by the +CI/CD pipeline to update the version of the package when a new release is made. + +It uses argparse to parse the command line arguments, which are the new version +and the path to the package's __init__.py file. +""" + +import argparse +from pathlib import Path + +def main(): + parser = argparse.ArgumentParser( + description="Update the version of the package." + ) + parser.add_argument( + "--version", + type=str, + help="The new version of the package.", + required=True, + ) + parser.add_argument( + "--path", + type=Path, + help="The path to the package's version file.", + default="instruct_qa/version.py", + ) + args = parser.parse_args() + + with open(args.path, "w") as f: + f.write(f"__version__ = \"{args.version}\"") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/.github/workflows/publish-python.yml b/.github/workflows/publish-python.yml new file mode 100644 index 0000000..2a3215c --- /dev/null +++ b/.github/workflows/publish-python.yml @@ -0,0 +1,38 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Publish Python Package + +on: + release: + types: [created] + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + + - name: Update version.py with release tag + env: + RELEASE_TAG: ${{ github.event.release.tag_name }} + run: | + python .github/scripts/update_version.py --version $RELEASE_TAG + + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* diff --git a/instruct_qa/version.py b/instruct_qa/version.py new file mode 100644 index 0000000..9f46ecc --- /dev/null +++ b/instruct_qa/version.py @@ -0,0 +1,5 @@ +__version__ = "0.0.1" + +# NOTE: Do not modify this manually. Version is automatically updated in +# .github/scripts/update_version.py when .github/workflows/publish-python.yml +# is run. \ No newline at end of file diff --git a/setup.py b/setup.py index 41c789c..3173543 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,21 @@ -from setuptools import setup +from setuptools import setup, find_packages + + +version = {} +with open("instruct_qa/version.py") as fp: + exec(fp.read(), version) + +with open("README.md") as fp: + long_description = fp.read() setup( name="instruct-qa", description="Empirical evaluation of retrieval-augmented instruction-following models.", - version="0.0.1", + version=version["__version__"], + author="McGill NLP", url="https://github.com/McGill-NLP/instruct-qa", python_requires=">=3.7", - packages=["instruct_qa"], + packages=find_packages(include=['instruct_qa*']), install_requires=[ "torch", "transformers", @@ -29,6 +38,14 @@ extras_require={ "evaluation": ["tensorflow-text", "bert_score", "allennlp", "allennlp-models"], }, + classifiers=[ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + # Apache license + "License :: OSI Approved :: Apache Software License", + ], + long_description=long_description, + long_description_content_type="text/markdown", include_package_data=True, zip_safe=False, ) From 6b839590ae47cc120896d8cce0b52b28f3ea7937 Mon Sep 17 00:00:00 2001 From: xhluca Date: Wed, 9 Aug 2023 17:38:04 -0400 Subject: [PATCH 2/8] Remove username and password --- .github/workflows/publish-python.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/publish-python.yml b/.github/workflows/publish-python.yml index 2a3215c..6c36860 100644 --- a/.github/workflows/publish-python.yml +++ b/.github/workflows/publish-python.yml @@ -30,9 +30,6 @@ jobs: python .github/scripts/update_version.py --version $RELEASE_TAG - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | python setup.py sdist bdist_wheel twine upload dist/* From c69bdd1072a37af7c85fc041ee28cad8a4c466a0 Mon Sep 17 00:00:00 2001 From: xhluca Date: Wed, 9 Aug 2023 17:41:32 -0400 Subject: [PATCH 3/8] Add permission and environment --- .github/workflows/publish-python.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-python.yml b/.github/workflows/publish-python.yml index 6c36860..d8ab9af 100644 --- a/.github/workflows/publish-python.yml +++ b/.github/workflows/publish-python.yml @@ -11,7 +11,11 @@ jobs: deploy: runs-on: ubuntu-latest - + # Specifying a GitHub environment is optional, but strongly encouraged + environment: release + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write steps: - uses: actions/checkout@v2 - name: Set up Python @@ -30,6 +34,9 @@ jobs: python .github/scripts/update_version.py --version $RELEASE_TAG - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | python setup.py sdist bdist_wheel twine upload dist/* From 5fe69502cd5edd9c27ca4df0bb2450739340acef Mon Sep 17 00:00:00 2001 From: xhluca Date: Wed, 9 Aug 2023 17:44:21 -0400 Subject: [PATCH 4/8] Refactor to follow pypi convention --- .github/workflows/publish-python.yml | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/.github/workflows/publish-python.yml b/.github/workflows/publish-python.yml index d8ab9af..8dc90bd 100644 --- a/.github/workflows/publish-python.yml +++ b/.github/workflows/publish-python.yml @@ -8,8 +8,7 @@ on: types: [created] jobs: - deploy: - + publish-on-pypi: runs-on: ubuntu-latest # Specifying a GitHub environment is optional, but strongly encouraged environment: release @@ -22,21 +21,12 @@ jobs: uses: actions/setup-python@v2 with: python-version: '3.8' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - + - name: Update version.py with release tag env: RELEASE_TAG: ${{ github.event.release.tag_name }} run: | python .github/scripts/update_version.py --version $RELEASE_TAG - - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file From 4878ab3174170310ef73dbde7e06296bc992548a Mon Sep 17 00:00:00 2001 From: xhluca Date: Wed, 9 Aug 2023 17:46:08 -0400 Subject: [PATCH 5/8] Test 4 --- .github/workflows/publish-python.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-python.yml b/.github/workflows/publish-python.yml index 8dc90bd..231aa8e 100644 --- a/.github/workflows/publish-python.yml +++ b/.github/workflows/publish-python.yml @@ -8,13 +8,8 @@ on: types: [created] jobs: - publish-on-pypi: + update-version: runs-on: ubuntu-latest - # Specifying a GitHub environment is optional, but strongly encouraged - environment: release - permissions: - # IMPORTANT: this permission is mandatory for trusted publishing - id-token: write steps: - uses: actions/checkout@v2 - name: Set up Python @@ -28,5 +23,14 @@ jobs: run: | python .github/scripts/update_version.py --version $RELEASE_TAG + publish-on-pypi: + runs-on: ubuntu-latest + needs: update-version # IMPORTANT: ensures that version is updated before publishing + # Specifying a GitHub environment is optional, but strongly encouraged + environment: release + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + steps: - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file From 94d8379831e6f538f257cca74db4d1adefd96ace Mon Sep 17 00:00:00 2001 From: xhluca Date: Wed, 9 Aug 2023 17:50:16 -0400 Subject: [PATCH 6/8] Add a install and build step --- .github/workflows/publish-python.yml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish-python.yml b/.github/workflows/publish-python.yml index 231aa8e..babdf04 100644 --- a/.github/workflows/publish-python.yml +++ b/.github/workflows/publish-python.yml @@ -8,7 +8,14 @@ on: types: [created] jobs: - update-version: + publish-on-pypi: + needs: update-version # IMPORTANT: ensures that version is updated before publishing + # Specifying a GitHub environment is optional, but strongly encouraged + environment: release + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -23,14 +30,14 @@ jobs: run: | python .github/scripts/update_version.py --version $RELEASE_TAG - publish-on-pypi: - runs-on: ubuntu-latest - needs: update-version # IMPORTANT: ensures that version is updated before publishing - # Specifying a GitHub environment is optional, but strongly encouraged - environment: release - permissions: - # IMPORTANT: this permission is mandatory for trusted publishing - id-token: write - steps: + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools twine wheel + + - name: Build package by running setup.py + run: | + python setup.py sdist bdist_wheel + - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file From 82ec4a7fb1a6c88a4960a0db9a1d5c533e7adb38 Mon Sep 17 00:00:00 2001 From: xhluca Date: Wed, 9 Aug 2023 17:51:10 -0400 Subject: [PATCH 7/8] Remove old dependencies --- .github/workflows/publish-python.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish-python.yml b/.github/workflows/publish-python.yml index babdf04..2ec0572 100644 --- a/.github/workflows/publish-python.yml +++ b/.github/workflows/publish-python.yml @@ -9,7 +9,6 @@ on: jobs: publish-on-pypi: - needs: update-version # IMPORTANT: ensures that version is updated before publishing # Specifying a GitHub environment is optional, but strongly encouraged environment: release permissions: From d5902fdf35376135d1315be99f5bafcb5b4fa0f5 Mon Sep 17 00:00:00 2001 From: xhluca Date: Wed, 9 Aug 2023 18:04:15 -0400 Subject: [PATCH 8/8] Add pip install instructions and badge to readme --- README.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 87d2bd2..bdf0da5 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,39 @@ [![arXiv](https://img.shields.io/badge/arXiv-2307.16877-b31b1b.svg)](https://arxiv.org/abs/2307.16877) [![License](https://img.shields.io/badge/License-Apache_2.0-yellowgreen.svg)](https://opensource.org/licenses/Apache-2.0) - +[![PyPi](https://img.shields.io/pypi/v/instruct-qa)](https://pypi.org/project/instruct-qa/) ## Quick Start ### Installation -You can install the library via pip. +Make sure you have Python 3.7+ installed. It is also a good idea to use a virtual environment. +
+Show instructions for Virtual Environments +
+```bash +python3 -m venv instruct-qa-venv +source instruct-qa-venv/bin/activate ``` -pip install -e . +
+ + +You can install the library via `pip`: + +```bash +# Install the latest release +pip3 install instruct-qa + +# Install the latest version from GitHub +pip3 install git+https://github.com/McGill-NLP/instruct-qa ``` + +For development, you can install it in editable mode with: +``` +git clone https://github.com/McGill-NLP/instruct-qa +cd instruct-qa/ +pip3 install -e . +``` + ### Usage Here is a simple example to get started. Using this library, use can easily leverage retrieval-augmented instruction-following models for question-answering in ~25 lines of code. The source file for this example is [examples/get_started.py](examples/get_started.py). ```python