| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f273922 commit 30037d1
30 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,7 +33,7 @@ jobs: | |||
| 33 | 33 | ||
| 34 | 34 | - name: Format check (Black) | |
| 35 | 35 | run: | | |
| 36 | - black --check . | ||
| 36 | + black --check src apps tests | ||
| 37 | 37 | ||
| 38 | 38 | - name: Type check (MyPy) | |
| 39 | 39 | run: | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,3 +7,10 @@ warn_return_any = False | |||
| 7 | 7 | strict_optional = False | |
| 8 | 8 | pretty = True | |
| 9 | 9 | 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,12 @@ license-files = ["LICENSE*"] | |||
| 69 | 69 | [tool.ruff] | |
| 70 | 70 | target-version = "py39" | |
| 71 | 71 | line-length = 120 | |
| 72 | + extend-exclude = [ | ||
| 73 | + "experiments", | ||
| 74 | + "apps", | ||
| 75 | + "templates", | ||
| 76 | + "docs", | ||
| 77 | + ] | ||
| 72 | 78 | ||
| 73 | 79 | [tool.ruff.lint] | |
| 74 | 80 | select = ["E", "F", "I"] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,2 +1,5 @@ | |||
| 1 | 1 | [pytest] | |
| 2 | 2 | addopts = -q | |
| 3 | + testpaths = | ||
| 4 | + tests | ||
| 5 | + src/pythonnative | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | from abc import ABC, abstractmethod | |
| 2 | + | ||
| 2 | 3 | from .utils import IS_ANDROID | |
| 3 | 4 | from .view import ViewBase | |
| 4 | 5 | ||
@@ -57,8 +58,8 @@ class ActivityIndicatorView(ActivityIndicatorViewBase, ViewBase): | |||
| 57 | 58 | def __init__(self) -> None: | |
| 58 | 59 | super().__init__() | |
| 59 | 60 | 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 | ||
| 62 | 63 | ) # 0: UIActivityIndicatorViewStyleLarge | |
| 63 | 64 | self.native_instance.hidesWhenStopped = True | |
| 64 | 65 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | from abc import ABC, abstractmethod | |
| 2 | 2 | from typing import Callable | |
| 3 | + | ||
| 3 | 4 | from .utils import IS_ANDROID | |
| 4 | 5 | from .view import ViewBase | |
| 5 | 6 | ||
@@ -48,9 +49,7 @@ def get_title(self) -> str: | |||
| 48 | 49 | return self.native_instance.getText().toString() | |
| 49 | 50 | ||
| 50 | 51 | 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)): | ||
| 54 | 53 | def __init__(self, callback): | |
| 55 | 54 | super().__init__() | |
| 56 | 55 | self.callback = callback | |
@@ -67,7 +66,7 @@ def onClick(self, view): | |||
| 67 | 66 | # https://developer.apple.com/documentation/uikit/uibutton | |
| 68 | 67 | # ======================================== | |
| 69 | 68 | ||
| 70 | - from rubicon.objc import ObjCClass, SEL | ||
| 69 | + from rubicon.objc import SEL, ObjCClass | ||
| 71 | 70 | ||
| 72 | 71 | class Button(ButtonBase, ViewBase): | |
| 73 | 72 | def __init__(self, title: str = "") -> None: | |
@@ -87,6 +86,4 @@ def objc_callback(_cmd, sender): | |||
| 87 | 86 | callback() | |
| 88 | 87 | ||
| 89 | 88 | 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) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,11 @@ | |||
| 1 | 1 | import argparse | |
| 2 | + import io | ||
| 2 | 3 | import os | |
| 3 | 4 | import shutil | |
| 4 | 5 | import subprocess | |
| 5 | - import requests | ||
| 6 | 6 | import zipfile | |
| 7 | - import io | ||
| 7 | + | ||
| 8 | + import requests | ||
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | 11 | def init_project(args: argparse.Namespace) -> None: | |
@@ -35,7 +36,9 @@ def create_android_project(project_name: str, destination: str) -> None: | |||
| 35 | 36 | :param project_name: The name of the project. | |
| 36 | 37 | :param destination: The directory where the project will be created. | |
| 37 | 38 | """ | |
| 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 | + ) | ||
| 39 | 42 | ||
| 40 | 43 | # Download and extract the Android template project | |
| 41 | 44 | download_template_project(android_template_url, destination) | |
@@ -48,7 +51,9 @@ def create_ios_project(project_name: str, destination: str) -> None: | |||
| 48 | 51 | :param project_name: The name of the project. | |
| 49 | 52 | :param destination: The directory where the project will be created. | |
| 50 | 53 | """ | |
| 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 | + ) | ||
| 52 | 57 | ||
| 53 | 58 | # Download and extract the iOS template project | |
| 54 | 59 | download_template_project(ios_template_url, destination) | |
@@ -78,21 +83,18 @@ def run_project(args: argparse.Namespace) -> None: | |||
| 78 | 83 | ||
| 79 | 84 | # Adjust the destination directory for Android project | |
| 80 | 85 | 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 | ||
| 88 | 89 | ||
| 89 | 90 | # Create the destination directory if it doesn't exist | |
| 90 | 91 | os.makedirs(dest_dir, exist_ok=True) | |
| 91 | 92 | shutil.copytree(src_dir, dest_dir, dirs_exist_ok=True) | |
| 92 | 93 | ||
| 93 | 94 | # 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) | ||
| 96 | 98 | ||
| 97 | 99 | # Run the project | |
| 98 | 100 | if platform == "android": | |
@@ -105,9 +107,7 @@ def run_project(args: argparse.Namespace) -> None: | |||
| 105 | 107 | os.chmod(gradlew_path, 0o755) # this makes the file executable for the user | |
| 106 | 108 | ||
| 107 | 109 | # 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() | ||
| 111 | 111 | env: dict[str, str] = os.environ.copy() | |
| 112 | 112 | env["JAVA_HOME"] = jdk_path | |
| 113 | 113 | subprocess.run(["./gradlew", "installDebug"], check=True, env=env) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | from abc import ABC, abstractmethod | |
| 2 | + | ||
| 2 | 3 | from .utils import IS_ANDROID | |
| 3 | 4 | from .view import ViewBase | |
| 4 | 5 | ||
@@ -30,9 +31,7 @@ def get_date(self) -> tuple: | |||
| 30 | 31 | from java import jclass | |
| 31 | 32 | ||
| 32 | 33 | 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: | ||
| 36 | 35 | super().__init__() | |
| 37 | 36 | self.native_class = jclass("android.widget.DatePicker") | |
| 38 | 37 | self.native_instance = self.native_class(context) | |
@@ -53,9 +52,10 @@ def get_date(self) -> tuple: | |||
| 53 | 52 | # https://developer.apple.com/documentation/uikit/uidatepicker | |
| 54 | 53 | # ======================================== | |
| 55 | 54 | ||
| 56 | - from rubicon.objc import ObjCClass | ||
| 57 | 55 | from datetime import datetime | |
| 58 | 56 | ||
| 57 | + from rubicon.objc import ObjCClass | ||
| 58 | + | ||
| 59 | 59 | class DatePicker(DatePickerBase, ViewBase): | |
| 60 | 60 | def __init__(self, year: int = 0, month: int = 0, day: int = 0) -> None: | |
| 61 | 61 | super().__init__() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | from abc import ABC, abstractmethod | |
| 2 | + | ||
| 2 | 3 | from .utils import IS_ANDROID | |
| 3 | 4 | from .view import ViewBase | |
| 4 | 5 | ||
@@ -27,10 +28,8 @@ def get_image(self) -> str: | |||
| 27 | 28 | # https://developer.android.com/reference/android/widget/ImageView | |
| 28 | 29 | # ======================================== | |
| 29 | 30 | ||
| 30 | - from java import jclass | ||
| 31 | - from java.io import File | ||
| 32 | - from android.graphics.drawable import Drawable | ||
| 33 | 31 | from android.graphics import BitmapFactory | |
| 32 | + from java import jclass | ||
| 34 | 33 | ||
| 35 | 34 | class ImageView(ImageViewBase, ViewBase): | |
| 36 | 35 | def __init__(self, context, image: str = "") -> None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | from abc import ABC, abstractmethod | |
| 2 | + | ||
| 2 | 3 | from .utils import IS_ANDROID | |
| 3 | 4 | from .view import ViewBase | |
| 4 | 5 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments