Skip to content

Commit

Permalink
Merge pull request #6 from McGill-NLP/publish-pypi
Browse files Browse the repository at this point in the history
Publish to PyPi via actions, update readme
  • Loading branch information
vaibhavad authored Aug 9, 2023
2 parents 67a163f + d5902fd commit 7ebc8e8
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 6 deletions.
35 changes: 35 additions & 0 deletions .github/scripts/update_version.py
Original file line number Diff line number Diff line change
@@ -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()
42 changes: 42 additions & 0 deletions .github/workflows/publish-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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:
publish-on-pypi:
# 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
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- 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: 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
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<details>
<summary>Show instructions for Virtual Environments</summary>
<br>
```bash
python3 -m venv instruct-qa-venv
source instruct-qa-venv/bin/activate
```
pip install -e .
</details>


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
Expand Down
5 changes: 5 additions & 0 deletions instruct_qa/version.py
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 20 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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,
)

0 comments on commit 7ebc8e8

Please sign in to comment.