From 0e2eca28a9d40935dfa9d7d2ab53d447dcb32b51 Mon Sep 17 00:00:00 2001 From: Wes Okes Date: Tue, 24 Jan 2023 14:37:59 -0500 Subject: [PATCH 1/8] github actions --- .github/workflows/tests.yml | 85 +++++++++++++++++++++++++++ .travis.yml | 40 ------------- MANIFEST.in | 1 + data_schema/docs/release_notes.rst | 6 ++ data_schema/version.py | 2 +- requirements/requirements-testing.txt | 13 ++-- requirements/requirements.txt | 4 ++ settings.py | 23 ++++---- setup.py | 31 +++++----- tox.ini | 25 -------- 10 files changed, 134 insertions(+), 96 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml create mode 100644 requirements/requirements.txt delete mode 100644 tox.ini diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..1a76113 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,85 @@ +# copied from django-cte +name: data_schema tests +on: + push: + branches: [master] + pull_request: + branches: [master,develop] + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python: ['3.7'] + python: ['3.7', '3.8', '3.9'] + # Time to switch to pytest or nose2?? + # nosetests is broken on 3.10 + # AttributeError: module 'collections' has no attribute 'Callable' + # https://github.com/nose-devs/nose/issues/1099 + django: + - 'Django~=2.2.0' +# - 'Django~=3.0.0' +# - 'Django~=3.1.0' +# - 'Django~=3.2.0' +# - 'Django~=4.0.0' +# - 'Django~=4.1.0' + experimental: [false] +# include: +# - python: '3.9' +# django: 'https://github.com/django/django/archive/refs/heads/main.zip#egg=Django' +# experimental: true +# # NOTE this job will appear to pass even when it fails because of +# # `continue-on-error: true`. Github Actions apparently does not +# # have this feature, similar to Travis' allow-failure, yet. +# # https://github.com/actions/toolkit/issues/399 + exclude: + - python: '3.7' + django: 'Django~=4.0.0' + - python: '3.7' + django: 'Django~=4.1.0' + services: + postgres: + image: postgres:latest + env: + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Setup + run: | + python --version + pip install --upgrade pip wheel + pip install -r requirements/requirements.txt + pip install -r requirements/requirements-testing.txt + pip install "${{ matrix.django }}" + pip freeze + - name: Run tests + env: + DB_SETTINGS: >- + { + "ENGINE":"django.db.backends.postgresql_psycopg2", + "NAME":"data_schema", + "USER":"postgres", + "PASSWORD":"postgres", + "HOST":"localhost", + "PORT":"5432" + } + run: | + coverage run manage.py test data_schema + coverage report --fail-under=99 + continue-on-error: ${{ matrix.experimental }} + - name: Check style + run: flake8 data_schema diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c900606..0000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -dist: xenial -language: python -sudo: false - -python: - - "3.6" - - "3.7" - -env: - matrix: - - DJANGO=2.2 - - DJANGO=master - -addons: - postgresql: '9.6' - -matrix: - exclude: - - { python: "3.7", env: DJANGO=2.0 } - - include: - - { python: "3.6", env: TOXENV=flake8 } - - allow_failures: - - env: DJANGO=master - -install: - - pip install tox-travis - -before_script: - - psql -c 'CREATE DATABASE data_schema;' -U postgres - -script: - - tox - -after_success: - coveralls - -notifications: - email: false diff --git a/MANIFEST.in b/MANIFEST.in index 04f196a..34ea49d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include README.md include LICENSE +recursive-include requirements * diff --git a/data_schema/docs/release_notes.rst b/data_schema/docs/release_notes.rst index 163ef5f..96e7c9f 100644 --- a/data_schema/docs/release_notes.rst +++ b/data_schema/docs/release_notes.rst @@ -1,5 +1,11 @@ Release Notes +v2.0.0 +------ +* drop python 3.6 +* python 3.8, 3.9 +* django 3.0, 3.1, 3.2, 4.0, 4.1 + v1.5.0 ------ * Update display_name field on FieldSchema to no longer have a char limit. diff --git a/data_schema/version.py b/data_schema/version.py index 77f1c8e..afced14 100644 --- a/data_schema/version.py +++ b/data_schema/version.py @@ -1 +1 @@ -__version__ = '1.5.0' +__version__ = '2.0.0' diff --git a/requirements/requirements-testing.txt b/requirements/requirements-testing.txt index 48603f6..bea6921 100644 --- a/requirements/requirements-testing.txt +++ b/requirements/requirements-testing.txt @@ -1,6 +1,7 @@ -coverage<=5.5 -coveralls<=3.0.1 -django-dynamic-fixture<=3.1.1 -django-nose<=1.4.7 -mock<=4.0.3 -psycopg2<=2.8.6 +coverage +#coveralls +django-dynamic-fixture +django-nose +mock +psycopg2 +flake8 diff --git a/requirements/requirements.txt b/requirements/requirements.txt new file mode 100644 index 0000000..b7f6885 --- /dev/null +++ b/requirements/requirements.txt @@ -0,0 +1,4 @@ +Django>=2.2 +django-manager-utils>=1.4.0 +fleming>=0.5.0 +python-dateutil>=2.2 diff --git a/settings.py b/settings.py index 367fe67..5b97952 100644 --- a/settings.py +++ b/settings.py @@ -1,4 +1,5 @@ import os +import json from django.conf import settings @@ -12,28 +13,30 @@ def configure_settings(): test_db = os.environ.get('DB', None) if test_db is None: db_config = { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'ambition_dev', + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'db_mutex', 'USER': 'postgres', 'PASSWORD': '', - 'HOST': 'db' + 'HOST': 'db', } elif test_db == 'postgres': db_config = { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'db_mutex', 'USER': 'postgres', - 'NAME': 'data_schema', - } - elif test_db == 'sqlite': - db_config = { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'data_schema', + 'PASSWORD': '', + 'HOST': 'db', } else: raise RuntimeError('Unsupported test DB {0}'.format(test_db)) + # Check env for db override (used for github actions) + if os.environ.get('DB_SETTINGS'): + db_config = json.loads(os.environ.get('DB_SETTINGS')) + settings.configure( TEST_RUNNER='django_nose.NoseTestSuiteRunner', + SECRET_KEY='*', NOSE_ARGS=['--nocapture', '--nologcapture', '--verbosity=1'], DATABASES={ 'default': db_config, diff --git a/setup.py b/setup.py index 07f1668..1eab4ba 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,14 @@ def get_version(): raise RuntimeError('Unable to find version string in {0}.'.format(VERSION_FILE)) +def get_lines(file_path): + return open(file_path, 'r').read().split('\n') + + +install_requires = get_lines('requirements/requirements.txt') +tests_require = get_lines('requirements/requirements-testing.txt') + + setup( name='django-data-schema', version=get_version(), @@ -30,28 +38,23 @@ def get_version(): packages=find_packages(), classifiers=[ 'Programming Language :: Python', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Framework :: Django', 'Framework :: Django :: 2.2', + 'Framework :: Django :: 3.0', + 'Framework :: Django :: 3.1', + 'Framework :: Django :: 3.2', + 'Framework :: Django :: 4.0', + 'Framework :: Django :: 4.1', ], license='MIT', - install_requires=[ - 'Django<4.0', - 'django-manager-utils>=1.4.0', - 'fleming>=0.5.0', - 'python-dateutil>=2.2', - ], - tests_require=[ - 'Django<4.0', - 'django-dynamic-fixture', - 'psycopg2', - 'django-nose', - 'mock', - ], + install_requires=install_requires, + tests_require=tests_require, test_suite='run_tests.run_tests', include_package_data=True, ) diff --git a/tox.ini b/tox.ini deleted file mode 100644 index c5d578e..0000000 --- a/tox.ini +++ /dev/null @@ -1,25 +0,0 @@ -[tox] -envlist = - flake8 - py{36,37}-django22 - py{36,37}-djangomaster - -[testenv] -setenv = - DB = postgres -deps = - django22: Django>=2.2,<3.0 - djangomaster: https://github.com/django/django/archive/master.tar.gz - -rrequirements/requirements-testing.txt -commands = - coverage run setup.py test - coverage report --fail-under=100 - -[testenv:flake8] -deps = flake8 -commands = flake8 data_schema - -[travis:env] -DJANGO = - 2.2: django22 - master: djangomaster From 081f18e72653124dfcfcb6fa043813dfde1a471b Mon Sep 17 00:00:00 2001 From: Wes Okes Date: Tue, 24 Jan 2023 14:38:44 -0500 Subject: [PATCH 2/8] fix test file --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1a76113..17b9230 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - python: ['3.7'] +# python: ['3.7'] python: ['3.7', '3.8', '3.9'] # Time to switch to pytest or nose2?? # nosetests is broken on 3.10 From a38c9d90712707d978e7b0b7c6213f55cecc2a7c Mon Sep 17 00:00:00 2001 From: Wes Okes Date: Tue, 24 Jan 2023 14:43:36 -0500 Subject: [PATCH 3/8] only 3.7 --- .github/workflows/tests.yml | 4 ++-- settings.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 17b9230..0834eaf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,8 +12,8 @@ jobs: strategy: fail-fast: false matrix: -# python: ['3.7'] - python: ['3.7', '3.8', '3.9'] + python: ['3.7'] +# python: ['3.7', '3.8', '3.9'] # Time to switch to pytest or nose2?? # nosetests is broken on 3.10 # AttributeError: module 'collections' has no attribute 'Callable' diff --git a/settings.py b/settings.py index 5b97952..6962947 100644 --- a/settings.py +++ b/settings.py @@ -36,7 +36,6 @@ def configure_settings(): settings.configure( TEST_RUNNER='django_nose.NoseTestSuiteRunner', - SECRET_KEY='*', NOSE_ARGS=['--nocapture', '--nologcapture', '--verbosity=1'], DATABASES={ 'default': db_config, From f63e7784e36182a39effbec7e37f047e59fad8ad Mon Sep 17 00:00:00 2001 From: Wes Okes Date: Tue, 24 Jan 2023 14:45:01 -0500 Subject: [PATCH 4/8] fix db name --- settings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/settings.py b/settings.py index 6962947..3501ef3 100644 --- a/settings.py +++ b/settings.py @@ -14,7 +14,7 @@ def configure_settings(): if test_db is None: db_config = { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'db_mutex', + 'NAME': 'data_schema', 'USER': 'postgres', 'PASSWORD': '', 'HOST': 'db', @@ -22,10 +22,10 @@ def configure_settings(): elif test_db == 'postgres': db_config = { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'db_mutex', + 'NAME': 'data_schema', 'USER': 'postgres', 'PASSWORD': '', - 'HOST': 'db', + 'HOST': 'db', } else: raise RuntimeError('Unsupported test DB {0}'.format(test_db)) From 0efb4be38cf26a8abf35f8eeeb8b99dff6889fb4 Mon Sep 17 00:00:00 2001 From: Wes Okes Date: Tue, 24 Jan 2023 14:47:14 -0500 Subject: [PATCH 5/8] fix typo of set_spec to spec_set --- data_schema/tests/tests.py | 20 ++++++++++---------- settings.py | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data_schema/tests/tests.py b/data_schema/tests/tests.py index 6f9badf..24a3625 100644 --- a/data_schema/tests/tests.py +++ b/data_schema/tests/tests.py @@ -368,7 +368,7 @@ def test_set_value_dict(self): data_schema.set_value(val, 'field_key', 'value') self.assertEquals(val['field_key'], 'value') - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_dict(self, convert_value_mock): """ Tests getting the value of a field when the object is a dictionary. @@ -395,7 +395,7 @@ def test_get_value_dict_cached(self): value = data_schema.get_value(obj, 'field_key') self.assertEquals(value, 'none') - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_obj(self, convert_value_mock): """ Tests the get_value function with an object as input. @@ -410,7 +410,7 @@ class Input: data_schema.get_value(Input(), 'field_key') convert_value_mock.assert_called_once_with(FieldSchemaType.STRING, 'value', 'format', None, None) - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_list(self, convert_value_mock): """ Tests the get_value function with a list as input. @@ -456,7 +456,7 @@ def test_set_value_dict(self): field_schema.set_value(val, 'value') self.assertEquals(val['field_key'], 'value') - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_dict(self, convert_value_mock): """ Tests getting the value of a field when the object is a dictionary. @@ -465,7 +465,7 @@ def test_get_value_dict(self, convert_value_mock): field_schema.get_value({'field_key': 'hello'}) convert_value_mock.assert_called_once_with(FieldSchemaType.STRING, 'hello', None, None, None) - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_obj(self, convert_value_mock): """ Tests the get_value function with an object as input. @@ -477,7 +477,7 @@ class Input: field_schema.get_value(Input()) convert_value_mock.assert_called_once_with(FieldSchemaType.STRING, 'value', 'format', None, None) - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_list(self, convert_value_mock): """ Tests the get_value function with a list as input. @@ -486,7 +486,7 @@ def test_get_value_list(self, convert_value_mock): field_schema.get_value(['hello', 'world']) convert_value_mock.assert_called_once_with(FieldSchemaType.STRING, 'world', None, None, None) - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_dict_non_extant(self, convert_value_mock): """ Tests getting the value of a field when the object is a dictionary and it doesn't exist in the dict. @@ -495,7 +495,7 @@ def test_get_value_dict_non_extant(self, convert_value_mock): field_schema.get_value({'field_key': 'hello'}) convert_value_mock.assert_called_once_with(FieldSchemaType.STRING, None, None, None, None) - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_obj_non_extant(self, convert_value_mock): """ Tests the get_value function with an object as input and the field key is not in the object. @@ -508,7 +508,7 @@ class Input: field_schema.get_value(Input()) convert_value_mock.assert_called_once_with(FieldSchemaType.STRING, None, 'format', None, None) - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_list_non_extant_negative(self, convert_value_mock): """ Tests the get_value function with a list as input and the input position is negative. @@ -517,7 +517,7 @@ def test_get_value_list_non_extant_negative(self, convert_value_mock): field_schema.get_value(['hello', 'world']) convert_value_mock.assert_called_once_with(FieldSchemaType.STRING, None, None, None, None) - @patch('data_schema.models.convert_value', set_spec=True) + @patch('data_schema.models.convert_value', spec_set=True) def test_get_value_list_non_extant_out_of_range(self, convert_value_mock): """ Tests the get_value function with a list as input and the input position is greater than the diff --git a/settings.py b/settings.py index 3501ef3..e3e72e5 100644 --- a/settings.py +++ b/settings.py @@ -25,7 +25,7 @@ def configure_settings(): 'NAME': 'data_schema', 'USER': 'postgres', 'PASSWORD': '', - 'HOST': 'db', + 'HOST': 'db', } else: raise RuntimeError('Unsupported test DB {0}'.format(test_db)) From 3ad5708e2f7e821cf986952fdffadecbeaafc0bf Mon Sep 17 00:00:00 2001 From: Wes Okes Date: Tue, 24 Jan 2023 14:49:54 -0500 Subject: [PATCH 6/8] more versions --- .github/workflows/tests.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0834eaf..3f22441 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,19 +12,18 @@ jobs: strategy: fail-fast: false matrix: - python: ['3.7'] -# python: ['3.7', '3.8', '3.9'] + python: ['3.7', '3.8', '3.9'] # Time to switch to pytest or nose2?? # nosetests is broken on 3.10 # AttributeError: module 'collections' has no attribute 'Callable' # https://github.com/nose-devs/nose/issues/1099 django: - 'Django~=2.2.0' -# - 'Django~=3.0.0' -# - 'Django~=3.1.0' -# - 'Django~=3.2.0' -# - 'Django~=4.0.0' -# - 'Django~=4.1.0' + - 'Django~=3.0.0' + - 'Django~=3.1.0' + - 'Django~=3.2.0' + - 'Django~=4.0.0' + - 'Django~=4.1.0' experimental: [false] # include: # - python: '3.9' From 960d0e01d7cd129826ee284585d10e335380fb49 Mon Sep 17 00:00:00 2001 From: Wes Okes Date: Tue, 24 Jan 2023 14:50:02 -0500 Subject: [PATCH 7/8] more versions --- .github/workflows/tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3f22441..2ccf49a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,11 +19,11 @@ jobs: # https://github.com/nose-devs/nose/issues/1099 django: - 'Django~=2.2.0' - - 'Django~=3.0.0' - - 'Django~=3.1.0' - - 'Django~=3.2.0' - - 'Django~=4.0.0' - - 'Django~=4.1.0' + - 'Django~=3.0.0' + - 'Django~=3.1.0' + - 'Django~=3.2.0' + - 'Django~=4.0.0' + - 'Django~=4.1.0' experimental: [false] # include: # - python: '3.9' From f8850a03791fd08635475fe54e509755b6af45da Mon Sep 17 00:00:00 2001 From: Wes Okes Date: Tue, 24 Jan 2023 14:51:59 -0500 Subject: [PATCH 8/8] fix formatting --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2ccf49a..7c8b27f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,7 +18,7 @@ jobs: # AttributeError: module 'collections' has no attribute 'Callable' # https://github.com/nose-devs/nose/issues/1099 django: - - 'Django~=2.2.0' + - 'Django~=2.2.0' - 'Django~=3.0.0' - 'Django~=3.1.0' - 'Django~=3.2.0'