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

Testing: Replace flake8 and black with ruff, add testing for Python 3.12, drop testing for Python 3.7 #143

Merged
merged 10 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = flake8 ${PACKAGE_DIR} ${TEST_DIR} ${EXAMPLE_DIR}
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


Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


class DjangoRequestValidator(RequestValidator):

TIMESTAMP_THRESHOLD = 300

def __init__(self, request, *args, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions django_declarative_apis/machinery/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion django_declarative_apis/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [("contenttypes", "0002_remove_content_type_name")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class Migration(migrations.Migration):

dependencies = [("django_declarative_apis", "0001_initial")]

operations = [
Expand Down
1 change: 0 additions & 1 deletion django_declarative_apis/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion django_declarative_apis/resources/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
100 changes: 57 additions & 43 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------------------------------
Expand All @@ -33,58 +35,57 @@
#
# needs_sphinx = '1.0'

import django
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:
Expand Down Expand Up @@ -120,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 = []
Expand All @@ -137,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
Expand Down Expand Up @@ -251,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
Expand Down Expand Up @@ -313,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.
Expand All @@ -328,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.
Expand Down Expand Up @@ -404,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.
#
Expand Down Expand Up @@ -436,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}
2 changes: 1 addition & 1 deletion example/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
1 change: 0 additions & 1 deletion example/myapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [("django_declarative_apis", "0002_add_consumer_type_field")]
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
26 changes: 4 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,19 @@ classifiers = [
[project.optional-dependencies]
dev = [
"bandit>=1.7.4",
"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",
"ruff~=0.1.2",
"sphinx_rtd_theme==0.5.2",
"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.ruff]
extend-exclude = [".heroku"]
extend-select = ["C901"]

[tool.coverage.run]
omit = ["*/tests/*", "*/management/*", "*/migrations/*"]
Expand Down
1 change: 0 additions & 1 deletion tests/resources/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down