Skip to content

Commit

Permalink
Update CI config and dev tools
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Aug 22, 2023
1 parent 87b5268 commit 054886a
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 68 deletions.
121 changes: 99 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ jobs:
strategy:
matrix:
python:
- '2.7'
- '3.9'
- '3.11'
# - 'pypy-3.7-v7.3.5'
arch:
- 'x86'
Expand Down Expand Up @@ -37,6 +36,7 @@ jobs:
matrix:
python:
- '2.6'
- '2.7'
- '3.3'
arch:
- 'x86'
Expand All @@ -62,14 +62,37 @@ jobs:
run: python run.py ci-driver winlegacy

build-mac:
name: Python ${{ matrix.python }} on macos-10.15
runs-on: macos-10.15
name: Python ${{ matrix.python }} on macos-13
runs-on: macos-13
strategy:
matrix:
python:
- '2.7'
- '3.9'
# - 'pypy-3.7-v7.3.5'
- '3.11'
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
architecture: x64
- name: Install dependencies
run: python run.py deps
- name: Run test suite
run: python run.py ci-driver
- name: Run test suite (Mac cffi)
run: python run.py ci-driver cffi
- name: Run test suite (Mac OpenSSL)
run: python run.py ci-driver openssl
- name: Run test suite (Mac OpenSSL/cffi)
run: python run.py ci-driver cffi openssl

build-mac-legacy:
name: Python ${{ matrix.python }} on macos-11
runs-on: macos-11
strategy:
matrix:
python:
- '3.7'
- '3.11'
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v2
Expand All @@ -84,19 +107,20 @@ jobs:
run: python run.py ci-driver cffi
- name: Run test suite (Mac OpenSSL)
run: python run.py ci-driver openssl
if: ${{ matrix.python }} != 'pypy-3.7-v7.3.5'
- name: Run test suite (Mac OpenSSL/cffi)
run: python run.py ci-driver cffi openssl
if: ${{ matrix.python }} != 'pypy-3.7-v7.3.5'

build-mac-old:
name: Python ${{ matrix.python }} on macos-10.15
runs-on: macos-10.15
name: Python ${{ matrix.python }} on macos-11
runs-on: macos-11
strategy:
matrix:
python:
- '2.6'
- '2.7'
- '3.3'
env:
PYTHONIOENCODING: 'utf-8:surrogateescape'
steps:
- uses: actions/checkout@master

Expand All @@ -105,7 +129,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.pyenv
key: macos-10.15-${{ matrix.python }}-pyenv
key: macos-11-${{ matrix.python }}-pyenv

- name: Install Python ${{ matrix.python }}
run: python run.py pyenv-install ${{ matrix.python }} >> $GITHUB_PATH
Expand All @@ -121,15 +145,38 @@ jobs:
- name: Run test suite (Mac OpenSSL/cffi)
run: python run.py ci-driver cffi openssl

build-ubuntu:
name: Python ${{ matrix.python }} on ubuntu-18.04 x64
runs-on: ubuntu-18.04
build-mac-openssl3:
name: Python ${{ matrix.python }} on macos-11 with OpenSSL 3.0
runs-on: macos-11
strategy:
matrix:
python:
- '2.7'
- '3.6'
- '3.11'
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
architecture: x64
- name: Install OpenSSL 3.0
run: brew install openssl@3
- name: Install dependencies
run: python run.py deps
- name: Run test suite (Mac OpenSSL 3.0)
run: python run.py ci-driver openssl3
- name: Run test suite (Mac OpenSSL 3.0/cffi)
run: python run.py ci-driver cffi openssl3

build-ubuntu:
name: Python ${{ matrix.python }} on ubuntu-20.04 x64
runs-on: ubuntu-20.04
strategy:
matrix:
python:
- '3.9'
- '3.10'
- '3.11'
- 'pypy-3.7-v7.3.5'
steps:
- uses: actions/checkout@master
Expand All @@ -142,23 +189,53 @@ jobs:
- name: Run test suite
run: python run.py ci-driver

build-ubuntu-openssl3-py3:
name: Python 3 on (Docker) ubuntu-22.04 x64
runs-on: ubuntu-latest
container: ubuntu:22.04
steps:
- uses: actions/checkout@master
- name: Install Python and OpenSSL
run: DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends python3 python3-setuptools python-is-python3 openssl curl ca-certificates git
- name: Install dependencies
run: python run.py deps
- name: Run test suite
run: python run.py ci-driver
- name: Run test suite (cffi)
run: python run.py ci-driver cffi

build-ubuntu-openssl3-py2:
name: Python 2 on (Docker) ubuntu-22.04 x64
runs-on: ubuntu-latest
container: ubuntu:22.04
steps:
- uses: actions/checkout@master
- name: Install Python and OpenSSL
run: DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends python2 python-setuptools openssl curl ca-certificates git
- name: Install dependencies
run: python2 run.py deps
- name: Run test suite
run: python2 run.py ci-driver
- name: Run test suite (cffi)
run: python2 run.py ci-driver cffi


build-ubuntu-old:
name: Python ${{ matrix.python }} on ubuntu-18.04 x64
runs-on: ubuntu-18.04
name: Python ${{ matrix.python }} on ubuntu-20.04 x64
runs-on: ubuntu-20.04
strategy:
matrix:
python:
- '2.6'
- '3.2'
- '3.3'
- '3.6'
- '3.7'
steps:
- uses: actions/checkout@master
- name: Setup deadsnakes/ppa
run: sudo apt-add-repository ppa:deadsnakes/ppa
- name: Update apt
run: sudo apt-get update
- name: Install Python ${{matrix.python}}
run: sudo apt-get install python${{matrix.python}}
run: sudo apt-get install python${{matrix.python}} python${{matrix.python}}-distutils
- name: Install dependencies
run: python${{matrix.python}} run.py deps
- name: Run test suite
Expand Down
89 changes: 82 additions & 7 deletions dev/_import.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
# coding: utf-8
from __future__ import unicode_literals, division, absolute_import, print_function

import imp
import sys
import os

from . import build_root, package_name, package_root

if sys.version_info < (3, 5):
import imp
else:
import importlib
import importlib.abc
import importlib.util


if sys.version_info < (3,):
getcwd = os.getcwdu
else:
getcwd = os.getcwd


class ModCryptoMetaFinder(importlib.abc.MetaPathFinder):
def setup(self):
self.modules = {}
sys.meta_path.insert(0, self)

def add_module(self, package_name, package_path):
if package_name not in self.modules:
self.modules[package_name] = package_path

def find_spec(self, fullname, path, target=None):
name_parts = fullname.split('.')
if name_parts[0] not in self.modules:
return None

package = name_parts[0]
package_path = self.modules[package]

fullpath = os.path.join(package_path, *name_parts[1:])

if os.path.isdir(fullpath):
filename = os.path.join(fullpath, "__init__.py")
submodule_locations = [fullpath]
else:
filename = fullpath + ".py"
submodule_locations = None

if not os.path.exists(filename):
return None

return importlib.util.spec_from_file_location(
fullname,
filename,
loader=None,
submodule_search_locations=submodule_locations
)


if sys.version_info >= (3, 5):
CUSTOM_FINDER = ModCryptoMetaFinder()
CUSTOM_FINDER.setup()


def _import_from(mod, path, mod_dir=None, allow_error=False):
"""
Imports a module from a specific path
Expand All @@ -34,23 +83,44 @@ def _import_from(mod, path, mod_dir=None, allow_error=False):
None if not loaded, otherwise the module
"""

if mod in sys.modules:
return sys.modules[mod]

if mod_dir is None:
full_mod = mod
else:
full_mod = mod_dir.replace(os.sep, '.')

if mod_dir is None:
mod_dir = mod.replace('.', os.sep)

if not os.path.exists(path):
return None

if not os.path.exists(os.path.join(path, mod_dir)) \
and not os.path.exists(os.path.join(path, mod_dir + '.py')):
source_path = os.path.join(path, mod_dir, '__init__.py')
if not os.path.exists(source_path):
source_path = os.path.join(path, mod_dir + '.py')

if not os.path.exists(source_path):
return None

if os.sep in mod_dir:
append, mod_dir = mod_dir.rsplit(os.sep, 1)
path = os.path.join(path, append)

try:
mod_info = imp.find_module(mod_dir, [path])
return imp.load_module(mod, *mod_info)
if sys.version_info < (3, 5):
mod_info = imp.find_module(mod_dir, [path])
return imp.load_module(mod, *mod_info)

else:
package = mod.split('.', 1)[0]
package_dir = full_mod.split('.', 1)[0]
package_path = os.path.join(path, package_dir)
CUSTOM_FINDER.add_module(package, package_path)

return importlib.import_module(mod)

except ImportError:
if allow_error:
raise
Expand Down Expand Up @@ -107,10 +177,15 @@ def _preload(require_oscrypto, print_info):
)
)
if require_oscrypto:
backend = oscrypto.backend()
if backend == 'openssl':
from oscrypto._openssl._libcrypto import libcrypto_version
backend = '%s (%s)' % (backend, libcrypto_version)

print(
'oscrypto: %s backend, %s, %s' % (
oscrypto.backend(),
'oscrypto: %s, %s backend, %s' % (
oscrypto.__version__,
backend,
os.path.dirname(oscrypto.__file__)
)
)
5 changes: 3 additions & 2 deletions dev/_pep425.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ def _pep425tags():
if sys.platform == 'win32':
if 'amd64' in sys.version.lower():
arches = ['win_amd64']
arches = [sys.platform]
else:
arches = [sys.platform]
elif hasattr(os, 'uname'):
(plat, _, _, _, machine) = os.uname()
plat = plat.lower().replace('/', '')
machine.replace(' ', '_').replace('/', '_')
if plat == 'linux' and sys.maxsize == 2147483647:
if plat == 'linux' and sys.maxsize == 2147483647 and 'arm' not in machine:
machine = 'i686'
arch = '%s_%s' % (plat, machine)
if _pep425_supports_manylinux():
Expand Down
6 changes: 3 additions & 3 deletions dev/build.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# coding: utf-8
from __future__ import unicode_literals, division, absolute_import, print_function

import imp
import os
import tarfile
import zipfile

import setuptools.sandbox

from . import package_root, package_name, has_tests_package
from ._import import _import_from


def _list_zip(filename):
Expand Down Expand Up @@ -45,8 +45,8 @@ def run():

# Trying to call setuptools.sandbox.run_setup(setup, ['--version'])
# resulted in a segfault, so we do this instead
module_info = imp.find_module('version', [os.path.join(package_root, package_name)])
version_mod = imp.load_module('%s.version' % package_name, *module_info)
package_dir = os.path.join(package_root, package_name)
version_mod = _import_from('%s.version' % package_name, package_dir, 'version')

pkg_name_info = (package_name, version_mod.__version__)
print('Building %s-%s' % pkg_name_info)
Expand Down
6 changes: 6 additions & 0 deletions dev/ci-driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def run(**_):
else:
_write_env(env, 'OSCRYPTO_USE_OPENSSL', '/usr/lib/libcrypto.35.dylib,/usr/lib/libssl.35.dylib')
newline = True
if 'openssl3' in options and sys.platform == 'darwin':
_write_env(
env,
'OSCRYPTO_USE_OPENSSL',
'/usr/local/opt/openssl@3/lib/libcrypto.dylib,/usr/local/opt/openssl@3/lib/libssl.dylib'
)
if 'winlegacy' in options:
_write_env(env, 'OSCRYPTO_USE_WINLEGACY', 'true')
newline = True
Expand Down
2 changes: 2 additions & 0 deletions dev/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
deps_dir = os.path.join(build_root, 'modularcrypto-deps')
if os.path.exists(deps_dir):
site.addsitedir(deps_dir)
# In case any of the deps are installed system-wide
sys.path.insert(0, deps_dir)

if sys.version_info[0:2] not in [(2, 6), (3, 2)]:
from .lint import run as run_lint
Expand Down
Loading

0 comments on commit 054886a

Please sign in to comment.