-
-
Notifications
You must be signed in to change notification settings - Fork 369
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 ToolCache
typing
#964
Add ToolCache
typing
#964
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The ``ToolCache`` and its tools are now typed to better support IDE hints and auto-completion. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,29 @@ | |
from collections import defaultdict | ||
from collections.abc import Mapping | ||
from pathlib import Path | ||
from typing import DefaultDict | ||
from typing import TYPE_CHECKING, DefaultDict | ||
|
||
import requests | ||
from cookiecutter.main import cookiecutter | ||
|
||
from briefcase.config import AppConfig | ||
from briefcase.console import Console, Log | ||
from briefcase.integrations.download import Download | ||
from briefcase.integrations.subprocess import Subprocess | ||
|
||
if TYPE_CHECKING: | ||
# Tools are imported only for type checking | ||
# to avoid circular import errors. | ||
import git as git_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was almost ready to approve this PR... and then I remembered something. That opens up a bunch of questions:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's probably possible if something monkeypatched
Not currently. But if we wanted to ensure this was avoided, we could change |
||
|
||
from briefcase.integrations.android_sdk import AndroidSDK | ||
from briefcase.integrations.docker import Docker, DockerAppContext | ||
from briefcase.integrations.download import Download | ||
from briefcase.integrations.flatpak import Flatpak | ||
from briefcase.integrations.java import JDK | ||
from briefcase.integrations.linuxdeploy import LinuxDeploy | ||
from briefcase.integrations.rcedit import RCEdit | ||
from briefcase.integrations.subprocess import Subprocess | ||
from briefcase.integrations.visualstudio import VisualStudio | ||
from briefcase.integrations.wix import WiX | ||
|
||
|
||
# TODO: Implement Tool base class | ||
|
@@ -25,11 +39,29 @@ class Tool(ABC): | |
|
||
|
||
class ToolCache(Mapping): | ||
# Briefcase tools | ||
android_sdk: AndroidSDK | ||
app_context: Subprocess | DockerAppContext | ||
docker: Docker | ||
download: Download | ||
flatpak: Flatpak | ||
git: git_ | ||
java: JDK | ||
linuxdeploy: LinuxDeploy | ||
rcedit: RCEdit | ||
subprocess: Subprocess | ||
visualstudio: VisualStudio | ||
wix: WiX | ||
xcode: bool | ||
xcode_cli: bool | ||
|
||
# Python stdlib tools | ||
platform = platform | ||
os = os | ||
shutil = shutil | ||
sys = sys | ||
|
||
# Third party tools | ||
cookiecutter = staticmethod(cookiecutter) | ||
requests = requests | ||
|
||
|
@@ -71,10 +103,6 @@ def __init__( | |
) | ||
) | ||
|
||
# Built-in tools without any external dependencies | ||
Subprocess.verify(tools=self) | ||
Download.verify(tools=self) | ||
|
||
def __getitem__(self, app: AppConfig) -> ToolCache: | ||
return self.app_tools[app] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this after discovering Ned said it should be part of the default
exclude
.I'll revert back to
# pragma: no cover
if you're not a fan.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd actually prefer it here; manual
#pragma
calls are sometimes inevitable, but are a code smell IMHO. My comment was more about having a fairly big block of code that isn't ever executed that only exists to keep an IDE happy, and the resulting problems ensuring that code is correct.