Skip to content

Commit

Permalink
Use ruff formatter as pre-commit (#103)
Browse files Browse the repository at this point in the history
* Use ruff formatter as pre-commit

* Update code

* Update docs
  • Loading branch information
hagenw authored Mar 28, 2024
1 parent 90253f1 commit a4c5e96
Show file tree
Hide file tree
Showing 15 changed files with 520 additions and 514 deletions.
10 changes: 0 additions & 10 deletions .flake8

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.10'

- name: Install pre-commit hooks
run: |
Expand Down
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
#
#
default_language_version:
python: python3.8
python: python3.10

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.276
rev: v0.1.8
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Coding Convention
-----------------

We follow the PEP8_ convention for Python code
and check for correct syntax with ruff_.
and use ruff_ as a linter and code formatter.
In addition,
we check for common spelling errors with codespell_.
Both tools and possible exceptions
Expand All @@ -57,7 +57,8 @@ You can also install ruff_ and codespell_
and call it directly::

pip install ruff codespell # consider system wide installation
ruff check .
ruff check --fix . # lint all Python files, and fix any fixable errors
ruff format . # format code of all Python files
codespell

It can be restricted to specific folders::
Expand Down
77 changes: 38 additions & 39 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,54 @@
import audeer


config = toml.load(audeer.path('..', 'pyproject.toml'))
config = toml.load(audeer.path("..", "pyproject.toml"))


# Project -----------------------------------------------------------------

project = config['project']['name']
author = ', '.join(author['name'] for author in config['project']['authors'])
copyright = f'2020-{date.today().year} audEERING GmbH'
project = config["project"]["name"]
author = ", ".join(author["name"] for author in config["project"]["authors"])
copyright = f"2020-{date.today().year} audEERING GmbH"
version = audeer.git_repo_version()
title = 'Documentation'
title = "Documentation"


# General -----------------------------------------------------------------

master_doc = 'index'
source_suffix = '.rst'
master_doc = "index"
source_suffix = ".rst"
exclude_patterns = [
'api-src',
'build',
'tests',
'Thumbs.db',
'.DS_Store',
"api-src",
"build",
"tests",
"Thumbs.db",
".DS_Store",
]
templates_path = ['_templates']
templates_path = ["_templates"]
pygments_style = None
extensions = [
'jupyter_sphinx', # executing code blocks
'sphinx.ext.autodoc',
'sphinx.ext.napoleon', # support for Google-style docstrings
'sphinx.ext.autosummary',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx',
'sphinx.ext.autosectionlabel',
'sphinx_autodoc_typehints',
'sphinx_copybutton', # for "copy to clipboard" buttons
"jupyter_sphinx", # executing code blocks
"sphinx.ext.autodoc",
"sphinx.ext.napoleon", # support for Google-style docstrings
"sphinx.ext.autosummary",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
"sphinx.ext.autosectionlabel",
"sphinx_autodoc_typehints",
"sphinx_copybutton", # for "copy to clipboard" buttons
]

napoleon_use_ivar = True # List of class attributes
autodoc_inherit_docstrings = False # disable docstring inheritance

intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
'pandas': ('https://pandas.pydata.org/pandas-docs/stable/', None),
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://docs.scipy.org/doc/numpy/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
}

# Do not copy prompot output
copybutton_prompt_text = r'>>> |\.\.\. |\$ '
copybutton_prompt_text = r">>> |\.\.\. |\$ "
copybutton_prompt_is_regexp = True

# Disable auto-generation of TOC entries in the API
Expand All @@ -64,35 +64,34 @@

# HTML --------------------------------------------------------------------

html_theme = 'sphinx_audeering_theme'
html_theme = "sphinx_audeering_theme"
html_theme_options = {
'display_version': True,
'footer_links': False,
'logo_only': False,
'wide_pages': ['usage'],
"display_version": True,
"footer_links": False,
"logo_only": False,
"wide_pages": ["usage"],
}
html_context = {
'display_github': True,
"display_github": True,
}
html_title = title


# Linkcheck ---------------------------------------------------------------

linkcheck_ignore = [
'https://sail.usc.edu/',
'http://sphinx-doc.org/',
"https://sail.usc.edu/",
"http://sphinx-doc.org/",
]


# Copy API (sub-)module RST files to docs/api/ folder ---------------------

audeer.rmdir('api')
audeer.mkdir('api')
api_src_files = audeer.list_file_names('api-src')
audeer.rmdir("api")
audeer.mkdir("api")
api_src_files = audeer.list_file_names("api-src")
api_dst_files = [
audeer.path('api', os.path.basename(src_file))
for src_file in api_src_files
audeer.path("api", os.path.basename(src_file)) for src_file in api_src_files
]
for src_file, dst_file in zip(api_src_files, api_dst_files):
shutil.copyfile(src_file, dst_file)
40 changes: 20 additions & 20 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ but it's also possible to run custom config files.

audb.config.REPOSITORIES = [
audb.Repository(
name='data-public',
host='https://audeering.jfrog.io/artifactory',
backend='artifactory',
name="data-public",
host="https://audeering.jfrog.io/artifactory",
backend="artifactory",
),
]

Expand All @@ -43,20 +43,20 @@ emodb_ database.


db = audb.load(
'emodb',
version='1.1.1',
format='wav',
"emodb",
version="1.1.1",
format="wav",
mixdown=True,
sampling_rate=16000,
media='wav/03a01.*', # load subset
media="wav/03a01.*", # load subset
full_path=False,
verbose=False,
)

.. jupyter-execute::
:hide-code:

pd.set_option('display.max_columns', 4)
pd.set_option("display.max_columns", 4)

Process signal
--------------
Expand Down Expand Up @@ -128,13 +128,13 @@ we can create a log file.
feature_set=opensmile.FeatureSet.eGeMAPSv02,
feature_level=opensmile.FeatureLevel.Functionals,
loglevel=2,
logfile='smile.log',
logfile="smile.log",
)
smile.process_signal(
signal,
sampling_rate
)
with open('./smile.log', 'r') as fp:
with open("./smile.log", "r") as fp:
log = fp.readlines()
log

Expand All @@ -145,7 +145,7 @@ We can create a custom config.

.. jupyter-execute::

config_str = '''
config_str = """
[componentInstances:cComponentManager]
instance[dataMemory].type=cDataMemory

Expand Down Expand Up @@ -201,24 +201,24 @@ We can create a custom config.

\{\cm[sink{?}:include external sink]}

'''
"""

It's important to always set the
``source`` and ``sink`` as we did above.
But we are free in choosing the levels.
In the above we have added two
levels ``'func'`` and ``'lld'``.
levels ``"func"`` and ``"lld"``.
Now, we simply pass the level
we are interested in.

.. jupyter-execute::

with open('my.conf', 'w') as fp:
with open("my.conf", "w") as fp:
fp.write(config_str)

smile = opensmile.Smile(
feature_set='my.conf',
feature_level='func',
feature_set="my.conf",
feature_level="func",
)
smile.process_signal(
signal,
Expand All @@ -230,8 +230,8 @@ And...
.. jupyter-execute::

smile = opensmile.Smile(
feature_set='my.conf',
feature_level='lld',
feature_set="my.conf",
feature_level="lld",
)
smile.process_signal(
signal,
Expand Down Expand Up @@ -294,7 +294,7 @@ the first ten seconds of the files
)
smile.process_files(
files,
ends=['2s'] * len(files),
ends=["2s"] * len(files),
root=db.root,
)

Expand All @@ -308,7 +308,7 @@ to speed up the processing.

.. jupyter-execute::

index = db['emotion'].index # pick table index
index = db["emotion"].index # pick table index
smile = opensmile.Smile(
feature_set=opensmile.FeatureSet.eGeMAPSv02,
feature_level=opensmile.FeatureLevel.Functionals,
Expand Down
3 changes: 2 additions & 1 deletion opensmile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
__all__ = []


__version__ = 'unknown'
__version__ = "unknown"

# Dynamically get the version of the installed module
try:
import importlib.metadata

__version__ = importlib.metadata.version(__name__)
except Exception: # pragma: no cover
importlib = None # pragma: no cover
Expand Down
27 changes: 12 additions & 15 deletions opensmile/core/config.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
class config:
r"""Get/set defaults for the :mod:`opensmile` module."""

CONFIG_ROOT = 'config'
CONFIG_ROOT = "config"
"""Root directory of config files."""

CONFIG_EXT = '.conf'
CONFIG_EXT = ".conf"
"""Extension of config files."""

EXTERNAL_SOURCE_COMPONENT = 'extsource'
EXTERNAL_SOURCE_COMPONENT = "extsource"
"""Standard component name for external input."""

EXTERNAL_OUTPUT_COMPONENT = 'extsink'
EXTERNAL_OUTPUT_COMPONENT = "extsink"
"""Standard component name for external data output."""

FILE_INPUT_CONFIG = 'shared/standard_wave_input.conf.inc'
FILE_INPUT_CONFIG = "shared/standard_wave_input.conf.inc"
"""Standard config name for wave input from file."""

EXTERNAL_INPUT_CONFIG = \
'shared/standard_external_wave_input.conf.inc'
EXTERNAL_INPUT_CONFIG = "shared/standard_external_wave_input.conf.inc"
"""Standard config name for external wave input."""

EXTERNAL_OUTPUT_SINGLE_CONFIG = \
'shared/standard_external_data_output_single.conf.inc'
EXTERNAL_OUTPUT_SINGLE_CONFIG = (
"shared/standard_external_data_output_single.conf.inc"
)
"""Standard config name for external data output from a single level."""

EXTERNAL_OUTPUT_MULTI_CONFIG = \
'shared/standard_external_data_output_multi.conf.inc'
EXTERNAL_OUTPUT_MULTI_CONFIG = "shared/standard_external_data_output_multi.conf.inc"
"""Standard config name for external data output from multiple levels."""

FILE_OUTPUT_CONFIG = \
'shared/standard_data_output.conf.inc'
FILE_OUTPUT_CONFIG = "shared/standard_data_output.conf.inc"
"""Standard config name for external data output."""

FILE_OUTPUT_CONFIG_NO_LLD_DE = \
'shared/standard_data_output_no_lld_de.conf.inc'
FILE_OUTPUT_CONFIG_NO_LLD_DE = "shared/standard_data_output_no_lld_de.conf.inc"
"""Standard config name for external data output without lld_de level."""
Loading

0 comments on commit a4c5e96

Please sign in to comment.