Skip to content

Commit

Permalink
User ruff linter and formatter (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas authored May 15, 2024
1 parent a2a6c5f commit eddcf10
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
interval: monthly
groups:
gha-dependencies:
patterns:
Expand Down
28 changes: 8 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,19 @@ repos:
- id: trailing-whitespace
exclude: miscellaneous/structures/SiO2.xyz

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
hooks:
- id: ruff-format
exclude: ^docs/.*
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.3
hooks:
- id: yamlfmt

- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: [--count, --show-source, --statistics]
additional_dependencies:
- flake8-bugbear

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: [--profile, black, --filter-files]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
Expand Down
28 changes: 20 additions & 8 deletions home/app_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""Module that contains widgets for managing AiiDAlab applications."""

from subprocess import CalledProcessError

import ipywidgets as ipw
Expand Down Expand Up @@ -207,7 +207,7 @@ def __init__(self, app, minimalistic=False):
self.app.observe(
self._refresh_prereleases, names=["has_prereleases", "installed_version"]
)
self._refresh_prereleases(change=dict(owner=self.app)) # initialize
self._refresh_prereleases(change={"owner": self.app}) # initialize

children = [
ipw.HBox([self.header_warning]),
Expand Down Expand Up @@ -347,19 +347,25 @@ def _refresh_widget_state(self, _=None):
self.install_button.icon = (
""
if can_install and not detached
else warn_or_ban_icon if can_install else ""
else warn_or_ban_icon
if can_install
else ""
)
if self.app.compatible:
self.install_button.tooltip = (
""
if can_install and not detached
else tooltip_danger if can_install else ""
else tooltip_danger
if can_install
else ""
)
else:
self.install_button.tooltip = (
""
if installed and not detached
else tooltip_danger if installed else tooltip_incompatible
else tooltip_danger
if installed
else tooltip_incompatible
)
self.install_button.description = (
"Install"
Expand All @@ -376,7 +382,9 @@ def _refresh_widget_state(self, _=None):
self.uninstall_button.tooltip = (
""
if can_uninstall and not detached
else tooltip_danger if can_uninstall else ""
else tooltip_danger
if can_uninstall
else ""
)

# Update the update button state.
Expand All @@ -390,13 +398,17 @@ def _refresh_widget_state(self, _=None):
self.update_button.icon = (
"arrow-circle-up"
if can_update and not detached
else warn_or_ban_icon if can_update else ""
else warn_or_ban_icon
if can_update
else ""
)
self.update_button.button_style = "success" if can_update else ""
self.update_button.tooltip = (
""
if can_update and not detached
else tooltip_danger if can_update else ""
else tooltip_danger
if can_update
else ""
)

# Update the version_selector widget state.
Expand Down
12 changes: 4 additions & 8 deletions home/app_store.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""AiiDAlab app store."""

import logging

import ipywidgets as ipw
Expand All @@ -21,7 +21,7 @@ def __init__(self):
self.index = load_app_registry_index()
except RuntimeError as error:
logger.warning(error)
self.index = dict(apps=[], categories=[])
self.index = {"apps": [], "categories": []}
self.output = ipw.Output()

# Apps per page.
Expand Down Expand Up @@ -120,12 +120,8 @@ def change_vis_list(self, _=None):

if self.category_filter.value:
all_apps = self.apps_to_display
self.apps_to_display = (
[]
) # clear the array that contains all the apps to be displayed
self.app_corresponding_categories = (
[]
) # create a parallel array that contains corresponding category names
self.apps_to_display = [] # clear the array that contains all the apps to be displayed
self.app_corresponding_categories = [] # create a parallel array that contains corresponding category names
# iterate over all categories
for category in self.category_filter.value:
category_key = self.category_title_key_mapping[category]
Expand Down
6 changes: 3 additions & 3 deletions home/start_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AiidaLabHome:
def __init__(self):
self.config_fn = ".launcher.json"
self.output = ipw.Output()
self._app_widgets = dict()
self._app_widgets = {}

def _create_app_widget(self, name):
"""Create the widget representing the app on the home screen."""
Expand Down Expand Up @@ -93,7 +93,7 @@ def write_config(self, config):

def read_config(self):
if path.exists(self.config_fn):
return json.load(open(self.config_fn, "r"))
return json.load(open(self.config_fn))
return {"order": [], "hidden": []} # default config

def render(self):
Expand Down Expand Up @@ -125,7 +125,7 @@ def load_apps(self):
apps.sort(key=lambda x: order.index(x) if x in order else -1)
config["order"] = apps
self.write_config(config)
return ["home"] + apps
return ["home", *apps]

def move_updown(self, name, delta):
"""Move the app up/down on the start page."""
Expand Down
6 changes: 3 additions & 3 deletions home/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def load_start_py(name):
except TypeError:
return mod.get_start_widget(appbase=appbase, jupbase=jupbase)
except Exception: # pylint: disable=broad-except
return ipw.HTML("<pre>{}</pre>".format(sys.exc_info()))
return ipw.HTML(f"<pre>{sys.exc_info()}</pre>")


def load_start_md(name):
"""Load app appearance from a Markdown file."""
fname = path.join(AIIDALAB_APPS, name, "start.md")
try:
md_src = open(fname).read()
md_src = md_src.replace("](./", "](../{}/".format(name))
md_src = md_src.replace("](./", f"](../{name}/")
html = markdown(md_src)

# open links in new window/tab
Expand All @@ -52,7 +52,7 @@ def load_start_md(name):
return ipw.HTML(html)

except Exception as exc: # pylint: disable=broad-except
return ipw.HTML("Could not load start.md: {}".format(str(exc)))
return ipw.HTML(f"Could not load start.md: {exc!s}")


def load_logo(app):
Expand Down
3 changes: 1 addition & 2 deletions home/widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""AiiDAlab basic widgets."""

from threading import Timer
Expand Down Expand Up @@ -104,7 +103,7 @@ class AppStatusInfoWidget(ipw.HTML):
"and avoid compatibility isssues."
)

MESSAGES_UPDATES = {
MESSAGES_UPDATES = { # noqa: RUF012
AppStatus.CANNOT_REACH_REGISTRY: f'<div title="Unable to reach the registry server ({AIIDALAB_REGISTRY}).">'
f'<font color="{Theme.COLORS.GRAY}">{Theme.ICONS.APP_UPDATE_AVAILABLE_UNKNOWN} '
"Cannot reach server.</font></div>",
Expand Down
31 changes: 31 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[build-system]
# this version is required to support reading of version in setup.cfg
requires = ["setuptools>=46.4.0"]
build-backend = "setuptools.build_meta"

[tool.ruff]
line-length = 88
show-fixes = true
target-version = "py38"

[tool.ruff.lint]
ignore = ["E501", "E402", "B904", "TRY003"]
select = [
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"N", # pep8-naming
"PLE", # pylint error rules
"PLW", # pylint warning rules
"PLC", # pylint convention rules
"RUF", # ruff-specific rules
"TRY", # Tryceratops
"UP" # pyupgrade
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["ARG001"]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf8 -*-
"""This file is required for editable installs of the package."""

from setuptools import setup

setup()

0 comments on commit eddcf10

Please sign in to comment.