Skip to content

Commit

Permalink
run ruff format . and ruff --check . --fix
Browse files Browse the repository at this point in the history
- also fix things that couldn't be fixed automatically
  • Loading branch information
swelborn committed Sep 13, 2024
1 parent 045b4e2 commit c3a883a
Show file tree
Hide file tree
Showing 13 changed files with 620 additions and 594 deletions.
53 changes: 23 additions & 30 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,47 @@

import os
import sys

import sphinx_rtd_theme
from unittest import mock

sys.path.insert(0, os.path.abspath('../../python'))
sys.path.insert(0, os.path.abspath("../../python"))


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

project = 'stempy'
copyright = '2020, Kitware, INC'
author = 'Kitware, INC'
project = "stempy"
copyright = "2020, Kitware, INC"
author = "Kitware, INC"

# The full version, including alpha/beta/rc tags
release = '1.0'
release = "1.0"


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

# 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_rtd_theme',
'recommonmark'
]
extensions = ["sphinx.ext.autodoc", "sphinx_rtd_theme", "recommonmark"]

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

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# Unfortunately, if we have a class that inherits sphinx's mock
# object, and we use that class in a default argument, we run into
# attribute errors. Fix it by defining an explicit mock of the class.
class MockReader:
class H5Format:
Frame = 1

sys.modules['stempy._io'] = mock.Mock()
_io_mock = sys.modules['stempy._io']

sys.modules["stempy._io"] = mock.Mock()
_io_mock = sys.modules["stempy._io"]

# We have to override these so we get don't get conflicting metaclasses
_io_mock._sector_reader = MockReader
Expand All @@ -70,36 +66,33 @@ class H5Format:
# 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"

# 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 = ['_static']
html_static_path = ["_static"]

# Get autodoc to mock these imports, because we don't actually need them
# for generating the docs
autodoc_mock_imports = [
'stempy._image',
'numpy',
'h5py'
]
autodoc_mock_imports = ["stempy._image", "numpy", "h5py"]


# Modify this function to customize which classes/functions are skipped
def autodoc_skip_member_handler(app, what, name, obj, skip, options):
# Exclude any names that start with a string in this list
exclude_startswith_list = ['_']
exclude_startswith_list = ["_"]

if any([name.startswith(x) for x in exclude_startswith_list]):
if any(name.startswith(x) for x in exclude_startswith_list):
return True

# Exclude any names that match a string in this list
exclude_names = [
'ReaderMixin',
'PyReader',
'SectorReader',
'get_hdf5_reader',
'SectorThreadedMultiPassReader',
"ReaderMixin",
"PyReader",
"SectorReader",
"get_hdf5_reader",
"SectorThreadedMultiPassReader",
]

return name in exclude_names
Expand All @@ -109,4 +102,4 @@ def autodoc_skip_member_handler(app, what, name, obj, skip, options):
def setup(app):
# Connect the autodoc-skip-member event from apidoc to the callback
# This allows us to customize which classes/functions are skipped
app.connect('autodoc-skip-member', autodoc_skip_member_handler)
app.connect("autodoc-skip-member", autodoc_skip_member_handler)
2 changes: 1 addition & 1 deletion python/stempy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
__version__ = get_version()

__all__ = [
'__version__',
"__version__",
]
20 changes: 5 additions & 15 deletions python/stempy/contrib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class FileSuffix(Enum):

def check_only_one_filepath(file_path):
if len(file_path) > 1:
raise ValueError(
"Multiple files match that input. Add scan_id to be more specific."
)
raise ValueError("Multiple files match that input. Add scan_id to be more specific.")
elif len(file_path) == 0:
raise FileNotFoundError("No file with those parameters can be found.")

Expand Down Expand Up @@ -125,13 +123,9 @@ def get_scan_path_version_1(
if file_suffix == FileSuffix.STANDARD:
file_pattern = f"FOURD_*_{str(scan_id).zfill(5)}_?????.{filetype}"
else:
file_pattern = (
f"FOURD_*_{str(scan_id).zfill(5)}_?????{file_suffix.value}.{filetype}"
)
file_pattern = f"FOURD_*_{str(scan_id).zfill(5)}_?????{file_suffix.value}.{filetype}"
elif scan_num is not None:
file_pattern = (
f"FOURD_*_*_{str(scan_num).zfill(5)}{file_suffix.value}.{filetype}"
)
file_pattern = f"FOURD_*_*_{str(scan_num).zfill(5)}{file_suffix.value}.{filetype}"

file_path = list(directory.glob(file_pattern))
check_only_one_filepath(file_path)
Expand Down Expand Up @@ -188,9 +182,7 @@ def get_scan_path(
th=th,
file_suffix=file_suffix,
),
1: lambda: get_scan_path_version_1(
directory, scan_num=scan_num, scan_id=scan_id, file_suffix=file_suffix
),
1: lambda: get_scan_path_version_1(directory, scan_num=scan_num, scan_id=scan_id, file_suffix=file_suffix),
}

for ver in versions_to_try:
Expand All @@ -202,6 +194,4 @@ def get_scan_path(
except FileNotFoundError:
continue

raise FileNotFoundError(
"No file with those parameters can be found for any version."
)
raise FileNotFoundError("No file with those parameters can be found for any version.")
Loading

0 comments on commit c3a883a

Please sign in to comment.