Skip to content

Commit

Permalink
Merge branch 'master' into issue-228
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Aug 23, 2023
2 parents 745a2f7 + db15926 commit 0b28668
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 65 deletions.
128 changes: 106 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:
name: Python ${{ matrix.python }} on windows-2019 ${{ matrix.arch }}
runs-on: windows-2019
strategy:
fail-fast: false
matrix:
python:
- '2.7'
- '3.9'
- '3.11'
# - 'pypy-3.7-v7.3.5'
arch:
- 'x86'
Expand All @@ -34,9 +34,11 @@ jobs:
name: Python ${{ matrix.python }} on windows-2019 ${{ matrix.arch }}
runs-on: windows-2019
strategy:
fail-fast: false
matrix:
python:
- '2.6'
- '2.7'
- '3.3'
arch:
- 'x86'
Expand All @@ -62,14 +64,39 @@ 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:
fail-fast: false
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:
fail-fast: false
matrix:
python:
- '3.7'
- '3.11'
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v2
Expand All @@ -84,19 +111,21 @@ 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:
fail-fast: false
matrix:
python:
- '2.6'
- '2.7'
- '3.3'
env:
PYTHONIOENCODING: 'utf-8:surrogateescape'
steps:
- uses: actions/checkout@master

Expand All @@ -105,7 +134,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,16 +150,40 @@ 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:
fail-fast: false
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:
fail-fast: false
matrix:
python:
- '3.9'
- '3.10'
- '3.11'
- 'pypy-3.7-v7.3.5'
steps:
- uses: actions/checkout@master
Expand All @@ -143,23 +196,54 @@ 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:
fail-fast: false
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
79 changes: 74 additions & 5 deletions dev/_import.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,66 @@
# 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


if sys.version_info >= (3, 5):
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
)

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 +82,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
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: 2 additions & 4 deletions dev/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cgi
import codecs
import coverage
import imp
import json
import os
import unittest
Expand All @@ -17,6 +16,7 @@
from fnmatch import fnmatch

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

if sys.version_info < (3,):
str_cls = unicode # noqa
Expand Down Expand Up @@ -103,9 +103,7 @@ def _load_package_tests(name):
if not os.path.exists(package_dir):
return []

tests_module_info = imp.find_module('tests', [package_dir])
tests_module = imp.load_module('%s.tests' % name, *tests_module_info)
return tests_module.test_classes()
return _import_from('%s_tests' % name, package_dir, 'tests').test_classes()


def _env_info():
Expand Down
Loading

0 comments on commit 0b28668

Please sign in to comment.