Skip to content

Commit

Permalink
making ruff happier
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Nov 25, 2024
1 parent 902f24f commit 01fd596
Show file tree
Hide file tree
Showing 22 changed files with 472 additions and 360 deletions.
14 changes: 7 additions & 7 deletions docs/_theme/flask_theme_support.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# flasky extensions. flasky pygments style based on tango style
from pygments.style import Style
from pygments.token import (
Keyword,
Name,
Comment,
String,
Error,
Generic,
Keyword,
Literal,
Name,
Number,
Operator,
Generic,
Whitespace,
Punctuation,
Other,
Literal,
Punctuation,
String,
Whitespace,
)


Expand Down
46 changes: 21 additions & 25 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Documentation build configuration file, created by
# sphinx-quickstart on Thu Feb 27 20:00:23 2014.
Expand All @@ -12,19 +11,18 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import datetime
import os
import sys
import datetime

try:
import numpy
import numpy as np

assert numpy
assert np
except ImportError:
# From the readthedocs manual
# http://read-the-docs.readthedocs.org/en/latest/faq.html?highlight=numpy
print('Unable to import numpy, falling back to mock', file=sys.stderr)
import mock
from unittest import mock

MOCK_MODULES = ['pygtk', 'gtk', 'gobject', 'argparse', 'numpy', 'pandas']
for mod_name in MOCK_MODULES:
Expand All @@ -36,7 +34,6 @@
sys.path.insert(0, os.path.abspath('..'))
from stl import __about__ as metadata


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

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down Expand Up @@ -70,10 +67,7 @@

# General information about the project.
project = metadata.__package_name__.replace('-', ' ').capitalize()
copyright = '%s, <a href="https://wol.ph/">%s</a>' % (
datetime.date.today().year,
metadata.__author__,
)
copyright = f'{datetime.date.today().year}, <a href="https://wol.ph/">{metadata.__author__}</a>'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -219,14 +213,15 @@
#'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
# Grouping the document tree into LaTeX files. List of tuples (source start
# file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
(
'index',
'%s.tex' % metadata.__package_name__,
'%s Documentation'
% metadata.__package_name__.replace('-', ' ').capitalize(),
f'{metadata.__package_name__}.tex',
'{} Documentation'.format(
metadata.__package_name__.replace('-', ' ').capitalize()
),
metadata.__author__,
'manual',
)
Expand Down Expand Up @@ -261,8 +256,9 @@
(
'index',
metadata.__package_name__,
'%s Documentation'
% metadata.__package_name__.replace('-', ' ').capitalize(),
'{} Documentation'.format(
metadata.__package_name__.replace('-', ' ').capitalize()
),
[metadata.__author__],
1,
)
Expand All @@ -281,8 +277,9 @@
(
'index',
metadata.__package_name__,
'%s Documentation'
% metadata.__package_name__.replace('-', ' ').capitalize(),
'{} Documentation'.format(
metadata.__package_name__.replace('-', ' ').capitalize()
),
metadata.__author__,
metadata.__package_name__,
metadata.__description__,
Expand Down Expand Up @@ -311,11 +308,10 @@
epub_publisher = metadata.__author__
epub_copyright = copyright

# The HTML theme for the epub output. Since the default themes are not optimized
# for small screen space, using the same theme for HTML and epub output is
# usually not wise. This defaults to 'epub', a theme designed to save visual
# space.
# epub_theme = 'epub'
# The HTML theme for the epub output. Since the default themes are not
# optimized for small screen space, using the same theme for HTML and epub
# output is usually not wise. This defaults to 'epub', a theme designed to
# save visual space. epub_theme = 'epub'

# The language of the text. It defaults to the language option
# or en if the language is not set.
Expand Down
111 changes: 111 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# We keep the ruff configuration separate so it can easily be shared across
# all projects

target-version = 'py39'

src = ['stl']
exclude = [
'.tox',
# Ignore local test files/directories/old-stuff
'test.py',
'*_old.py',
]

line-length = 79

[lint]
ignore = [
'A001', # Variable {name} is shadowing a Python builtin
'A002', # Argument {name} is shadowing a Python builtin
'A003', # Class attribute {name} is shadowing a Python builtin
'B023', # function-uses-loop-variable
'B024', # `FormatWidgetMixin` is an abstract base class, but it has no abstract methods
'D205', # blank-line-after-summary
'D212', # multi-line-summary-first-line
'RET505', # Unnecessary `else` after `return` statement
'TRY003', # Avoid specifying long messages outside the exception class
'RET507', # Unnecessary `elif` after `continue` statement
'C405', # Unnecessary {obj_type} literal (rewrite as a set literal)
'C406', # Unnecessary {obj_type} literal (rewrite as a dict literal)
'C408', # Unnecessary {obj_type} call (rewrite as a literal)
'SIM114', # Combine `if` branches using logical `or` operator
'RET506', # Unnecessary `else` after `raise` statement
'Q001', # Remove bad quotes
'Q002', # Remove bad quotes
'FA100', # Missing `from __future__ import annotations`, but uses `typing.Optional`
'COM812', # Missing trailing comma in a list
'ISC001', # String concatenation with implicit str conversion
'SIM108', # Ternary operators are not always more readable
'RUF100', # Unused noqa directives. Due to multiple Python versions, we need to keep them
]

select = [
'A', # flake8-builtins
'ASYNC', # flake8 async checker
'B', # flake8-bugbear
'C4', # flake8-comprehensions
'C90', # mccabe
'COM', # flake8-commas

## Require docstrings for all public methods, would be good to enable at some point
# 'D', # pydocstyle

'E', # pycodestyle error ('W' for warning)
'F', # pyflakes
'FA', # flake8-future-annotations
'I', # isort
'ICN', # flake8-import-conventions
'INP', # flake8-no-pep420
'ISC', # flake8-implicit-str-concat
'N', # pep8-naming
'NPY', # NumPy-specific rules
'PERF', # perflint,
'PIE', # flake8-pie
'Q', # flake8-quotes

'RET', # flake8-return
'RUF', # Ruff-specific rules
'SIM', # flake8-simplify
'T20', # flake8-print
'TD', # flake8-todos
'TRY', # tryceratops
'UP', # pyupgrade
]

[lint.per-file-ignores]
'tests/*' = ['SIM115', 'SIM117', 'T201', 'B007']
'docs/*' = ['INP001', 'RUF012']

[lint.pydocstyle]
convention = 'google'
ignore-decorators = [
'typing.overload',
'typing.override',
]

[lint.isort]
case-sensitive = true
combine-as-imports = true
force-wrap-aliases = true

[lint.flake8-quotes]
docstring-quotes = 'single'
inline-quotes = 'single'
multiline-quotes = 'single'

[format]
line-ending = 'lf'
indent-style = 'space'
quote-style = 'single'
docstring-code-format = true
skip-magic-trailing-comma = false
exclude = [
'__init__.py',
]

[lint.pycodestyle]
max-line-length = 79

[lint.flake8-pytest-style]
mark-parentheses = true

31 changes: 17 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import os
import sys
import warnings
from setuptools import setup, extension

from setuptools import extension, setup
from setuptools.command.build_ext import build_ext

setup_kwargs = {}


def error(*lines):
for line in lines:
print(line, file=sys.stderr)
for _line in lines:
pass


try:
Expand All @@ -27,15 +28,15 @@ def error(*lines):


try:
import numpy
import numpy as np
from Cython import Build

setup_kwargs['ext_modules'] = Build.cythonize(
[
extension.Extension(
'stl._speedups',
['stl/_speedups.pyx'],
include_dirs=[numpy.get_include()],
include_dirs=[np.get_include()],
),
]
)
Expand All @@ -57,8 +58,8 @@ def error(*lines):
with open('README.rst') as fh:
long_description = fh.read()
else:
long_description = (
'See http://pypi.python.org/pypi/%s/' % (about['__package_name__'])
long_description = 'See http://pypi.python.org/pypi/{}/'.format(
about['__package_name__']
)

install_requires = [
Expand All @@ -76,12 +77,12 @@ def run(self):
build_ext.run(self)
except Exception as e:
warnings.warn(
"""
f"""
Unable to build speedups module, defaulting to pure Python. Note
that the pure Python version is more than fast enough in most cases
%r
"""
% e
{e!r}
""",
stacklevel=2,
)


Expand All @@ -101,9 +102,11 @@ def run(self):
tests_require=tests_require,
entry_points={
'console_scripts': [
'stl = %s.main:main' % about['__import_name__'],
'stl2ascii = %s.main:to_ascii' % about['__import_name__'],
'stl2bin = %s.main:to_binary' % about['__import_name__'],
'stl = {}.main:main'.format(about['__import_name__']),
'stl2ascii = {}.main:to_ascii'.format(
about['__import_name__']
),
'stl2bin = {}.main:to_binary'.format(about['__import_name__']),
],
},
classifiers=[
Expand Down
10 changes: 2 additions & 8 deletions stl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from .stl import BUFFER_SIZE
from .stl import HEADER_SIZE
from .stl import COUNT_SIZE
from .stl import MAX_COUNT

from .stl import Mode
from .base import Dimension
from .base import RemoveDuplicates
from .base import Dimension, RemoveDuplicates
from .mesh import Mesh
from .stl import BUFFER_SIZE, COUNT_SIZE, HEADER_SIZE, MAX_COUNT, Mode

__all__ = [
'BUFFER_SIZE',
Expand Down
Loading

0 comments on commit 01fd596

Please sign in to comment.