Skip to content

Commit

Permalink
Run CI on Mac/Linux/Windows with Python 3.3 and 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Aug 16, 2021
1 parent dd0d119 commit 2ea8653
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 8 deletions.
100 changes: 92 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,28 @@ on:
- master

jobs:
build:
name: Python ${{ matrix.python }} on ${{ matrix.os }} ${{ matrix.arch }}
build-38:
name: Python 3.8.7 on ${{ matrix.os }} ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- windows-2019
- macos-10.15
- ubuntu-18.04
python:
- '3.3.7'
- '3.8.7'
arch:
- 'x64'
- x86
- x64
exclude:
- os: macos-10.15
arch: x86
- os: ubuntu-18.04
arch: x86
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@main
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
python-version: '3.8.7'
architecture: ${{ matrix.arch }}
- name: Install dependencies
run: python dev/deps.py
Expand All @@ -37,3 +42,82 @@ jobs:
GH_PASS: ${{ secrets.GH_PASS }}
GL_PASS: ${{ secrets.GL_PASS }}
BB_PASS: ${{ secrets.BB_PASS }}

build-linux-33:
name: Python 3.3.7 on ubuntu-18.04 x64
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@main
with:
python-version: '3.3.7'
architecture: x64
- name: Install dependencies
run: python dev/deps.py
- name: Run linter
run: python dev/lint.py
- name: Run tests
run: python dev/tests.py
env:
GH_PASS: ${{ secrets.GH_PASS }}
GL_PASS: ${{ secrets.GL_PASS }}
BB_PASS: ${{ secrets.BB_PASS }}

build-mac-33:
name: Python 3.3.7 on macos-10.15 x64
runs-on: macos-10.15
steps:
- uses: actions/checkout@master

- name: Check pyenv
id: check-pyenv
uses: actions/cache@v2
with:
path: ~/.pyenv
key: macos-10.15-3.3-pyenv

- name: Install Python 3.3
run: python dev/pyenv-install.py 3.3 >> $GITHUB_PATH

- name: Install dependencies
run: python dev/deps.py
- name: Run linter
run: python dev/lint.py
- name: Run tests
run: python dev/tests.py
env:
GH_PASS: ${{ secrets.GH_PASS }}
GL_PASS: ${{ secrets.GL_PASS }}
BB_PASS: ${{ secrets.BB_PASS }}

build-windows-33:
name: Python 3.3.5 on windows-2019 ${{ matrix.arch }}
runs-on: windows-2019
strategy:
matrix:
arch:
- 'x86'
- 'x64'
steps:
- uses: actions/checkout@master

- name: Cache Python
id: cache-python
uses: actions/cache@v2
with:
path: ~/AppData/Local/Python3.3-${{ matrix.arch }}
key: windows-2019-python-3.3-${{ matrix.arch }}

- name: Install Python 3.3.5
run: python dev/python-install.py 3.3 ${{ matrix.arch }} | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Install dependencies
run: python dev/deps.py
- name: Run linter
run: python dev/lint.py
- name: Run tests
run: python dev/tests.py
env:
GH_PASS: ${{ secrets.GH_PASS }}
GL_PASS: ${{ secrets.GL_PASS }}
BB_PASS: ${{ secrets.BB_PASS }}
1 change: 1 addition & 0 deletions dev/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def run():
A bool - if flake8 did not find any errors
"""

print('Python %s' % sys.version)
print('Running flake8 %s' % flake8.__version__)

flake8_style = get_style_guide(config_file=os.path.join(PACKAGE_ROOT, 'tox.ini'))
Expand Down
97 changes: 97 additions & 0 deletions dev/pyenv-install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# coding: utf-8
from __future__ import unicode_literals, division, absolute_import, print_function

import os
import subprocess
import sys


def run(version=None):
"""
Installs a version of Python on Mac using pyenv
:return:
A bool - if Python was installed successfully
"""

if sys.platform == 'win32':
raise ValueError('pyenv-install is not designed for Windows')

if version not in set(['3.3']):
raise ValueError('Invalid version: %r' % version)

python_path = os.path.expanduser('~/.pyenv/versions/%s/bin' % version)
if os.path.exists(os.path.join(python_path, 'python')):
print(python_path)
return True

stdout = ""
stderr = ""

proc = subprocess.Popen(
'command -v pyenv',
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
proc.communicate()
if proc.returncode != 0:
proc = subprocess.Popen(
['brew', 'install', 'pyenv'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
so, se = proc.communicate()
stdout += so.decode('utf-8')
stderr += se.decode('utf-8')
if proc.returncode != 0:
print(stdout)
print(stderr, file=sys.stderr)
return False

pyenv_script = './%s' % version
try:
with open(pyenv_script, 'wb') as f:
if version == '3.3':
contents = '#require_gcc\n' \
'install_package "openssl-1.0.2k" "https://www.openssl.org/source/old/1.0.2/openssl-1.0.2k.tar.gz' \
'#6b3977c61f2aedf0f96367dcfb5c6e578cf37e7b8d913b4ecb6643c3cb88d8c0" mac_openssl\n' \
'install_package "readline-8.0" "https://ftpmirror.gnu.org/readline/readline-8.0.tar.gz' \
'#e339f51971478d369f8a053a330a190781acb9864cf4c541060f12078948e461" mac_readline' \
' --if has_broken_mac_readline\n' \
'install_package "Python-3.3.7" "https://www.python.org/ftp/python/3.3.7/Python-3.3.7.tar.xz' \
'#85f60c327501c36bc18c33370c14d472801e6af2f901dafbba056f61685429fe" standard verify_py33'
f.write(contents.encode('utf-8'))

args = ['pyenv', 'install', pyenv_script]
stdin = None
stdin_contents = None
env = os.environ.copy()

proc = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=stdin,
env=env
)
so, se = proc.communicate(stdin_contents)
stdout += so.decode('utf-8')
stderr += se.decode('utf-8')

if proc.returncode != 0:
print(stdout)
print(stderr, file=sys.stderr)
return False

finally:
if os.path.exists(pyenv_script):
os.unlink(pyenv_script)

print(python_path)
return True


if __name__ == "__main__":
result = run(sys.argv[1])
sys.exit(int(not result))
70 changes: 70 additions & 0 deletions dev/python-install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# coding: utf-8
from __future__ import unicode_literals, division, absolute_import, print_function

import os
import shutil
import subprocess
import sys
from urllib.parse import urlparse
from urllib.request import urlopen


def run(version=None, arch=None):
"""
Installs a version of Python on Windows
:return:
A bool - if Python was installed successfully
"""

if sys.platform != 'win32':
raise ValueError('python-install is only designed for Windows')

if version not in set(['2.6', '3.3']):
raise ValueError('Invalid version: %r' % version)

if arch not in set(['x86', 'x64']):
raise ValueError('Invalid arch: %r' % arch)

if version == '2.6':
if arch == 'x64':
url = 'https://www.python.org/ftp/python/2.6.6/python-2.6.6.amd64.msi'
else:
url = 'https://www.python.org/ftp/python/2.6.6/python-2.6.6.msi'
else:
if arch == 'x64':
url = 'https://www.python.org/ftp/python/3.3.5/python-3.3.5.amd64.msi'
else:
url = 'https://www.python.org/ftp/python/3.3.5/python-3.3.5.msi'

home = os.environ.get('USERPROFILE')
msi_filename = os.path.basename(urlparse(url).path)
msi_path = os.path.join(home, msi_filename)
install_path = os.path.join(os.environ.get('LOCALAPPDATA'), 'Python%s-%s' % (version, arch))

if os.path.exists(os.path.join(install_path, 'python.exe')):
print(install_path)
return True

try:
with urlopen(url) as r, open(msi_path, 'wb') as f:
shutil.copyfileobj(r, f)

proc = subprocess.Popen(
'msiexec /passive /a %s TARGETDIR=%s' % (msi_filename, install_path),
shell=True,
cwd=home
)
proc.communicate()

finally:
if os.path.exists(msi_path):
os.unlink(msi_path)

print(install_path)
return True


if __name__ == "__main__":
result = run(sys.argv[1], sys.argv[2])
sys.exit(int(not result))
1 change: 1 addition & 0 deletions dev/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def run(matcher=None):
A bool - if tests did not find any errors
"""

print('Python %s' % sys.version)
print('Running tests')

loader = unittest.TestLoader()
Expand Down

0 comments on commit 2ea8653

Please sign in to comment.