Skip to content

Commit

Permalink
Merge branch 'DiamondLightSource:main' into slits
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-fernandes authored Oct 9, 2023
2 parents d67ef85 + 16468c9 commit 612d000
Show file tree
Hide file tree
Showing 74 changed files with 2,201 additions and 460 deletions.
2 changes: 1 addition & 1 deletion .github/pages/make_switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_versions(ref: str, add: Optional[str], remove: Optional[str]) -> List[st
def write_json(path: Path, repository: str, versions: str):
org, repo_name = repository.split("/")
struct = [
dict(version=version, url=f"https://{org}.github.io/{repo_name}/{version}/")
{"version": version, "url": f"https://{org}.github.io/{repo_name}/{version}/"}
for version in versions
]
text = json.dumps(struct, indent=2)
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ venv*
# further build artifacts
lockfiles/

# ruff cache
.ruff_cache/
29 changes: 8 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,15 @@ repos:
files: \.pyi?
types: [file]

# Sort imports
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: local
hooks:
- id: isort
name: isort (python)
args:
[
"--profile=black",
'--add_imports="from __future__ import annotations',
]

# Linting
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
["flake8-comprehensions==3.8.0", "Flake8-pyproject"]
args: ["--max-line-length=88", "--ignore=E203,F811,F722,E501,W503,C408"]

# Type checking
- id: ruff
name: Run ruff
stages: [commit]
language: system
entry: ruff
types: [python]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ms-python.python",
"tamasfe.even-better-toml",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters"
"ryanluker.vscode-coverage-gutters",
"charliermarsh.Ruff"
]
}
17 changes: 7 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.flake8Enabled": false,
"python.linting.mypyEnabled": true,
"python.linting.enabled": true,
"python.testing.pytestArgs": [],
Expand All @@ -9,19 +9,16 @@
"python.formatting.provider": "black",
"python.languageServer": "Pylance",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"python.sortImports.args": [
"--profile",
"black"
],
"[python]": {
"editor.rulers": [
88
]
],
"editor.codeActionsOnSave": {
"source.fixAll.ruff": false,
"source.organizeImports.ruff": true
}
},
"python.analysis.extraPaths": [
"./src"
],
}
}
67 changes: 33 additions & 34 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,16 @@

# This means you can link things like `str` and `asyncio` to the relevant
# docs in the python documentation.
intersphinx_mapping = dict(python=("https://docs.python.org/3/", None))
intersphinx_mapping = {"python": ("https://docs.python.org/3/", None)}

# A dictionary of graphviz graph attributes for inheritance diagrams.
inheritance_graph_attrs = dict(rankdir="TB")
inheritance_graph_attrs = {"rankdir": "TB"}

# Common links that should be available on every page
rst_epilog = """
.. _Diamond Light Source: http://www.diamond.ac.uk
.. _black: https://github.com/psf/black
.. _flake8: https://flake8.pycqa.org/en/latest/
.. _isort: https://github.com/PyCQA/isort
.. _ruff: https://beta.ruff.rs/docs/
.. _mypy: http://mypy-lang.org/
.. _pre-commit: https://pre-commit.com/
"""
Expand Down Expand Up @@ -149,40 +148,40 @@
# Point 3 makes checking switcher difficult, because the updated skeleton
# will fix the switcher at the end of the docs workflow, but never gets a chance
# to complete as the docs build warns and fails.
html_theme_options = dict(
logo=dict(
text=project,
),
use_edit_page_button=True,
github_url=f"https://github.com/{github_user}/{github_repo}",
icon_links=[
dict(
name="PyPI",
url=f"https://pypi.org/project/{project}",
icon="fas fa-cube",
)
html_theme_options = {
"logo": {
"text": project,
},
"use_edit_page_button": True,
"github_url": f"https://github.com/{github_user}/{github_repo}",
"icon_links": [
{
"name": "PyPI",
"url": f"https://pypi.org/project/{project}",
"icon": "fas fa-cube",
}
],
switcher=dict(
json_url=switcher_json,
version_match=version,
),
check_switcher=False,
navbar_end=["theme-switcher", "icon-links", "version-switcher"],
external_links=[
dict(
name="Release Notes",
url=f"https://github.com/{github_user}/{github_repo}/releases",
)
"switcher": {
"json_url": switcher_json,
"version_match": version,
},
"check_switcher": False,
"navbar_end": ["theme-switcher", "icon-links", "version-switcher"],
"external_links": [
{
"name": "Release Notes",
"url": f"https://github.com/{github_user}/{github_repo}/releases",
}
],
)
}

# A dictionary of values to pass into the template engine’s context for all pages
html_context = dict(
github_user=github_user,
github_repo=project,
github_version=version,
doc_path="docs",
)
html_context = {
"github_user": github_user,
"github_repo": project,
"github_version": version,
"doc_path": "docs",
}

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
html_show_sphinx = False
Expand Down
14 changes: 6 additions & 8 deletions docs/developer/how-to/lint.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Run linting using pre-commit
============================

Code linting is handled by black_, flake8_ and isort_ run under pre-commit_.
Code linting is handled by black_ and ruff_ run under pre-commit_.

Running pre-commit
------------------
Expand All @@ -23,16 +23,14 @@ repository::

$ black .

Likewise with isort::
Likewise with ruff::

$ isort .
$ ruff --fix .

If you get any flake8 issues you will have to fix those manually.
Ruff may not be able to automatically fix all issues; in this case, you will have to fix those manually.

VSCode support
--------------

The ``.vscode/settings.json`` will run black and isort formatters as well as
flake8 checking on save. Issues will be highlighted in the editor window.


The ``.vscode/settings.json`` will run black formatting as well as
ruff checking on save. Issues will be highlighted in the editor window.
12 changes: 6 additions & 6 deletions docs/developer/how-to/move-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Moving code from another repo
=============================

In the process of writing code in other DLS repos you may come to realise that it makes more sense to be in ``dodal``. It is a good idea to keep the history for this code, you can do this by doing the following (we will be using moving devices from https://github.com/DiamondLightSource/python-artemis as an example):
In the process of writing code in other DLS repos you may come to realise that it makes more sense to be in ``dodal``. It is a good idea to keep the history for this code, you can do this by doing the following (we will be using moving devices from https://github.com/DiamondLightSource/hyperion as an example):

#. Clone the codebase you are copying from::

git clone git@github.com:DiamondLightSource/python-artemis.git clone_for_history
git clone git@github.com:DiamondLightSource/hyperion.git clone_for_history
cd clone_for_history/

#. Remove the remote to avoid any mistaken pushes::
Expand All @@ -28,11 +28,11 @@ In the process of writing code in other DLS repos you may come to realise that i
#. Add a note to every commit message to mention it's been moved::

git filter-branch --msg-filter 'sed "$ a \
NOTE: Commit originally came from https://github.com/DiamondLightSource/python-artemis"' -f -- --all
NOTE: Commit originally came from https://github.com/DiamondLightSource/hyperion"' -f -- --all

#. If you have been using Github `issue references`_ in the old repository modify these to point to be more explicit (Note that this assumes the old repo uses ``#123`` notation and only ever references issues from it's own repo)::

git filter-branch -f --msg-filter 'sed "s|#[0-9]\+|DiamondLightSource/python-artemis&|g"' -- --all
git filter-branch -f --msg-filter 'sed "s|#[0-9]\+|DiamondLightSource/hyperion&|g"' -- --all

#. Prepare the code to be in the correct structure for dodal::

Expand All @@ -51,7 +51,7 @@ In the process of writing code in other DLS repos you may come to realise that i
git clone git@github.com:DiamondLightSource/dodal.git
cd dodal
git remote rm origin
git checkout -b add_code_from_artemis
git checkout -b add_code_from_hyperion

#. Add the source repo as a remote for ``dodal``::

Expand All @@ -68,6 +68,6 @@ In the process of writing code in other DLS repos you may come to realise that i
git remote rm source
git remote add origin git@github.com:DiamondLightSource/dodal.git

#. Tidy up the code so that it fits into the ``dodal`` repo e.g. in the Artemis case we had to change the tests to import from ``artemis`` to import from ``dodal`` and add some more dependencies.
#. Tidy up the code so that it fits into the ``dodal`` repo e.g. in the Hyperion case we had to change the tests to import from ``hyperion`` to import from ``dodal`` and add some more dependencies.

.. _issue references: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls#issues-and-pull-requests
3 changes: 1 addition & 2 deletions docs/developer/reference/standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Code Standards
The code in this repository conforms to standards set by the following tools:

- black_ for code formatting
- flake8_ for style checks
- isort_ for import ordering
- ruff_ for style checks
- mypy_ for static type checking

.. seealso::
Expand Down
42 changes: 23 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "dodal"
name = "dls-dodal"
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: Apache Software License",
Expand All @@ -15,13 +15,17 @@ classifiers = [
description = "Ophyd devices and other utils that could be used across DLS beamlines"
dependencies = [
"ophyd",
"ophyd-async",
"bluesky",
"pyepics",
"dataclasses-json",
"pillow",
"requests",
"graypy",
"pydantic<2.0",
"opencv-python-headless", # For pin-tip detection.
"aioca", # Required for CA support with ophyd-async.
"p4p", # Required for PVA support with ophyd-async.
]
dynamic = ["version"]
license.file = "LICENSE"
Expand All @@ -32,14 +36,14 @@ requires-python = ">=3.8"
dev = [
"black",
"mypy",
"flake8-isort",
"Flake8-pyproject",
"mockito",
"pipdeptree",
"pre-commit",
"pydata-sphinx-theme>=0.12",
"pytest-asyncio",
"pytest-cov",
"pytest-random-order",
"ruff",
"sphinx-autobuild",
"sphinx-copybutton",
"sphinx-design",
Expand Down Expand Up @@ -68,22 +72,6 @@ write_to = "src/dodal/_version.py"
plugins = ["pydantic.mypy"]
ignore_missing_imports = true # Ignore missing stubs in imported modules

[tool.isort]
float_to_top = true
profile = "black"

[tool.flake8]
extend-ignore = [
"E203", # See https://github.com/PyCQA/pycodestyle/issues/373
"F811", # support typing.overload decorator
"F722", # allow Annotated[typ, some_func("some string")]
"E501",
"W503",
]
max-line-length = 88 # Respect black's line length (default 88),
exclude = [".tox", "venv"]


[tool.pytest.ini_options]
# Run pytest with all our checkers, and don't spam us with massive tracebacks on error
markers = [
Expand Down Expand Up @@ -126,3 +114,19 @@ commands =
pre-commit: pre-commit run --all-files {posargs}
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
"""


[tool.ruff]
src = ["src", "tests"]
line-length = 88
extend-ignore = [
"E501", # Line too long
"F811", # support typing.overload decorator
]
select = [
"C4", # flake8-comprehensions - https://beta.ruff.rs/docs/rules/#flake8-comprehensions-c4
"E", # pycodestyle errors - https://beta.ruff.rs/docs/rules/#error-e
"F", # pyflakes rules - https://beta.ruff.rs/docs/rules/#pyflakes-f
"W", # pycodestyle warnings - https://beta.ruff.rs/docs/rules/#warning-w
"I001", # isort
]
2 changes: 1 addition & 1 deletion src/dodal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from importlib.metadata import version

__version__ = version("dodal")
__version__ = version("dls-dodal")
del version

__all__ = ["__version__"]
Loading

0 comments on commit 612d000

Please sign in to comment.