Skip to content

Commit

Permalink
Merge pull request #4 from Erotemic/dev/pypi_deploy
Browse files Browse the repository at this point in the history
Actions for sdist and pypi deployment
  • Loading branch information
erezsh authored Aug 3, 2022
2 parents 1f92dd1 + ad3636c commit 7ce53d1
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 5 deletions.
93 changes: 92 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jobs:
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", pypy3]

steps:
- uses: actions/checkout@v2
- name: Download submodules
Expand All @@ -29,6 +28,51 @@ jobs:
run: |
pytest
build_sdist:
name: Build source wheels
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/[email protected]
with:
python-version: 3.8
- name: Upgrade pip
run: |-
python -m pip install --upgrade pip
python -m pip install setuptools>=0.8 wheel build
- name: Build sdist
shell: bash
run: |-
python -m build --sdist --outdir wheelhouse
- name: Install sdist
run: |-
ls -al ./wheelhouse
pip install pytest pytest-cov
pip install Cython
pip install wheelhouse/*.tar.gz -v
- name: Test sdist
run: |-
pwd
ls -al
# Run in a sandboxed directory
WORKSPACE_DNAME="testsrcdir_minimal_${CI_PYTHON_VERSION}_${GITHUB_RUN_ID}_${RUNNER_OS}"
mkdir -p $WORKSPACE_DNAME
cd $WORKSPACE_DNAME
# Get path to installed package
MOD_NAME=lark_cython
MOD_DPATH=$(python -c "import $MOD_NAME, os; print(os.path.dirname($MOD_NAME.__file__))")
echo "MOD_DPATH = $MOD_DPATH"
# Run the tests
python -m pytest --cov=$MOD_NAME $MOD_DPATH ../tests
cd ..
- name: Upload sdist artifact
uses: actions/upload-artifact@v3
with:
name: wheels
path: ./wheelhouse/*.tar.gz

build_binary_wheels:
name: ${{ matrix.os }}, arch=${{ matrix.arch }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -99,3 +143,50 @@ jobs:
with:
name: wheels
path: ./wheelhouse/*.whl

publish_wheels:
name: Publish Wheels
runs-on: ubuntu-latest
needs:
- build_binary_wheels
- build_sdist

steps:
- name: Checkout source
uses: actions/checkout@v3

- name: Download wheels and sdist
uses: actions/download-artifact@v3
with:
name: wheels
path: wheelhouse

- name: Show files to upload
shell: bash
run: ls -la wheelhouse

### See github action page for details
# https://github.com/marketplace/actions/pypi-publish

# ----
- name: Publish to Live PyPI
# Only publish real wheels for new git tags.
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
#repository_url: https://upload.pypi.org/legacy/ # default url should be fine
packages_dir: wheelhouse
verbose: true

# ----
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: github.event_name == 'push' && ! startsWith(github.event.ref, 'refs/tags')
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
skip_existing: true
repository_url: https://test.pypi.org/legacy/
packages_dir: wheelhouse
verbose: true
42 changes: 38 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

__version__ ,= re.findall('__version__ = "(.*)"', open('lark_cython/__init__.py').read())

# python .\setup.py build_ext --inplace

from distutils.core import setup
# python .\setup.py build_ext --inplace


# Delayed import; https://stackoverflow.com/questions/37471313/setup-requires-with-cython
Expand All @@ -16,6 +14,20 @@ def cythonize(*args, **kwargs):
from Cython.Build import cythonize
return cythonize(*args, **kwargs)


def parse_description():
"""
Parse the description in the README file
"""
from os.path import dirname, join, exists
readme_fpath = join(dirname(__file__), 'README.md')
# This breaks on pip install, so check that it exists.
if exists(readme_fpath):
with open(readme_fpath, 'r') as f:
text = f.read()
return text
return ''

setup(
name = "lark-cython",
version = __version__,
Expand All @@ -31,4 +43,26 @@ def cythonize(*args, **kwargs):
description = "A Lark plugin that optimizes LALR parsing using Cython",
keywords = "Lark LALR parser optimized Cython",
url = "https://github.com/lark-parser/lark_cython",
)
long_description = parse_description(),
long_description_content_type = 'text/markdown',
license = 'MIT',
python_requires = '>=3.6',
classifiers = [
# List of classifiers available at:
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
"Development Status :: 4 - Beta",
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Utilities',
'Operating System :: Microsoft :: Windows',
'Operating System :: MacOS',
'Operating System :: POSIX :: Linux',
'License :: OSI Approved :: MIT License',
# Supported Python versions
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
],
)

0 comments on commit 7ce53d1

Please sign in to comment.