From 27468e550288e94686c7e42ba080d76e6ab2d8e4 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 10:07:49 -0400 Subject: [PATCH 01/10] Drop python 3.7, add python 3.12 Matching the Python support schedule: https://devguide.python.org/versions/ --- .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 8e42272..e9360c8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v3 From b79297dc3d1c64333e86c438997ee038d1805262 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 10:21:24 -0400 Subject: [PATCH 02/10] Replace flake8 with ruff as the static checker --- Makefile | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9e2e2e8..27d79b3 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ TEST_CMD = ${PYTHON} manage.py test --parallel TEST_WARNINGS_CMD = ${PYTHON} -Wa manage.py test # see .coveragerc for settings COVERAGE_CMD = coverage run manage.py test --noinput && coverage xml && coverage report -STATIC_CMD = flake8 ${PACKAGE_DIR} ${TEST_DIR} ${EXAMPLE_DIR} +STATIC_CMD = ruff . VULN_STATIC_CMD = bandit -r -ii -ll -x ${PACKAGE_DIR}/migrations ${PACKAGE_DIR} FORMAT_CMD = black ${PACKAGE_DIR} ${TEST_DIR} ${EXAMPLE_DIR} FORMATCHECK_CMD = ${FORMAT_CMD} --check diff --git a/pyproject.toml b/pyproject.toml index 9ca2657..324d17a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ dev = [ "ipython~=7.0", "oauth2==1.9.0.post1", "pyyaml~=6.0", + "ruff~=0.1.2", "sphinx_rtd_theme==0.5.2", "tblib~=1.6.0", ] From 2e1d7f79ae59351197ac8d2672eb666fa630c82c Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 10:21:44 -0400 Subject: [PATCH 03/10] Placate ruff --- django_declarative_apis/resources/utils.py | 2 +- docs/source/conf.py | 3 ++- example/manage.py | 2 +- manage.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/django_declarative_apis/resources/utils.py b/django_declarative_apis/resources/utils.py index 98a14f0..3028afe 100644 --- a/django_declarative_apis/resources/utils.py +++ b/django_declarative_apis/resources/utils.py @@ -259,7 +259,7 @@ def wrap(f, self, request, *args, **kwargs): for idx, mime in enumerate(mimes): realmimes.add(rewrite.get(mime, mime)) - if not m.content_type() in realmimes: + if m.content_type() not in realmimes: return rc.BAD_REQUEST return f(self, request, *args, **kwargs) diff --git a/docs/source/conf.py b/docs/source/conf.py index f5f0c47..48f54a0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -25,6 +25,8 @@ # import os import sys +import django + sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) # -- General configuration ------------------------------------------------ @@ -33,7 +35,6 @@ # # needs_sphinx = '1.0' -import django os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' django.setup() diff --git a/example/manage.py b/example/manage.py index 4e15e7d..48d91e1 100755 --- a/example/manage.py +++ b/example/manage.py @@ -18,7 +18,7 @@ # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: - import django + import django # noqa: F401 except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " diff --git a/manage.py b/manage.py index 47b52d5..2bb807f 100755 --- a/manage.py +++ b/manage.py @@ -18,7 +18,7 @@ # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: - import django + import django # noqa: F401 except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " From b79c3c8203ee7e07417dc6c54e4f2378c07b41c6 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 10:23:42 -0400 Subject: [PATCH 04/10] Remove flake8 dependency and config --- .flake8 | 7 ------- pyproject.toml | 1 - 2 files changed, 8 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 991da2f..0000000 --- a/.flake8 +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -max-line-length = 120 -max-complexity = 14 -exclude = - setup.py, - manage.py, - migrations diff --git a/pyproject.toml b/pyproject.toml index 324d17a..dd730f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,6 @@ dev = [ "black==22.3.0", "bumpversion~=0.5", "coverage[toml]==6.3.2", - "flake8==4.0.1", "ipython~=7.0", "oauth2==1.9.0.post1", "pyyaml~=6.0", From dde6c465b9da1d482b4bc4fa6f821e0c92cc88f3 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 10:28:59 -0400 Subject: [PATCH 05/10] Replace black with ruff --- Makefile | 4 ++-- pyproject.toml | 22 ---------------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 27d79b3..59a8632 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,9 @@ TEST_CMD = ${PYTHON} manage.py test --parallel TEST_WARNINGS_CMD = ${PYTHON} -Wa manage.py test # see .coveragerc for settings COVERAGE_CMD = coverage run manage.py test --noinput && coverage xml && coverage report -STATIC_CMD = ruff . +STATIC_CMD = ruff check . VULN_STATIC_CMD = bandit -r -ii -ll -x ${PACKAGE_DIR}/migrations ${PACKAGE_DIR} -FORMAT_CMD = black ${PACKAGE_DIR} ${TEST_DIR} ${EXAMPLE_DIR} +FORMAT_CMD = ruff format . FORMATCHECK_CMD = ${FORMAT_CMD} --check diff --git a/pyproject.toml b/pyproject.toml index dd730f3..e7fe65c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,6 @@ classifiers = [ [project.optional-dependencies] dev = [ "bandit>=1.7.4", - "black==22.3.0", "bumpversion~=0.5", "coverage[toml]==6.3.2", "ipython~=7.0", @@ -47,27 +46,6 @@ dev = [ "tblib~=1.6.0", ] -[tool.black] -line-length = 88 -target_version = ['py39'] -exclude = ''' -^/( - ( - \.eggs # exclude a few common directories in the - | \.git # root of the project - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - )/ - | \.heroku -) -''' - [tool.coverage.run] omit = ["*/tests/*", "*/management/*", "*/migrations/*"] From 30cd7b5b767201a42291e616383c1c7083f63f3a Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 10:30:03 -0400 Subject: [PATCH 06/10] Autoformat with ruff --- .../oauthlib/request_validator.py | 1 - .../machinery/attributes.py | 6 +- .../migrations/0001_initial.py | 1 - .../0002_add_consumer_type_field.py | 1 - django_declarative_apis/resources/resource.py | 1 - docs/source/conf.py | 97 +++++++++++-------- example/myapp/migrations/0001_initial.py | 1 - tests/resources/test_utils.py | 1 - 8 files changed, 58 insertions(+), 51 deletions(-) diff --git a/django_declarative_apis/authentication/oauthlib/request_validator.py b/django_declarative_apis/authentication/oauthlib/request_validator.py index 5a7ed3b..c36a662 100644 --- a/django_declarative_apis/authentication/oauthlib/request_validator.py +++ b/django_declarative_apis/authentication/oauthlib/request_validator.py @@ -18,7 +18,6 @@ class DjangoRequestValidator(RequestValidator): - TIMESTAMP_THRESHOLD = 300 def __init__(self, request, *args, **kwargs): diff --git a/django_declarative_apis/machinery/attributes.py b/django_declarative_apis/machinery/attributes.py index b77712b..d25434a 100644 --- a/django_declarative_apis/machinery/attributes.py +++ b/django_declarative_apis/machinery/attributes.py @@ -659,9 +659,9 @@ def __init__( if execute_unless: assert callable(execute_unless), "execute_unless MUST be callable" - assert inspect.getfullargspec(execute_unless).args == [ - "self" - ], "execute_unless MUST be an instance method that takes only the 'self' argument" + assert ( + inspect.getfullargspec(execute_unless).args == ["self"] + ), "execute_unless MUST be an instance method that takes only the 'self' argument" self.execute_unless = execute_unless diff --git a/django_declarative_apis/migrations/0001_initial.py b/django_declarative_apis/migrations/0001_initial.py index 247f5c3..d2b22b8 100644 --- a/django_declarative_apis/migrations/0001_initial.py +++ b/django_declarative_apis/migrations/0001_initial.py @@ -14,7 +14,6 @@ class Migration(migrations.Migration): - initial = True dependencies = [("contenttypes", "0002_remove_content_type_name")] diff --git a/django_declarative_apis/migrations/0002_add_consumer_type_field.py b/django_declarative_apis/migrations/0002_add_consumer_type_field.py index 0fe978a..5378b49 100644 --- a/django_declarative_apis/migrations/0002_add_consumer_type_field.py +++ b/django_declarative_apis/migrations/0002_add_consumer_type_field.py @@ -13,7 +13,6 @@ class Migration(migrations.Migration): - dependencies = [("django_declarative_apis", "0001_initial")] operations = [ diff --git a/django_declarative_apis/resources/resource.py b/django_declarative_apis/resources/resource.py index 14c6648..4d17368 100644 --- a/django_declarative_apis/resources/resource.py +++ b/django_declarative_apis/resources/resource.py @@ -185,7 +185,6 @@ def authenticate(self, request, rm): # noqa: C901 if not authentication_result: error = authentication_result if self.anonymous and rm in self.anonymous.allowed_methods: - actor, anonymous = self.anonymous(), True else: actor, anonymous = authenticator.challenge, CHALLENGE diff --git a/docs/source/conf.py b/docs/source/conf.py index 48f54a0..dab1f36 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -35,57 +35,57 @@ # # needs_sphinx = '1.0' -os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' +os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings" django.setup() # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.coverage', - 'sphinx.ext.viewcode', - 'sphinx.ext.githubpages', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.viewcode", + "sphinx.ext.githubpages", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = ['.rst'] +source_suffix = [".rst"] # The encoding of source files. # # source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'django-declarative-apis' -copyright = '2018, Salesforce' -author = 'Salesforce' +project = "django-declarative-apis" +copyright = "2018, Salesforce" +author = "Salesforce" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # The full version, including alpha/beta/rc tags. -release = '0.31.5' # set by bumpversion +release = "0.31.5" # set by bumpversion # The short X.Y version. -version = release.rsplit('.', 1)[0] +version = release.rsplit(".", 1)[0] # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = 'en' +language = "en" # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: @@ -121,7 +121,7 @@ # show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. # modindex_common_prefix = [] @@ -138,7 +138,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -252,34 +252,36 @@ # html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. -htmlhelp_basename = 'django-declarative-apisdoc' +htmlhelp_basename = "django-declarative-apisdoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'django-declarative-apis.tex', 'django-declarative-apis Documentation', - 'Drew Shafer', 'manual'), + ( + master_doc, + "django-declarative-apis.tex", + "django-declarative-apis Documentation", + "Drew Shafer", + "manual", + ), ] # The name of an image file (relative to this directory) to place at the top of @@ -314,8 +316,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'django-declarative-apis', 'django-declarative-apis Documentation', - [author], 1) + ( + master_doc, + "django-declarative-apis", + "django-declarative-apis Documentation", + [author], + 1, + ) ] # If true, show URL addresses after external links. @@ -329,9 +336,15 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'django-declarative-apis', 'django-declarative-apis Documentation', - author, 'django-declarative-apis', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "django-declarative-apis", + "django-declarative-apis Documentation", + author, + "django-declarative-apis", + "One line description of project.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. @@ -405,7 +418,7 @@ # epub_post_files = [] # A list of files that should not be packed into the epub file. -epub_exclude_files = ['search.html'] +epub_exclude_files = ["search.html"] # The depth of the table of contents in toc.ncx. # @@ -437,4 +450,4 @@ # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'https://docs.python.org/': None} +intersphinx_mapping = {"https://docs.python.org/": None} diff --git a/example/myapp/migrations/0001_initial.py b/example/myapp/migrations/0001_initial.py index aa4bfa6..25487ef 100644 --- a/example/myapp/migrations/0001_initial.py +++ b/example/myapp/migrations/0001_initial.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - initial = True dependencies = [("django_declarative_apis", "0002_add_consumer_type_field")] diff --git a/tests/resources/test_utils.py b/tests/resources/test_utils.py index fb23913..9b08211 100644 --- a/tests/resources/test_utils.py +++ b/tests/resources/test_utils.py @@ -122,7 +122,6 @@ def test_register_unregister(self): class KeyProcessingTestCase(unittest.TestCase): - # We can't compute these keys from the cryptography library because they're # nonstandard. These were both taken from their respective devices. From 7807314573ec8e770f2a27ad2b8b4426b66010a3 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 10:34:19 -0400 Subject: [PATCH 07/10] Exclude .heroku directory --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index e7fe65c..921a3e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,9 @@ dev = [ "tblib~=1.6.0", ] +[tool.ruff] +extend-exclude = [".heroku"] + [tool.coverage.run] omit = ["*/tests/*", "*/management/*", "*/migrations/*"] From c07d6c98c4901e9042244d64e971e25dde6cbf21 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 10:35:47 -0400 Subject: [PATCH 08/10] Add ruff --fix target to makefile --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 59a8632..7b39942 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,10 @@ format: ${FORMAT_CMD} .PHONY: format +static-fix: + ${STATIC_CMD} --fix +.PHONY: static-fix + docs: DJANGO_SETTINGS_MODULE=tests.settings $(MAKE) -C docs html SPHINXOPTS="-W" .PHONY: docs From 9ba106222488fcb330bf4d6bdd48c86b0fa16944 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 13:16:02 -0400 Subject: [PATCH 09/10] re-enable complexity check --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 921a3e1..d83f39a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,7 @@ dev = [ [tool.ruff] extend-exclude = [".heroku"] +extend-select = ["C901"] [tool.coverage.run] omit = ["*/tests/*", "*/management/*", "*/migrations/*"] From 980d7833a2bb4889d529ce5289f6e2158bb9eb7e Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Thu, 26 Oct 2023 13:31:41 -0400 Subject: [PATCH 10/10] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b19b6a..faa411f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# [Unreleased] +- [PR 143](https://github.com/salesforce/django-declarative-apis/pull/143) Testing: Replace `flake8` and `black` with `ruff`, add testing for Python 3.12, drop testing for Python 3.7 + # [0.31.5] - [PR 141](https://github.com/salesforce/django-declarative-apis/pull/141) Clean up logging - [PR 138](https://github.com/salesforce/django-declarative-apis/pull/138) Docs: Correct imports in code-blocks