Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typing checks to ui #45

Merged
merged 15 commits into from
Nov 29, 2022
2 changes: 2 additions & 0 deletions .github/workflows/make_bundle_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
branches:
- main
paths:
- 'build_installers.py'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about the rationale behind constraining the runs to this file only. otherwise PR lgtm

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @potating-potato, so we do not want to trigger a bundle build unless something changed in the file in charge of creating the bundles. I added this on this PR to make the other PRs simpler.

workflow_call:
inputs:
event_name:
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/typing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: typing
goanpeca marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- 'constructor-manager/**'
- 'constructor-manager-cli/**'
- 'constructor-manager-ui/**'
workflow_dispatch:

jobs:
test:
name: ${{ matrix.platform }} py${{ matrix.python-version }}
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: [ubuntu-latest]
python-version: ['3.10']

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
cd constructor-manager-ui
pip install -e ".[typing]"
pip install -e ".[testing]"
pip list

- name: Typing
run: |
cd constructor-manager-ui
pip install -e ".[pyqt5]"
cd src
mypy constructor_manager_ui --always-true=PYQT5 --always-false=PYSIDE2 --always-false=PYQT6 --always-false=PYSIDE6
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,37 @@ repos:
rev: v4.4.0
hooks:
- id: check-docstring-first
exclude: ^constructor-manager-ui/src/constructor_manager_ui/style/images.py
- id: end-of-file-fixer
exclude: ^constructor-manager-ui/src/constructor_manager_ui/style/images.py
- id: trailing-whitespace
exclude: ^constructor-manager-ui/src/constructor_manager_ui/style/images.py
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
hooks:
- id: pyupgrade
args: [--py38-plus, --keep-runtime-typing]
exclude: ^constructor-manager-ui/src/constructor_manager_ui/style/images.py
- repo: https://github.com/myint/autoflake
rev: v2.0.0
hooks:
- id: autoflake
args: ["--in-place", "--remove-all-unused-imports"]
exclude: ^constructor-manager-ui/src/constructor_manager_ui/style/images.py
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
exclude: ^constructor-manager-ui/src/constructor_manager_ui/style/images.py
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports>=1.9.0]
args: ["-j8", "--ignore=TYP001,E501,W503"]
exclude: ^constructor-manager-ui/src/constructor_manager_ui/style/images.py
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.143
hooks:
- id: ruff
exclude: ^constructor-manager-ui/src/constructor_manager_ui/style/images.py
16 changes: 16 additions & 0 deletions constructor-manager-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,24 @@ Install testing dependencies:
pip install -e .[testing]
```

Install typing dependencies:

```bash
pip install -e .[typing]
```

Run the application:

```bash
constructor-manager-ui napari
```

Generate resources file:

Once installed, run the command below to generate the resource file:

```bash
constructor-manager-ui-qrc
```

You need to have pyqt5 installed.
13 changes: 10 additions & 3 deletions constructor-manager-ui/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ build-backend = "setuptools.build_meta"
[tool.black]
line-length = 79

[tool.isort]
profile = "black"
line_length = 79
[tool.mypy]
ignore_missing_imports = true
exclude = [
"tests",
]
show_error_codes = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
check_untyped_defs = true
15 changes: 9 additions & 6 deletions constructor-manager-ui/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ where = src
[options.entry_points]
console_scripts =
constructor-manager-ui = constructor_manager_ui.cli:run
constructor-manager-ui-qrc = constructor_manager_ui.style.utils:generate_resource_file

[options.extras_require]
testing =
Expand All @@ -53,9 +54,11 @@ pyqt5 =
pyqt5
pyside2 =
pyside2

[mypy]
exclude = venv|tests

[mypy-packaging.*]
ignore_missing_imports = True
typing =
mypy
typing-extensions
types-requests
types-urllib3
typing-inspect
mypy-extensions
types-PyYAML
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Constructor manager."""
37 changes: 25 additions & 12 deletions constructor-manager-ui/src/constructor_manager_ui/data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
"""Mock data for the installation manager dialog UI."""
from typing import Dict, Optional, List, NamedTuple

PACKAGE_NAME = "napari"
INSTALL_INFORMATION = {
# Types
VersionInfo = Dict[str, str]


class PackageData(NamedTuple):
name: str
version: str
source: str
build: Optional[str]
plugin: bool


PACKAGE_NAME: str = "napari"
INSTALL_INFORMATION: Dict[str, VersionInfo] = {
"current_version": {
"version": "v0.4.16",
"last_modified": "July 27, 2022",
Expand All @@ -11,22 +24,22 @@
"last_modified": "April 5, 2022",
},
}
UPDATE_AVAILABLE_VERSION = "v0.4.17"
PACKAGES = [
UPDATE_AVAILABLE_VERSION: str = "v0.4.17"
PACKAGES: List[PackageData] = [
# Package:
# Name - Version - Source - Build - Related package (plugin or package itself)
("napari", "0.4.16", "pip", None, True),
("napari-console", "0.1.6", "pip", None, True),
(
PackageData("napari", "0.4.16", "pip", None, True),
PackageData("napari-console", "0.1.6", "pip", None, True),
PackageData(
"napari-live-recording",
"0.1.6rc",
"conda/conda-forge",
"pyhd3eb1b0_0",
True,
),
("napari-microscope", "0.7", "pip", None, True),
("alabaster", "0.7.12", "conda/conda-forge", "pyhd3eb1b0_0", False),
("aom", "3.5.0", "conda/conda-forge", "pyhd3eb1b0_0", False),
("appdirs", "1.4.4", "conda/conda-forge", "pyhd3eb1b0_0", False),
("appnope", "0.1.2", "conda/conda-forge", "pyhd3eb1b0_0", False),
PackageData("napari-microscope", "0.7", "pip", None, True),
PackageData("alabaster", "0.7.12", "conda/conda-forge", "pyhd3eb1b0_0", False),
PackageData("aom", "3.5.0", "conda/conda-forge", "pyhd3eb1b0_0", False),
PackageData("appdirs", "1.4.4", "conda/conda-forge", "pyhd3eb1b0_0", False),
PackageData("appnope", "0.1.2", "conda/conda-forge", "pyhd3eb1b0_0", False),
]
26 changes: 16 additions & 10 deletions constructor-manager-ui/src/constructor_manager_ui/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Constructor manager main interface."""

import sys
from typing import Optional

from qtpy.QtCore import QSize, Qt, QTimer, Signal
from qtpy.QtGui import QBrush, QMovie
Expand All @@ -23,11 +24,15 @@
QWidget,
)

# To get mock data
from constructor_manager_ui.data import (
INSTALL_INFORMATION,
PACKAGES,
UPDATE_AVAILABLE_VERSION,
)

# To setup image resources for .qss file
from constructor_manager_ui.style import images # noqa
goanpeca marked this conversation as resolved.
Show resolved Hide resolved
from constructor_manager_ui.style.utils import update_styles

# Packages table constants
Expand All @@ -36,8 +41,9 @@


class SpinnerWidget(QWidget):
def __init__(self, text, parent=None):
def __init__(self, text: str, parent: Optional[QWidget] = None):
super().__init__(parent=parent)

# Widgets for text and loading gif
self.text_label = QLabel(text)
spinner_label = QLabel()
Expand All @@ -54,7 +60,7 @@ def __init__(self, text, parent=None):
self.setLayout(layout)
self.spinner_movie.start()

def set_text(self, text):
def set_text(self, text: str):
self.text_label.setText(text)

def show(self):
Expand All @@ -71,7 +77,7 @@ class UpdateWidget(QWidget):
install_version = Signal(str)
skip_version = Signal(str)

def __init__(self, package_name, parent=None):
def __init__(self, package_name: str, parent: Optional[QWidget] = None):
super().__init__(parent=parent)
self.package_name = package_name
self.update_available_version = None
Expand Down Expand Up @@ -157,15 +163,15 @@ def __init__(self, packages, visible_packages=RELATED_PACKAGES, parent=None):
self.visible_packages = visible_packages
self.setup()

def _create_item(self, text, related_package):
def _create_item(self, text: str, related_package: bool):
item = QTableWidgetItem(text)
if related_package:
background_brush = QBrush(Qt.black)
background_brush = QBrush(Qt.GlobalColor.black)
else:
background_brush = QBrush(Qt.darkGray)
background_brush = QBrush(Qt.GlobalColor.darkGray)
item.setBackground(background_brush)
if not related_package:
foreground_brush = QBrush(Qt.black)
foreground_brush = QBrush(Qt.GlobalColor.black)
item.setForeground(foreground_brush)
return item

Expand Down Expand Up @@ -228,9 +234,9 @@ def change_detailed_info_visibility(self, state):
class InstallationManagerDialog(QDialog):
def __init__(
self,
package_name,
package_name: str,
install_information,
parent=None,
parent: Optional[QWidget] = None,
):
super().__init__(parent=parent)
self.package_name = package_name
Expand Down Expand Up @@ -422,7 +428,7 @@ def uninstall(self):
print("Uninstall")


def main(package_name):
def main(package_name: str):
"""Run the main interface.

Parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Constructor manager."""
Loading