| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,54 +21,48 @@ def download_template_project(template_url: str, destination: str) -> None: | |||
| 21 | 21 | :param template_url: The URL of the template project. | |
| 22 | 22 | :param destination: The directory where the project will be created. | |
| 23 | 23 | """ | |
| 24 | - response = requests.get(template_url, stream=True) | ||
| 24 | + response: requests.Response = requests.get(template_url, stream=True) | ||
| 25 | 25 | ||
| 26 | 26 | if response.status_code == 200: | |
| 27 | 27 | with zipfile.ZipFile(io.BytesIO(response.content)) as z: | |
| 28 | 28 | z.extractall(destination) | |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | - def create_android_project(project_name: str, destination: str) -> bool: | ||
| 31 | + def create_android_project(project_name: str, destination: str) -> None: | ||
| 32 | 32 | """ | |
| 33 | 33 | Create a new Android project using a template. | |
| 34 | 34 | ||
| 35 | 35 | :param project_name: The name of the project. | |
| 36 | 36 | :param destination: The directory where the project will be created. | |
| 37 | - :return: True if the project was created successfully, False otherwise. | ||
| 38 | 37 | """ | |
| 39 | - android_template_url = "https://github.com/owenthcarey/pythonnative-workspace/blob/main/apps/templates/android_template.zip?raw=true" | ||
| 38 | + android_template_url = "https://github.com/owenthcarey/pythonnative-workspace/blob/main/libs/templates/android_template.zip?raw=true" | ||
| 40 | 39 | ||
| 41 | 40 | # Download and extract the Android template project | |
| 42 | 41 | download_template_project(android_template_url, destination) | |
| 43 | 42 | ||
| 44 | - return True | ||
| 45 | 43 | ||
| 46 | - | ||
| 47 | - def create_ios_project(project_name: str, destination: str) -> bool: | ||
| 44 | + def create_ios_project(project_name: str, destination: str) -> None: | ||
| 48 | 45 | """ | |
| 49 | 46 | Create a new iOS project using a template. | |
| 50 | 47 | ||
| 51 | 48 | :param project_name: The name of the project. | |
| 52 | 49 | :param destination: The directory where the project will be created. | |
| 53 | - :return: True if the project was created successfully, False otherwise. | ||
| 54 | 50 | """ | |
| 55 | - ios_template_url = "https://github.com/owenthcarey/pythonnative-workspace/blob/main/apps/templates/ios_template.zip?raw=true" | ||
| 51 | + ios_template_url = "https://github.com/owenthcarey/pythonnative-workspace/blob/main/libs/templates/ios_template.zip?raw=true" | ||
| 56 | 52 | ||
| 57 | 53 | # Download and extract the iOS template project | |
| 58 | 54 | download_template_project(ios_template_url, destination) | |
| 59 | 55 | ||
| 60 | - return True | ||
| 61 | - | ||
| 62 | 56 | ||
| 63 | 57 | def run_project(args: argparse.Namespace) -> None: | |
| 64 | 58 | """ | |
| 65 | 59 | Run the specified project. | |
| 66 | 60 | """ | |
| 67 | 61 | # Determine the platform | |
| 68 | - platform = args.platform | ||
| 62 | + platform: str = args.platform | ||
| 69 | 63 | ||
| 70 | 64 | # Define the build directory | |
| 71 | - build_dir = os.path.join(os.getcwd(), "build", platform) | ||
| 65 | + build_dir: str = os.path.join(os.getcwd(), "build", platform) | ||
| 72 | 66 | ||
| 73 | 67 | # Create the build directory if it doesn't exist | |
| 74 | 68 | os.makedirs(build_dir, exist_ok=True) | |
@@ -80,54 +74,66 @@ def run_project(args: argparse.Namespace) -> None: | |||
| 80 | 74 | create_ios_project("MyApp", build_dir) | |
| 81 | 75 | ||
| 82 | 76 | # Copy the user's Python code into the project | |
| 83 | - src_dir = os.path.join(os.getcwd(), "app") | ||
| 77 | + src_dir: str = os.path.join(os.getcwd(), "app") | ||
| 84 | 78 | ||
| 85 | 79 | # Adjust the destination directory for Android project | |
| 86 | 80 | if platform == "android": | |
| 87 | - dest_dir = os.path.join(build_dir, "android_template", "app", "src", "main", "python", "app") | ||
| 81 | + dest_dir: str = os.path.join( | ||
| 82 | + build_dir, "android_template", "app", "src", "main", "python", "app" | ||
| 83 | + ) | ||
| 88 | 84 | elif platform == "ios": | |
| 89 | - dest_dir = os.path.join(build_dir, "app") # Adjust this based on your iOS project structure | ||
| 85 | + dest_dir: str = os.path.join( | ||
| 86 | + build_dir, "app" | ||
| 87 | + ) # Adjust this based on your iOS project structure | ||
| 90 | 88 | ||
| 91 | 89 | # Create the destination directory if it doesn't exist | |
| 92 | 90 | os.makedirs(dest_dir, exist_ok=True) | |
| 93 | 91 | shutil.copytree(src_dir, dest_dir, dirs_exist_ok=True) | |
| 94 | 92 | ||
| 95 | 93 | # Install any necessary Python packages into the project environment | |
| 96 | - requirements_file = os.path.join(os.getcwd(), "requirements.txt") | ||
| 94 | + requirements_file: str = os.path.join(os.getcwd(), "requirements.txt") | ||
| 97 | 95 | # TODO: Fill in with actual commands for installing Python packages | |
| 98 | 96 | ||
| 99 | 97 | # Run the project | |
| 100 | 98 | if platform == "android": | |
| 101 | 99 | # Change to the Android project directory | |
| 102 | - android_project_dir = os.path.join(build_dir, "android_template") | ||
| 100 | + android_project_dir: str = os.path.join(build_dir, "android_template") | ||
| 103 | 101 | os.chdir(android_project_dir) | |
| 104 | 102 | ||
| 105 | 103 | # Add executable permissions to the gradlew script | |
| 106 | - gradlew_path = os.path.join(android_project_dir, "gradlew") | ||
| 107 | - os.chmod(gradlew_path, | ||
| 108 | - 0o755) # this makes the file executable for the user | ||
| 104 | + gradlew_path: str = os.path.join(android_project_dir, "gradlew") | ||
| 105 | + os.chmod(gradlew_path, 0o755) # this makes the file executable for the user | ||
| 109 | 106 | ||
| 110 | 107 | # Build the Android project and install it on the device | |
| 111 | - jdk_path = subprocess.check_output( | ||
| 112 | - ["brew", "--prefix", "openjdk@17"]).decode().strip() | ||
| 113 | - env = os.environ.copy() | ||
| 108 | + jdk_path: str = ( | ||
| 109 | + subprocess.check_output(["brew", "--prefix", "openjdk@17"]).decode().strip() | ||
| 110 | + ) | ||
| 111 | + env: dict[str, str] = os.environ.copy() | ||
| 114 | 112 | env["JAVA_HOME"] = jdk_path | |
| 115 | 113 | subprocess.run(["./gradlew", "installDebug"], check=True, env=env) | |
| 116 | 114 | ||
| 117 | 115 | # Run the Android app | |
| 118 | 116 | # Assumes that the package name of your app is "com.example.myapp" and the main activity is "MainActivity" | |
| 119 | 117 | # Replace "com.example.myapp" and ".MainActivity" with your actual package name and main activity | |
| 120 | - subprocess.run(["adb", "shell", "am", "start", "-n", | ||
| 121 | - "com.pythonnative.android_template/.MainActivity"], | ||
| 122 | - check=True) | ||
| 118 | + subprocess.run( | ||
| 119 | + [ | ||
| 120 | + "adb", | ||
| 121 | + "shell", | ||
| 122 | + "am", | ||
| 123 | + "start", | ||
| 124 | + "-n", | ||
| 125 | + "com.pythonnative.android_template/.MainActivity", | ||
| 126 | + ], | ||
| 127 | + check=True, | ||
| 128 | + ) | ||
| 123 | 129 | ||
| 124 | 130 | ||
| 125 | 131 | def clean_project(args: argparse.Namespace) -> None: | |
| 126 | 132 | """ | |
| 127 | 133 | Clean the specified project. | |
| 128 | 134 | """ | |
| 129 | 135 | # Define the build directory | |
| 130 | - build_dir = os.path.join(os.getcwd(), "build") | ||
| 136 | + build_dir: str = os.path.join(os.getcwd(), "build") | ||
| 131 | 137 | ||
| 132 | 138 | # Check if the build directory exists | |
| 133 | 139 | if os.path.exists(build_dir): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments