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

A result of ruff formatting (no linting/isort) for testing #4501

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
76 changes: 76 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

# Same as Black.
line-length = 88
indent-width = 4

target-version = "py310"

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
68 changes: 37 additions & 31 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

# -- Project information -----------------------------------------------------

project = 'Janeway'
copyright = '2018-2024 Birkbeck, University of London'
author = 'Open Library of Humanities'
project = "Janeway"
copyright = "2018-2024 Birkbeck, University of London"
author = "Open Library of Humanities"

# The short X.Y version
version = '1.7.2'
version = "1.7.2"
# The full version, including alpha/beta/rc tags
release = '1.7.2'
release = "1.7.2"

# -- General configuration ---------------------------------------------------

Expand All @@ -38,29 +38,29 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'recommonmark',
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx_rtd_theme',
"recommonmark",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx_rtd_theme",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['ntemplates']
templates_path = ["ntemplates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
source_suffix = ['.rst', '.md']
source_suffix = [".rst", ".md"]

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# 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-GB'
language = "en-GB"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -76,9 +76,9 @@
# 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"
html_css_files = [
'custom.css',
"custom.css",
]
html_logo = "_static/janeway.svg"

Expand All @@ -91,7 +91,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['nstatic', '_static', '_static/css/']
html_static_path = ["nstatic", "_static", "_static/css/"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -107,7 +107,7 @@
# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'Janewaydoc'
htmlhelp_basename = "Janewaydoc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -116,15 +116,12 @@
# 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',
Expand All @@ -134,19 +131,21 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Janeway.tex', 'Janeway Documentation',
'Andy Byers, Mauro Sanchez \\& Martin Paul Eve', 'manual'),
(
master_doc,
"Janeway.tex",
"Janeway Documentation",
"Andy Byers, Mauro Sanchez \\& Martin Paul Eve",
"manual",
),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'janeway', 'Janeway Documentation',
[author], 1)
]
man_pages = [(master_doc, "janeway", "Janeway Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -155,9 +154,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Janeway', 'Janeway Documentation',
author, 'Janeway', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"Janeway",
"Janeway Documentation",
author,
"Janeway",
"One line description of project.",
"Miscellaneous",
),
]


Expand All @@ -176,10 +181,11 @@
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]


# -- Extension configuration -------------------------------------------------


def setup(app):
app.add_css_file('_static/css/custom.css')
app.add_css_file("_static/css/custom.css")
6 changes: 3 additions & 3 deletions jenkins/janeway_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
TEST_RUNNER = "xmlrunner.extra.djangotestrunner.XMLTestRunner"

TEST_OUTPUT_DIR = 'jenkins/test_results/'
TEST_OUTPUT_FILE_NAME = 'test_results.xml'
TEST_OUTPUT_DIR = "jenkins/test_results/"
TEST_OUTPUT_FILE_NAME = "test_results.xml"
4 changes: 2 additions & 2 deletions src/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class JanewayAdminSite(admin.AdminSite):
site_header = 'Janeway Administration'
site_title = 'Janeway Administration'
site_header = "Janeway Administration"
site_title = "Janeway Administration"
47 changes: 25 additions & 22 deletions src/api/oai/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@

metadata_formats = [
{
'prefix': 'oai_dc',
'schema': 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd',
'metadataNamespace': 'http://www.openarchives.org/OAI/2.0/oai_dc/',
"prefix": "oai_dc",
"schema": "http://www.openarchives.org/OAI/2.0/oai_dc.xsd",
"metadataNamespace": "http://www.openarchives.org/OAI/2.0/oai_dc/",
},
{
'prefix': 'jats',
'schema': 'https://jats.nlm.nih.gov/publishing/0.4/xsd/JATS-journalpublishing0.xsd',
'metadataNamespace': 'http://jats.nlm.nih.gov',
}
"prefix": "jats",
"schema": "https://jats.nlm.nih.gov/publishing/0.4/xsd/JATS-journalpublishing0.xsd",
"metadataNamespace": "http://jats.nlm.nih.gov",
},
]


class OAIModelView(BaseListView, TemplateResponseMixin):
""" Base class for OAI views generated from model Querysets """
"""Base class for OAI views generated from model Querysets"""

content_type = "application/xml"

metadata_prefix = 'oai_dc'
metadata_prefix = "oai_dc"

metadata_formats_set = {
format.get('prefix') for format in metadata_formats
}
metadata_formats_set = {format.get("prefix") for format in metadata_formats}

def get_queryset(self):
qs = super().get_queryset()
Expand All @@ -55,19 +54,20 @@ def apply_filters(self, qs):
return qs

def validate_metadata_format(self):
if self.metadata_prefix \
and self.metadata_prefix not in self.metadata_formats_set:
if (
self.metadata_prefix
and self.metadata_prefix not in self.metadata_formats_set
):
raise exceptions.OAIUnsupportedMetadataFormat()

def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context["metadata_prefix"] = self.request.GET.get("metadataPrefix",
"oai_dc")
context["metadata_prefix"] = self.request.GET.get("metadataPrefix", "oai_dc")
return context


class OAIPaginationMixin(View):
""" A Mixin allowing views to be paginated via OAI resumptionToken
"""A Mixin allowing views to be paginated via OAI resumptionToken

The resumptionToken is a query parameter that allows a consumer of the OAI
interface to resume consuming elements of a listed query when the bounds
Expand All @@ -80,14 +80,15 @@ class OAIPaginationMixin(View):
is addressed in the `dispatch` method where we have no option but to mutate
the self.request.GET member in order to inject those querystring filters.
"""

page_kwarg = "token_page"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._decoded_token = {}

def dispatch(self, *args, **kwargs):
""" Adds resumptionToken encoded parameters into request.GET
"""Adds resumptionToken encoded parameters into request.GET

This makes the implementation of resumptionToken transparent to any
child views that will see all encoded filters in the resumptionToken
Expand All @@ -112,14 +113,14 @@ def get_context_data(self, **kwargs):

def get_token_context(self, context):
return {
"page": context["page_obj"].next_page_number(),
"page": context["page_obj"].next_page_number(),
}

def encode_token(self, context):
token_data = {}
for key, value in self.request.GET.items():
# verb is an exception as per OAI spec
if key not in {'resumptionToken', "verb"}:
if key not in {"resumptionToken", "verb"}:
token_data[key] = value
token_data.update(self.get_token_context(context))

Expand All @@ -141,7 +142,6 @@ def page(self):


class OAIDateFilterMixin(OAIPaginationMixin):

def filter_by_date_range(self, qs):
try:
if self.from_:
Expand All @@ -153,7 +153,10 @@ def filter_by_date_range(self, qs):
# if it is not, add a default H:m:sZ.
if not until_date.tzinfo:
untile_date = until_date.replace(
hour=23, minute=59, second=59, tzinfo=utc,
hour=23,
minute=59,
second=59,
tzinfo=utc,
)

qs = qs.filter(date_published__lte=until_date)
Expand Down
Loading