Skip to content

Commit

Permalink
Merge branch 'release-4.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenkov committed Aug 23, 2023
2 parents a60edb3 + 2e5f3d2 commit 30179c8
Show file tree
Hide file tree
Showing 189 changed files with 3,981 additions and 5,170 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build-docs.yml
@@ -0,0 +1,68 @@
#
# This workflow rebuilds documentation and stores the resulting patch as a
# workflow artifact. We can then download the artifact, apply the patch, and
# then push the changes.
#
# It's possible to do all this locally on a developer's machine, but it's not
# trivial, because it requires many pre-requisites.
#
name: Rebuild documentation
on: workflow_dispatch
jobs:
docs:
name: Rebuild documentation
timeout-minutes: 180
runs-on: ubuntu-20.04
defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v3
- name: Setup up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
#
# We use Py3.8 here for historical reasons.
#
python-version: "3.8"

- name: Update pip
run: python -m pip install -U pip

- name: Install apt packages for LaTeX rendering
run: |
sudo apt-get -yq update
sudo apt-get -yq remove texlive-binaries --purge
sudo apt-get -yq --no-install-suggests --no-install-recommends --force-yes install dvipng texlive-latex-base texlive-latex-extra texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended latexmk
sudo apt-get -yq install build-essential python3.8-dev
- name: Install gensim and its dependencies
run: pip install -e .[docs]

- name: Build documentation
run: |
python setup.py build_ext --inplace
make -C docs/src clean html
- name: Check changes to prebuilt docs
run: |
git config user.email "noreply@github.com"
git config user.name "Gensim Docs Build"
if ! git diff --quiet @ ; then
git add .
branch="$GITHUB_HEAD_REF ($GITHUB_REF_NAME)"
git commit -m "Import rebuilt documentation for branch $branch"
git format-patch @^
git bundle create prebuilt-docs-changes.bundle @^...@
git reset --mixed @^
git diff --exit-code --stat @
fi
- name: Upload prebuilt docs changes
if: always()
uses: actions/upload-artifact@v3
with:
name: prebuilt-docs-changes
path: |
*.patch
*.bundle
116 changes: 103 additions & 13 deletions .github/workflows/build-wheels.yml
Expand Up @@ -36,32 +36,122 @@ jobs:
platforms: all

- name: Build wheels
uses: pypa/cibuildwheel@v2.12.0
uses: pypa/cibuildwheel@v2.13.1
env:
CIBW_ARCHS_LINUX: x86_64 aarch64
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_ARCHS_WINDOWS: AMD64 x86 ARM64
CIBW_BEFORE_BUILD: pip install numpy scipy
CIBW_ARCHS_WINDOWS: AMD64 x86
CIBW_SKIP: pp* cp36-* cp37-* *-win32 *_i686 *-musllinux_*
CIBW_TEST_COMMAND: pytest -rfxEXs --durations=20 --disable-warnings --showlocals --pyargs gensim
CIBW_TEST_REQUIRES: pytest testfixtures mock
CIBW_TEST_SKIP: cp38* cp39* cp310* *_aarch64 *_arm64 *_universal2
CIBW_TEST_SKIP: cp38* cp39* cp310* cp311* *_aarch64 *_arm64 *_universal2
CIBW_BUILD_VERBOSITY: 3

- name: Upload wheels as artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: wheels-${{ matrix.os }}
path: wheelhouse/*.whl

test:
name: Test wheel for ${{ matrix.os }} Python ${{ matrix.python }}
needs: build_wheels
strategy:
fail-fast: false
matrix:
include:
- {python: '3.8', os: macos-11}
- {python: '3.9', os: macos-11}
- {python: '3.10', os: macos-11}
- {python: '3.11', os: macos-11}

- {python: '3.8', os: ubuntu-20.04}
- {python: '3.9', os: ubuntu-20.04}
- {python: '3.10', os: ubuntu-20.04}
- {python: '3.11', os: ubuntu-20.04}

- {python: '3.8', os: windows-2019}
- {python: '3.9', os: windows-2019}

#
# We know that the Windows Py3.10 wheels are broken. Don't test them,
# because it will fail the entire workflow.
#
# https://github.com/RaRe-Technologies/gensim/issues/3489
#
# - {python: '3.10', os: windows-2019}
- {python: '3.11', os: windows-2019}

runs-on: ${{ matrix.os }}
steps:
- name: Setup up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Downloads build artifacts
uses: actions/download-artifact@v3
with:
path: artifacts/

#
# We want to make sure our wheels run against older Numpy versions
#
- name: Install oldest-supported-numpy
run: python -m pip install oldest-supported-numpy

#
# Avoid checking out the entire gensim repo to get just one file
#
- name: Download installwheel.py
run: curl "https://raw.githubusercontent.com/RaRe-Technologies/gensim/develop/.github/workflows/installwheel.py" --output installwheel.py --silent

- name: Install wheel
run: python installwheel.py artifacts/wheels-${{ matrix.os }}

- name: Debug test environment
run: |
pip freeze
python -c 'import numpy;print(numpy.__file__)'
python -c 'import numpy;print(numpy.__version__)'
#
# If the wheel was incorrectly built, then this will fail.
# https://github.com/RaRe-Technologies/gensim/issues/3097
#
- name: Test wheel
run: python -c 'import gensim'

upload:
name: Upload to S3
if: always()
needs: build_wheels
runs-on: ubuntu-latest
steps:

- name: Install wheel uploading tool
run: python -m pip install wheelhouse-uploader

- name: Downloads build artifacts
uses: actions/download-artifact@v3
with:
path: artifacts/

- name: Check files
run: tree artifacts/

- name: Move all wheels into one folder
run: mkdir wheelhouse ; find artifacts/ -name '*.whl' -exec mv -v {} wheelhouse/ \;

- name: Upload wheels to s3://gensim-wheels
#
# Only do this if the credentials are set.
# This means that PRs will still build wheels, but not upload them.
# (PRs do not have access to secrets).
#
# The always() ensures this step runs even if a previous step fails.
# We want to upload wheels whenever possible (even if e.g. tests failed)
# because we don't want an innocuous test failure from blocking a release.
#
if: ${{ always() && env.WHEELHOUSE_UPLOADER_USERNAME && env.WHEELHOUSE_UPLOADER_SECRET }}
run: |
python -m pip install wheelhouse-uploader
ls wheelhouse/*.whl
python -m wheelhouse_uploader upload --local-folder wheelhouse/ --no-ssl-check gensim-wheels --provider S3 --no-enable-cdn
if: ${{ env.WHEELHOUSE_UPLOADER_USERNAME && env.WHEELHOUSE_UPLOADER_SECRET }}
run: python -m wheelhouse_uploader upload --local-folder wheelhouse/ --no-ssl-check gensim-wheels --provider S3 --no-enable-cdn
env:
WHEELHOUSE_UPLOADER_USERNAME: ${{ secrets.AWS_ACCESS_KEY_ID }}
WHEELHOUSE_UPLOADER_SECRET: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
35 changes: 35 additions & 0 deletions .github/workflows/installwheel.py
@@ -0,0 +1,35 @@
"""Install a wheel for the current platform."""
import os
import platform
import subprocess
import sys


def main():
subdir = sys.argv[1]
vi = sys.version_info

if platform.system() in ('Linux', 'Darwin'):
arch = 'x86_64'
else:
arch = 'amd64'

want = f'-cp{vi.major}{vi.minor}-'
suffix = f'_{arch}.whl'

files = sorted(os.listdir(subdir))
for f in files:
if want in f and f.endswith(suffix):
command = [sys.executable, '-m', 'pip', 'install', os.path.join(subdir, f)]
subprocess.check_call(command)
return 0

print(f'no matches for {want} / {suffix} in {subdir}:')
print('\n'.join(files))

return 1



if __name__ == '__main__':
sys.exit(main())
76 changes: 76 additions & 0 deletions .github/workflows/test_wheel.py
@@ -0,0 +1,76 @@
#!/usr/bin/env python
"""Test a Gensim wheel stored on S3.
Downloads the wheel, installs it into a fresh working environment, and then runs gensim tests.
usage:
python test_wheel.py <url> $(which python3.10)
where the URL comes from http://gensim-wheels.s3-website-us-east-1.amazonaws.com/
"""

import argparse
import io
import os
import subprocess
import tempfile
import urllib.parse
import urllib.request
import shutil
import sys

curr_dir = os.path.dirname(os.path.abspath(__file__))


def run(*command, **kwargs):
print("-" * 70, file=sys.stderr)
print(" ".join(command), file=sys.stderr)
print("-" * 70, file=sys.stderr)
subprocess.check_call(command, **kwargs)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("wheel_path", help="The location of the wheel. May be a URL or local path")
parser.add_argument("python", help="Which python binary to use to test the wheel")
parser.add_argument("--gensim-path", default=os.path.expanduser("~/git/gensim"), help="Where the gensim repo lives")
parser.add_argument("--keep", action="store_true", help="Do not delete the sandbox after testing")
parser.add_argument("--test", default="test", help="Specify which tests to run")
args = parser.parse_args()

_, python_version = subprocess.check_output([args.python, "--version"]).decode().strip().split(" ", 1)

try:
tmpdir = tempfile.mkdtemp(prefix=f"test_wheel-py{python_version}-")

tmp_test_path = os.path.join(tmpdir, "test")
shutil.copytree(os.path.join(args.gensim_path, "gensim/test"), tmp_test_path)

if args.wheel_path.startswith("http://") or args.wheel_path.startswith("https://"):
parsed = urllib.parse.urlparse(args.wheel_path)
filename = parsed.path.split('/')[-1]
wheel_path = os.path.join(tmpdir, filename)
urllib.request.urlretrieve(args.wheel_path, wheel_path)
else:
wheel_path = args.wheel_path

env_path = os.path.join(tmpdir, "env")
run("virtualenv", "-p", args.python, env_path)

python_exe = os.path.join(tmpdir, "env/bin/python")
run(python_exe, "-m", "pip", "install", wheel_path)
run(python_exe, "-m", "pip", "install", "mock", "pytest", "testfixtures")

pytest_exe = os.path.join(tmpdir, "env/bin/pytest")
run(pytest_exe, "-vvv", args.test, "--durations", "0", cwd=tmpdir)
finally:
if args.keep:
print(f"keeping {tmpdir}, remove it yourself when done")
else:
shutil.rmtree(tmpdir)



if __name__ == "__main__":
main()

0 comments on commit 30179c8

Please sign in to comment.