Skip to content

Commit

Permalink
Merge pull request #199 from bjester/fix-gh-actions
Browse files Browse the repository at this point in the history
Fix GH action workflows for py2.7 deprecation
  • Loading branch information
rtibbles committed Sep 12, 2023
2 parents 7ed1215 + 8fac257 commit 7320330
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: 3.9
- name: Install dependencies
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/python2-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ jobs:
name: Python 2 syntax checking
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
container:
image: python:2.7.18-buster
steps:
- uses: actions/checkout@v2
- name: Set up Python 2.7
uses: actions/setup-python@v2
with:
python-version: 2.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
138 changes: 103 additions & 35 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,133 @@ jobs:
unit_test:
name: Python unit tests
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
max-parallel: 5
matrix:
python-version: [2.7, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9]

python-version: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: |
python -m pip install --upgrade pip
pip install tox
- name: tox env cache
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.tox/py${{ matrix.python-version }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-${{ hashFiles('setup.py', 'requirements/*.txt') }}
- name: Test with tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: tox -e py${{ matrix.python-version }}
unit_test_deprecated:
name: Python unit tests (deprecated python versions)
needs: pre_job
runs-on: ubuntu-20.04
strategy:
max-parallel: 3
matrix:
python-version: [2.7, 3.4, 3.5]
container:
image: python:${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- name: Install tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: |
python -m pip install --upgrade pip
pip install tox
- name: tox env cache
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.tox/py${{ matrix.python-version }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-${{ hashFiles('setup.py', 'requirements/*.txt') }}
- name: Test with tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: tox -e py${{ matrix.python-version }}
cryptography:
name: Python unit tests + cryptography
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
max-parallel: 5
matrix:
# only crypto 2.3 seems to work
python-version: [ 2.7, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9 ]
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
crypto-version: [ 2.3 ]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
run: |
sudo apt-get -y -qq update
sudo apt-get install -y openssl libssl-dev
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- name: tox env cache
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.tox/py${{ matrix.python-version }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-crypto${{ matrix.crypto-version }}-${{ hashFiles('setup.py', 'requirements/*.txt') }}
- name: Test with tox
run: tox -e py${{ matrix.python-version }}-cryptography${{ matrix.crypto-version }}
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: |
sudo apt-get -y -qq update
sudo apt-get install -y openssl libssl-dev
- name: Install tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: |
python -m pip install --upgrade pip
pip install tox
- name: tox env cache
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.tox/py${{ matrix.python-version }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-crypto${{ matrix.crypto-version }}-${{ hashFiles('setup.py', 'requirements/*.txt') }}
- name: Test with tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: tox -e py${{ matrix.python-version }}-cryptography${{ matrix.crypto-version }}
cryptography_deprecated:
name: Python unit tests (deprecated python versions) + cryptography
needs: pre_job
runs-on: ubuntu-20.04
strategy:
max-parallel: 3
matrix:
# Packages are no longer available for the distribution that comes with the
# python:3.4 image, so we can't install the necessary dependencies. Eventually,
# this will happen to the others as well.
# EOL: [3.4]
python-version: [2.7, 3.5]
container:
image: python:${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- name: Install system dependencies
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: |
apt-get -y -qq update
apt-get install -y openssl libssl-dev
- name: Install tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: |
python -m pip install --upgrade pip
pip install tox
- name: tox env cache
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.tox/py${{ matrix.python-version }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-crypto2.3-${{ hashFiles('setup.py', 'requirements/*.txt') }}
- name: Test with tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: tox -e py${{ matrix.python-version }}-cryptography2.3
postgres:
name: Python postgres unit tests
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
services:
# Label used to access the service container
postgres:
Expand All @@ -101,20 +166,24 @@ jobs:
- 5432:5432
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.5 for Postgres
- name: Set up Python 3.6 for Postgres
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/setup-python@v2
with:
python-version: 3.5
python-version: 3.6
- name: Install tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: |
python -m pip install --upgrade pip
pip install tox
- name: tox env cache
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.tox/py${{ matrix.python-version }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-${{ hashFiles('setup.py', 'requirements/*.txt') }}
path: ${{ github.workspace }}/.tox/py3.6
key: ${{ runner.os }}-tox-py3.6-${{ hashFiles('setup.py', 'requirements/*.txt') }}
- name: Test with tox
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
run: tox -e postgres
windows:
name: Python unit tests on Windows Server
Expand All @@ -124,7 +193,6 @@ jobs:
max-parallel: 5
matrix:
python-version: [3.6]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ venv/
ENV/
.venv
Pipfile
.envrc

# Spyder project settings
.spyderproject
Expand All @@ -97,4 +98,4 @@ Pipfile

*.db

.vscode
.vscode
4 changes: 2 additions & 2 deletions morango/management/commands/cleanupsyncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def handle(self, *args, **options):
if options["sync_filter"]:
transfer_sessions = transfer_sessions.filter(filter__startswith=options["sync_filter"])

if options["push"] == True and not options["pull"]:
if options["push"] and not options["pull"]:
transfer_sessions = transfer_sessions.filter(push=True)

if options["pull"] == True and not options["push"]:
if options["pull"] and not options["push"]:
transfer_sessions = transfer_sessions.filter(push=False)

transfer_count = transfer_sessions.count()
Expand Down
10 changes: 10 additions & 0 deletions tests/testapp/tests/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try:
# In the Python 2.7 GH workflows, we have to install backported version
from backports.test.support import EnvironmentVarGuard # noqa F401
except ImportError:
try:
# For python >2.7 and <3.10
from test.support import EnvironmentVarGuard # noqa F401
except ImportError:
# In Python 3.10, this has been moved to test.support.os_helper
from test.support.os_helper import EnvironmentVarGuard # noqa F401
2 changes: 1 addition & 1 deletion tests/testapp/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
import json
import uuid
from test.support import EnvironmentVarGuard

import factory
import mock
Expand All @@ -18,6 +17,7 @@
from facility_profile.models import MyUser
from facility_profile.models import SummaryLog

from .compat import EnvironmentVarGuard
from morango.api.serializers import BufferSerializer
from morango.models.core import AbstractStore
from morango.models.core import Buffer
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/tests/integration/test_syncsession.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextlib
import json
from test.support import EnvironmentVarGuard

import mock
import pytest
Expand All @@ -12,6 +11,7 @@
from facility_profile.models import SummaryLog
from requests.exceptions import Timeout

from ..compat import EnvironmentVarGuard
from morango.errors import MorangoError
from morango.models.certificates import Certificate
from morango.models.certificates import Filter
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/tests/sync/test_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import contextlib
import json
import uuid
from test.support import EnvironmentVarGuard

import factory
import mock
Expand All @@ -12,6 +11,7 @@
from facility_profile.models import MyUser
from facility_profile.models import SummaryLog

from ..compat import EnvironmentVarGuard
from ..helpers import serialized_facility_factory
from ..helpers import TestSessionContext
from morango.constants import transfer_stages
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import sys
import uuid
from test.support import EnvironmentVarGuard

from django.db import connection
from django.test.utils import CaptureQueriesContext
Expand All @@ -13,6 +12,7 @@
from facility_profile.models import MyUser
from rest_framework.test import APITestCase as BaseTestCase

from .compat import EnvironmentVarGuard
from morango.api.serializers import BufferSerializer
from morango.api.serializers import CertificateSerializer
from morango.api.serializers import InstanceIDSerializer
Expand Down
9 changes: 4 additions & 5 deletions tests/testapp/tests/test_uuid_utilities.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import hashlib
import mock
import sys
import uuid

import mock
from django.test import TestCase
from facility_profile.models import Facility
from facility_profile.models import InteractionLog
from facility_profile.models import MyUser
from test.support import EnvironmentVarGuard

from .compat import EnvironmentVarGuard
from morango.errors import InvalidMorangoSourceId
from morango.models.core import DatabaseIDModel
from morango.models.core import InstanceIDModel
Expand Down Expand Up @@ -157,9 +157,9 @@ def test_consistent_0_5_instance_id(self, *args):
env["MORANGO_SYSTEM_ID"] = "magicsysid"

DatabaseIDModel.objects.all().update(current=False)
database_id = DatabaseIDModel.objects.create(
DatabaseIDModel.objects.create(
id="7fe445b75cea11858c00fb97bdee8878", current=True
).id
)

self.assertEqual(get_0_5_system_id(), "54940f560a55bbf7d86b")
self.assertEqual(get_0_5_mac_address(), "804f4c20d3b2b5a29b95")
Expand Down Expand Up @@ -197,7 +197,6 @@ def test_envvar_overrides(self, *args):

self.assertEqual(instance.id, expected_id)


@mock.patch(
"ifcfg.interfaces",
return_value={"eth0": {"device": "eth0", "ether": "a0:aa:aa:aa:aa"}},
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ basepython =
py3.7: python3.7
py3.8: python3.8
py3.9: python3.9
postgres: python3.5
postgres: python3.6
windows: python3.6

deps =
-r{toxinidir}/requirements/test.txt
cryptography1.2: cryptography==1.2.3
cryptography1.8: cryptography==1.8.2
cryptography2.3: cryptography==2.3.1
py2.7: backports.test.support==0.1.1
py3.4: backports.test.support==0.1.1
py3.5: backports.test.support==0.1.1

commands =
sh -c '! tests/testapp/manage.py makemigrations --dry-run --exit --noinput'
Expand Down

0 comments on commit 7320330

Please sign in to comment.