Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new python versions to tox #366

Merged
merged 10 commits into from
Dec 13, 2021
Merged
54 changes: 28 additions & 26 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
name: CI
on: [pull_request, push]
jobs:
#################### Linters and checkers ####################
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2.3.4
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/setup-python@v2.2.1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install --upgrade pip setuptools wheel tox tox-docker
- name: Run flake8
run: tox -v -e py-flake8 -- -v
- name: Run pydocstyle
run: tox -v -e py-pydocstyle -- -v
- name: Run apicheck
run: tox -v -e py-apicheck -- -v

#################### Unittests ####################
unittest:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6,3.7,3.8,pypy3]
python-version: [3.6,3.7,3.8,3.9,pypy3]
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2.3.4
Expand All @@ -44,11 +22,11 @@ jobs:
run: tox -v -e ${{ matrix.python-version }}-unit -- -v
#################### Integration tests ####################
integration:
needs: [lint, unittest]
needs: [unittest]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6,3.7,3.8,pypy3]
python-version: [3.6,3.7,3.8,3.9,pypy3]
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2.3.4
Expand All @@ -68,3 +46,27 @@ jobs:
CELERY_ENABLE_SPEEDUPS=1 python setup.py develop
tox -v -e ${{ matrix.python-version }}-integration-rabbitmq -- -v
if: ${{ matrix.python-version != 'pypy3'}}

#################### Linters and checkers ####################
lint:
needs: [unittest, integration]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2.3.4
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/setup-python@v2.2.1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install --upgrade pip setuptools wheel tox tox-docker
- name: Run flake8
run: tox -v -e py-flake8 -- -v
- name: Run pydocstyle
run: tox -v -e py-pydocstyle -- -v
- name: Run apicheck
run: tox -v -e py-apicheck -- -v
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '16 4 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
20 changes: 20 additions & 0 deletions .github/workflows/tidelift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

name: Tidelift Alignment
on:
push:
schedule:
- cron: '0 0 * * *' # every day at midnight

jobs:
build:
name: Run Tidelift to ensure approved open source packages are in use
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Alignment
uses: tidelift/alignment-action@main
env:
TIDELIFT_API_KEY: ${{ secrets.TIDELIFT_API_KEY }}
TIDELIFT_ORGANIZATION: ${{ secrets.TIDELIFT_ORGANIZATION }}
TIDELIFT_PROJECT: ${{ secrets.TIDELIFT_PROJECT }}
32 changes: 14 additions & 18 deletions amqp/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,24 +466,20 @@ def connected(self):
return self._transport and self._transport.connected

def collect(self):
try:
if self._transport:
self._transport.close()

if self.channels:
# Copy all the channels except self since the channels
# dictionary changes during the collection process.
channels = [
ch for ch in self.channels.values()
if ch is not self
]

for ch in channels:
ch.collect()
except OSError:
pass # connection already closed on the other end
finally:
self._transport = self.connection = self.channels = None
if self._transport:
self._transport.close()

if self.channels:
# Copy all the channels except self since the channels
# dictionary changes during the collection process.
channels = [
ch for ch in self.channels.values()
if ch is not self
]

for ch in channels:
ch.collect()
self._transport = self.connection = self.channels = None

def _get_free_channel_id(self):
try:
Expand Down
11 changes: 7 additions & 4 deletions amqp/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ def close(self):
# Call shutdown first to make sure that pending messages
# reach the AMQP broker if the program exits after
# calling this method.
self.sock.shutdown(socket.SHUT_RDWR)
try:
self.sock.shutdown(socket.SHUT_RDWR)
except OSError:
pass
self.sock.close()
self.sock = None
self.connected = False
Expand Down Expand Up @@ -525,8 +528,8 @@ def _wrap_socket_sni(self, sock, keyfile=None, certfile=None,
context.load_verify_locations(ca_certs)
if ciphers is not None:
context.set_ciphers(ciphers)
# Set SNI headers if supported.
# Must set context.check_hostname before setting context.verify_mode
# Set SNI headers if supported.
# Must set context.check_hostname before setting context.verify_mode
# to avoid setting context.verify_mode=ssl.CERT_NONE while
# context.check_hostname is still True (the default value in context
# if client-side) which results in the following exception:
Expand All @@ -539,7 +542,7 @@ def _wrap_socket_sni(self, sock, keyfile=None, certfile=None,
except AttributeError:
pass # ask forgiveness not permission

# See note above re: ordering for context.check_hostname and
# See note above re: ordering for context.check_hostname and
# context.verify_mode assignments.
if cert_reqs is not None:
context.verify_mode = cert_reqs
Expand Down
1 change: 0 additions & 1 deletion requirements/test-ci.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pytest-cov
codecov
pytest-travis-fold
pytest-xdist
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
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
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
License :: OSI Approved :: BSD License
Expand Down
13 changes: 10 additions & 3 deletions t/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,17 @@ def test_collect(self):
channel.collect.assert_called_with()
assert self.conn._transport is None

def test_collect__channel_raises_socket_error(self):
self.conn.channels = self.conn.channels = {1: Mock(name='c1')}
self.conn.channels[1].collect.side_effect = socket.error()
def test_collect__transport_socket_raises_os_error(self):
self.conn.transport = TCPTransport('localhost:5672')
sock = self.conn.transport.sock = Mock(name='sock')
channel = Mock(name='c1')
self.conn.channels = {1: channel}
sock.shutdown.side_effect = OSError
self.conn.collect()
channel.collect.assert_called_with()
sock.close.assert_called_with()
assert self.conn._transport is None
assert self.conn.channels is None

def test_collect_no_transport(self):
self.conn = Connection()
Expand Down
11 changes: 9 additions & 2 deletions t/unit/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ def test_close(self):
self.t.close()
assert self.t.sock is None and self.t.connected is False

def test_close_os_error(self):
sock = self.t.sock = Mock()
sock.shutdown.side_effect = OSError
self.t.close()
sock.close.assert_called_with()
assert self.t.sock is None and self.t.connected is False

def test_read_frame__timeout(self):
self.t._read = Mock()
self.t._read.side_effect = socket.timeout()
Expand Down Expand Up @@ -719,7 +726,7 @@ def test_wrap_socket_sni_cert_reqs(self):
)
assert context.verify_mode == sentinel.CERT_REQS

# testing context creation inside _wrap_socket_sni() with parameter
# testing context creation inside _wrap_socket_sni() with parameter
# cert_reqs == ssl.CERT_NONE. Previously raised ValueError because
# code path attempted to set context.verify_mode=ssl.CERT_NONE before
# setting context.check_hostname = False which raised a ValueError
Expand All @@ -740,7 +747,7 @@ def test_wrap_socket_sni_cert_reqs(self):
)
mock_load_default_certs.assert_not_called()
mock_wrap_socket.assert_called_once()

with patch('ssl.SSLContext.wrap_socket') as mock_wrap_socket:
with patch('ssl.SSLContext.load_default_certs') as mock_load_default_certs:
sock = Mock()
Expand Down
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist =
{pypy3,3.6,3.7,3.8}-unit
{pypy3,3.6,3.7,3.8}-integration-rabbitmq
{pypy3,3.6,3.7,3.8,3.9,3.10}-unit
{pypy3,3.6,3.7,3.8,3.9.3.10}-integration-rabbitmq
flake8
flakeplus
apicheck
Expand All @@ -27,6 +27,8 @@ basepython =
3.6: python3.6
3.7: python3.7
3.8: python3.8
3.9: python3.9
3.10: python3.10
install_command = python -m pip --disable-pip-version-check install {opts} {packages}
commands_pre =
integration-rabbitmq: ./wait_for_rabbitmq.sh
Expand Down