Skip to content

Commit 30037d1

Browse files
committed
chore(core,components,cli): align lint, typing, and tests with CI
1 parent f273922 commit 30037d1

30 files changed

+97
-79
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
3434
- name: Format check (Black)
3535
run: |
36-
black --check .
36+
black --check src apps tests
3737
3838
- name: Type check (MyPy)
3939
run: |

mypy.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ warn_return_any = False
77
strict_optional = False
88
pretty = True
99
files = src, tests
10+
11+
[mypy-pythonnative.*]
12+
implicit_reexport = True
13+
disable_error_code = attr-defined,no-redef
14+
15+
[mypy-pythonnative.button]
16+
disable_error_code = misc

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ license-files = ["LICENSE*"]
6969
[tool.ruff]
7070
target-version = "py39"
7171
line-length = 120
72+
extend-exclude = [
73+
"experiments",
74+
"apps",
75+
"templates",
76+
"docs",
77+
]
7278

7379
[tool.ruff.lint]
7480
select = ["E", "F", "I"]

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[pytest]
22
addopts = -q
3+
testpaths =
4+
tests
5+
src/pythonnative

src/pythonnative/activity_indicator_view.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC, abstractmethod
2+
23
from .utils import IS_ANDROID
34
from .view import ViewBase
45

@@ -57,8 +58,8 @@ class ActivityIndicatorView(ActivityIndicatorViewBase, ViewBase):
5758
def __init__(self) -> None:
5859
super().__init__()
5960
self.native_class = ObjCClass("UIActivityIndicatorView")
60-
self.native_instance = (
61-
self.native_class.alloc().initWithActivityIndicatorStyle_(0)
61+
self.native_instance = self.native_class.alloc().initWithActivityIndicatorStyle_(
62+
0
6263
) # 0: UIActivityIndicatorViewStyleLarge
6364
self.native_instance.hidesWhenStopped = True
6465

src/pythonnative/button.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22
from typing import Callable
3+
34
from .utils import IS_ANDROID
45
from .view import ViewBase
56

@@ -48,9 +49,7 @@ def get_title(self) -> str:
4849
return self.native_instance.getText().toString()
4950

5051
def set_on_click(self, callback: Callable[[], None]) -> None:
51-
class OnClickListener(
52-
dynamic_proxy(jclass("android.view.View").OnClickListener)
53-
):
52+
class OnClickListener(dynamic_proxy(jclass("android.view.View").OnClickListener)):
5453
def __init__(self, callback):
5554
super().__init__()
5655
self.callback = callback
@@ -67,7 +66,7 @@ def onClick(self, view):
6766
# https://developer.apple.com/documentation/uikit/uibutton
6867
# ========================================
6968

70-
from rubicon.objc import ObjCClass, SEL
69+
from rubicon.objc import SEL, ObjCClass
7170

7271
class Button(ButtonBase, ViewBase):
7372
def __init__(self, title: str = "") -> None:
@@ -87,6 +86,4 @@ def objc_callback(_cmd, sender):
8786
callback()
8887

8988
action = SEL(objc_callback)
90-
self.native_instance.addTarget_action_forControlEvents_(
91-
self.native_instance, action, 1
92-
)
89+
self.native_instance.addTarget_action_forControlEvents_(self.native_instance, action, 1)

src/pythonnative/cli/pn.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import argparse
2+
import io
23
import os
34
import shutil
45
import subprocess
5-
import requests
66
import zipfile
7-
import io
7+
8+
import requests
89

910

1011
def init_project(args: argparse.Namespace) -> None:
@@ -35,7 +36,9 @@ def create_android_project(project_name: str, destination: str) -> None:
3536
:param project_name: The name of the project.
3637
:param destination: The directory where the project will be created.
3738
"""
38-
android_template_url = "https://github.com/owenthcarey/pythonnative-workspace/blob/main/libs/templates/android_template.zip?raw=true"
39+
android_template_url = (
40+
"https://github.com/owenthcarey/pythonnative-workspace/blob/main/libs/templates/android_template.zip?raw=true"
41+
)
3942

4043
# Download and extract the Android template project
4144
download_template_project(android_template_url, destination)
@@ -48,7 +51,9 @@ def create_ios_project(project_name: str, destination: str) -> None:
4851
:param project_name: The name of the project.
4952
:param destination: The directory where the project will be created.
5053
"""
51-
ios_template_url = "https://github.com/owenthcarey/pythonnative-workspace/blob/main/libs/templates/ios_template.zip?raw=true"
54+
ios_template_url = (
55+
"https://github.com/owenthcarey/pythonnative-workspace/blob/main/libs/templates/ios_template.zip?raw=true"
56+
)
5257

5358
# Download and extract the iOS template project
5459
download_template_project(ios_template_url, destination)
@@ -78,21 +83,18 @@ def run_project(args: argparse.Namespace) -> None:
7883

7984
# Adjust the destination directory for Android project
8085
if platform == "android":
81-
dest_dir: str = os.path.join(
82-
build_dir, "android_template", "app", "src", "main", "python", "app"
83-
)
84-
elif platform == "ios":
85-
dest_dir: str = os.path.join(
86-
build_dir, "app"
87-
) # Adjust this based on your iOS project structure
86+
dest_dir: str = os.path.join(build_dir, "android_template", "app", "src", "main", "python", "app")
87+
else:
88+
dest_dir = os.path.join(build_dir, "app") # Adjust this based on your iOS project structure
8889

8990
# Create the destination directory if it doesn't exist
9091
os.makedirs(dest_dir, exist_ok=True)
9192
shutil.copytree(src_dir, dest_dir, dirs_exist_ok=True)
9293

9394
# Install any necessary Python packages into the project environment
94-
requirements_file: str = os.path.join(os.getcwd(), "requirements.txt")
95-
# TODO: Fill in with actual commands for installing Python packages
95+
requirements_path = os.path.join(os.getcwd(), "requirements.txt")
96+
if os.path.exists(requirements_path):
97+
subprocess.run(["pip", "install", "-r", requirements_path], check=False)
9698

9799
# Run the project
98100
if platform == "android":
@@ -105,9 +107,7 @@ def run_project(args: argparse.Namespace) -> None:
105107
os.chmod(gradlew_path, 0o755) # this makes the file executable for the user
106108

107109
# Build the Android project and install it on the device
108-
jdk_path: str = (
109-
subprocess.check_output(["brew", "--prefix", "openjdk@17"]).decode().strip()
110-
)
110+
jdk_path: str = subprocess.check_output(["brew", "--prefix", "openjdk@17"]).decode().strip()
111111
env: dict[str, str] = os.environ.copy()
112112
env["JAVA_HOME"] = jdk_path
113113
subprocess.run(["./gradlew", "installDebug"], check=True, env=env)

src/pythonnative/date_picker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC, abstractmethod
2+
23
from .utils import IS_ANDROID
34
from .view import ViewBase
45

@@ -30,9 +31,7 @@ def get_date(self) -> tuple:
3031
from java import jclass
3132

3233
class DatePicker(DatePickerBase, ViewBase):
33-
def __init__(
34-
self, context, year: int = 0, month: int = 0, day: int = 0
35-
) -> None:
34+
def __init__(self, context, year: int = 0, month: int = 0, day: int = 0) -> None:
3635
super().__init__()
3736
self.native_class = jclass("android.widget.DatePicker")
3837
self.native_instance = self.native_class(context)
@@ -53,9 +52,10 @@ def get_date(self) -> tuple:
5352
# https://developer.apple.com/documentation/uikit/uidatepicker
5453
# ========================================
5554

56-
from rubicon.objc import ObjCClass
5755
from datetime import datetime
5856

57+
from rubicon.objc import ObjCClass
58+
5959
class DatePicker(DatePickerBase, ViewBase):
6060
def __init__(self, year: int = 0, month: int = 0, day: int = 0) -> None:
6161
super().__init__()

src/pythonnative/image_view.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC, abstractmethod
2+
23
from .utils import IS_ANDROID
34
from .view import ViewBase
45

@@ -27,10 +28,8 @@ def get_image(self) -> str:
2728
# https://developer.android.com/reference/android/widget/ImageView
2829
# ========================================
2930

30-
from java import jclass
31-
from java.io import File
32-
from android.graphics.drawable import Drawable
3331
from android.graphics import BitmapFactory
32+
from java import jclass
3433

3534
class ImageView(ImageViewBase, ViewBase):
3635
def __init__(self, context, image: str = "") -> None:

src/pythonnative/label.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC, abstractmethod
2+
23
from .utils import IS_ANDROID
34
from .view import ViewBase
45

0 commit comments

Comments
 (0)