Skip to content

Commit

Permalink
Merge pull request #183 from clEsperanto/add-pre-commit-check
Browse files Browse the repository at this point in the history
add pre-commit for auto format, linting
  • Loading branch information
StRigaud authored May 16, 2024
2 parents 840e506 + fa48e7e commit 054aaa9
Show file tree
Hide file tree
Showing 229 changed files with 2,064 additions and 2,872 deletions.
14 changes: 8 additions & 6 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[flake8]
# Ignore error codes that may conflict with Black
ignore = E203, E231, E501, W503, F401, F403

# Enable line length of 88, matching Black's default
ignore = E203, E266, E501, W503, F401
max-line-length = 88

# Exclude some directories and files from linting (customize as needed)
exclude = .git, .venv, __pycache__, .eggs, *.egg, build, dist

# Ignore F401 and F403 only for __init__.py files
per-file-ignores =
*/__init__.py: F403

# Warn if the complexity of a function exceeds 10
max-complexity = 18
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/prototype-related-issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ assignees: ''

**Describe the bug**
A clear and concise description of what the bug is. What were you trying to do and what happened.
It can be from a parameter or function name discreptency. to a change of results, or a full crash.
It can be from a parameter or function name discreptency. to a change of results, or a full crash.

**To Reproduce**
Steps to reproduce the behavior, ideally a notebook ready to run, with test data, at minima a code snippet.
Expand Down
17 changes: 13 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-toml
- id: check-yaml
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-toml
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: mixed-line-ending

# black - code formatting
# black - code formatting
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black

# flake8 - linting
# # isort - import sorting
# - repo: https://github.com/pycqa/isort
# rev: 5.12.0
# hooks:
# - id: isort

# flake8 - linting
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
- id: flake8
2 changes: 1 addition & 1 deletion docs/source/_static/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ $(function () {
$("[data-toggle='rst-debug-badge']").on("click", function () {
$("[data-toggle='rst-versions']").toggleClass("rst-badge");
});
})
})
2 changes: 1 addition & 1 deletion docs/source/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
</div>
</div>
{%- endif %}
{%- endblock %}
{%- endblock %}
2 changes: 1 addition & 1 deletion docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ tier3
:undoc-members:

tier4
------
------

.. automodule:: pyclesperanto._tier4
:members:
Expand Down
91 changes: 44 additions & 47 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import sys
import re
import sys

from sphinx.locale import _

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

# Open the CMakeCache.txt file and search for the project version
with open('../../pyclesperanto/_version.py', 'r') as f:
with open("../../pyclesperanto/_version.py", "r") as f:
for line in f:
if 'VERSION_CODE' in line:
start = line.find('=') + 1
end = line.find('\n', start)
release = ".".join(line[start:end].strip().split(', '))
if "VERSION_CODE" in line:
start = line.find("=") + 1
end = line.find("\n", start)
release = ".".join(line[start:end].strip().split(", "))
break

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = u"py-clEsperanto"
slug = re.sub(r'\W+', '-', project.lower())
author = u'Stephane Rigaud'
copyright = f'2024, {author}'
language = 'en'
project = "py-clEsperanto"
slug = re.sub(r"\W+", "-", project.lower())
author = "Stephane Rigaud"
copyright = f"2024, {author}"
language = "en"
version = release

# -- General configuration ---------------------------------------------------
Expand All @@ -39,9 +40,9 @@
"sphinx.ext.mathjax", # Print mathematical expressions
"nbsphinx", # link notebooks
"sphinx.ext.autosummary", # Make module lists in table
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
'sphinx_rtd_theme',
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
"sphinx_rtd_theme",
]

templates_path = ["_templates"]
Expand All @@ -51,74 +52,70 @@
add_module_names = False
modindex_common_prefix = ["pyclesperanto."]
gettext_compact = False
master_doc = 'index'
suppress_warnings = ['image.nonlocal_uri']
pygments_style = 'default'
master_doc = "index"
suppress_warnings = ["image.nonlocal_uri"]
pygments_style = "default"

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "sphinx_rtd_theme" # 'alabaster'
html_theme_options = {
'logo_only': False,
'navigation_depth': 5,
'display_version': True,
'collapse_navigation': False,
"logo_only": False,
"navigation_depth": 5,
"display_version": True,
"collapse_navigation": False,
}
html_context = {}

if not 'READTHEDOCS' in os.environ:
html_static_path = ['_static/']
html_js_files = ['debug.js']
if "READTHEDOCS" not in os.environ:
html_static_path = ["_static/"]
html_js_files = ["debug.js"]

# Add fake versions for local QA of the menu
html_context['test_versions'] = list(map(
lambda x: str(x / 10),
range(1, 100)
))
html_context["test_versions"] = list(map(lambda x: str(x / 10), range(1, 100)))

# html_logo = "demo/static/logo-wordmark-light.svg"
html_show_sourcelink = True
# html_favicon = "demo/static/favicon.ico"
htmlhelp_basename = slug

latex_documents = [
('index', '{0}.tex'.format(slug), project, author, 'manual'),
("index", "{0}.tex".format(slug), project, author, "manual"),
]

man_pages = [
('index', slug, project, [author], 1)
]
man_pages = [("index", slug, project, [author], 1)]

texinfo_documents = [
('index', slug, project, author, slug, project, 'Miscellaneous'),
("index", slug, project, author, slug, project, "Miscellaneous"),
]

html_static_path = ['_static']
html_static_path = ["_static"]


# Extensions to theme docs
def setup(app):
from sphinx.domains.python import PyField
from sphinx.util.docfields import Field

app.add_object_type(
'confval',
'confval',
objname='configuration value',
indextemplate='pair: %s; configuration value',
"confval",
"confval",
objname="configuration value",
indextemplate="pair: %s; configuration value",
doc_field_types=[
PyField(
'type',
label=_('Type'),
"type",
label=_("Type"),
has_arg=False,
names=('type',),
bodyrolename='class'
names=("type",),
bodyrolename="class",
),
Field(
'default',
label=_('Default'),
"default",
label=_("Default"),
has_arg=False,
names=('default',),
names=("default",),
),
]
)
],
)
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You will find here a first draft of the API for reference and documentation purp
.. toctree::
:caption: User Guide
:maxdepth: 1

install
usage
api
Expand All @@ -28,4 +28,4 @@ You will find here a first draft of the API for reference and documentation purp
:caption: Developper Guide
:maxdepth: 1

contribute
contribute
4 changes: 2 additions & 2 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ or via conda:
mamba create --name myenv
mamba activate myenv
.. note::
.. note::

It is often require to also install an additional package to use pyClesperanto, especially on MacOS or Linux:

Expand Down Expand Up @@ -81,4 +81,4 @@ However, any modification of the source code will require you to re-install the

.. warning::

If using an install from source, do not import the package from the source directory as it will not work properly.
If using an install from source, do not import the package from the source directory as it will not work properly.
6 changes: 3 additions & 3 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Memory transfer
===============

It is a good practice to consider the GPU as another computer. Its memory is separated from your computer (host) memory, hence you need to transfer your data to the device memory in order to process it.
Going both ways, you will need to transfer it back to your computer (host) memory when you are done running GPU operations so that you can read the results. In pyclesperanto this is managed by the
functions ``push``, ``pull``, and ``create``. ``push`` and ``pull`` are used to transfer data from the host to the GPU and vice versa. ``create`` is used to allocate an empty space on the GPU which will be
Going both ways, you will need to transfer it back to your computer (host) memory when you are done running GPU operations so that you can read the results. In pyclesperanto this is managed by the
functions ``push``, ``pull``, and ``create``. ``push`` and ``pull`` are used to transfer data from the host to the GPU and vice versa. ``create`` is used to allocate an empty space on the GPU which will be
then use, for example to store a result.


Expand Down Expand Up @@ -77,7 +77,7 @@ The ``push`` will create a memory space on the GPU like ``create`` but will also
The data pushed will keep the same data type as the array. Hence, if you push a ``uint8`` array, the data will be stored as ``uint8`` on the GPU.
The array will then use 4 times less memory than if it was stored as ``float32``. This is a good practice to keep in mind when working with GPUs as their
memory is limited.
memory is limited.

.. warning::
Python natively manage only 2 type of scalar, ``float`` and ``int``, correspondint to ``float64``, also known as ``double`` and ``int64``. However, ``double`` type
Expand Down
20 changes: 10 additions & 10 deletions pyclesperanto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from ._array import Array, Image, is_image
from ._core import (
Device,
default_initialisation,
get_device,
gpu_info,
list_available_backends,
list_available_devices,
select_backend,
select_device,
get_device,
wait_for_kernel_to_finish,
list_available_devices,
list_available_backends,
default_initialisation,
Device,
)
from ._array import Array, Image, is_image
from ._memory import create, create_like, push, pull
from ._functionalities import imshow, list_operations, execute, native_execute
from ._functionalities import execute, imshow, list_operations, native_execute
from ._memory import create, create_like, pull, push

from ._tier1 import *
from ._tier2 import *
Expand All @@ -21,11 +21,11 @@
from ._tier6 import *
from ._tier7 import *
from ._tier8 import *

from ._interroperability import *

from ._version import VERSION as __version__
from ._version import CLIC_VERSION as __clic_version__
from ._version import COMMON_ALIAS as __common_alias__

from ._version import VERSION as __version__

default_initialisation()
10 changes: 6 additions & 4 deletions pyclesperanto/_array.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from ._pyclesperanto import _Array as Array
from typing import Union

import numpy as np

from ._core import Device, get_device
from ._pyclesperanto import _Array as Array
from ._utils import _assert_supported_dtype
from . import _operators

from typing import Union
import numpy as np
from . import _operators


def _prepare_array(arr) -> np.ndarray:
Expand Down
5 changes: 3 additions & 2 deletions pyclesperanto/_core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import warnings
from typing import Optional, Union

import numpy as np
import warnings

from ._pyclesperanto import _Device as Device
from ._pyclesperanto import _BackendManager as BackendManager
from ._pyclesperanto import _Device as Device


class _current_device:
Expand Down
9 changes: 5 additions & 4 deletions pyclesperanto/_decorators.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Callable, Optional
import inspect
from functools import wraps
from typing import Callable, Optional

from toolz import curry
import inspect

from ._memory import push
from ._array import is_image, Image
from ._array import Image, is_image
from ._core import Device
from ._memory import push


@curry
Expand Down
Loading

0 comments on commit 054aaa9

Please sign in to comment.