Skip to content

Commit

Permalink
Add files for pypi release
Browse files Browse the repository at this point in the history
  • Loading branch information
xhluca committed Apr 20, 2024
1 parent 4e27687 commit 350bd13
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/scripts/python/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
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.",
)
args = parser.parse_args()

with open(args.path, "w") as f:
f.write(f"__version__ = \"{args.version}\"")


if __name__ == "__main__":
main()
46 changes: 46 additions & 0 deletions .github/workflows/publish-python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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:
bump-version-and-publish:
name: Bump version and upload release to PyPI

runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

environment:
name: pypi
url: https://pypi.org/p/webllama

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Update version.py with release tag
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
python .github/scripts/python/update_version.py --version $RELEASE_TAG --path "webllama/version.py"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build package
run: |
python setup.py sdist bdist_wheel
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
37 changes: 37 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from setuptools import setup, find_packages

package_name = "webllama"
version = {}
with open(f"{package_name}/version.py") as fp:
exec(fp.read(), version)

with open("README.md") as fp:
long_description = fp.read()

extras_require = {
"dev": ["black"],
}
# Dynamically create the 'all' extra by combining all other extras
extras_require["all"] = sum(extras_require.values(), [])

setup(
name=package_name,
version=version["__version__"],
author="Xing Han Lù",
author_email=f"{package_name}@googlegroups.com",
url=f"https://github.com/McGill-NLP/{package_name}",
description="Llama-powered agents for automatic web browsing",
long_description=long_description,
packages=find_packages(include=[f"{package_name}*"]),
package_data={},
install_requires=['scipy', 'numpy'],
extras_require=extras_require,
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires=">=3.8",
# Cast long description to markdown
long_description_content_type="text/markdown",
)
1 change: 1 addition & 0 deletions webllama/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .version import __version__
1 change: 1 addition & 0 deletions webllama/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.1dev0"

0 comments on commit 350bd13

Please sign in to comment.