Skip to content

Commit 12e0412

Browse files
committed
Update pn CLI
1 parent dc038fd commit 12e0412

File tree

1 file changed

+74
-6
lines changed
  • libs/pythonnative/cli

1 file changed

+74
-6
lines changed

libs/pythonnative/cli/pn.py

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,96 @@
11
import argparse
2+
import os
3+
import shutil
4+
import subprocess
25

36

4-
def init_project(args):
7+
def init_project(args: argparse.Namespace) -> None:
58
"""
69
Initialize a new PythonNative project.
710
"""
811
# TODO: Implementation
912

1013

11-
def run_project(args):
14+
def create_android_project(project_name: str, destination: str) -> bool:
15+
"""
16+
Create a new Android project using android command.
17+
18+
:param project_name: The name of the project.
19+
:param destination: The directory where the project will be created.
20+
:return: True if the project was created successfully, False otherwise.
21+
"""
22+
# The command to create a new Android project
23+
command = f"cd {destination} && android create project --name {project_name} --path . --target android-30 --package com.example.{project_name} --activity MainActivity"
24+
25+
# Run the command
26+
process = subprocess.run(command, shell=True, check=True, text=True)
27+
28+
return process.returncode == 0
29+
30+
31+
def create_ios_project(project_name: str, destination: str) -> bool:
32+
"""
33+
Create a new Xcode project using xcodeproj gem.
34+
35+
:param project_name: The name of the project.
36+
:param destination: The directory where the project will be created.
37+
:return: True if the project was created successfully, False otherwise.
38+
"""
39+
# The command to create a new Xcode project
40+
command = f"cd {destination} && xcodeproj new {project_name}.xcodeproj"
41+
42+
# Run the command
43+
process = subprocess.run(command, shell=True, check=True, text=True)
44+
45+
return process.returncode == 0
46+
47+
48+
def run_project(args: argparse.Namespace) -> None:
1249
"""
1350
Run the specified project.
1451
"""
15-
# TODO: Implementation
52+
# Determine the platform
53+
platform = args.platform
54+
55+
# Define the build directory
56+
build_dir = os.path.join(os.getcwd(), "build", platform)
57+
58+
# Create the build directory if it doesn't exist
59+
os.makedirs(build_dir, exist_ok=True)
60+
61+
# Generate the required project files
62+
if platform == "android":
63+
create_android_project("MyApp", build_dir)
64+
elif platform == "ios":
65+
create_ios_project("MyApp", build_dir)
1666

67+
# Copy the user's Python code into the project
68+
src_dir = os.path.join(os.getcwd(), "app")
69+
dest_dir = os.path.join(build_dir, "app") # You might need to adjust this depending on the project structure
70+
shutil.copytree(src_dir, dest_dir, dirs_exist_ok=True)
1771

18-
def clean_project(args):
72+
# Install any necessary Python packages into the project environment
73+
requirements_file = os.path.join(os.getcwd(), "requirements.txt")
74+
# TODO: Fill in with actual commands for installing Python packages
75+
76+
# Run the project
77+
# TODO: Fill in with actual commands for running the project
78+
79+
80+
def clean_project(args: argparse.Namespace) -> None:
1981
"""
2082
Clean the specified project.
2183
"""
22-
# TODO: Implementation
84+
# Define the build directory
85+
build_dir = os.path.join(os.getcwd(), "build")
86+
87+
# Check if the build directory exists
88+
if os.path.exists(build_dir):
89+
# Delete the build directory
90+
shutil.rmtree(build_dir)
2391

2492

25-
def main():
93+
def main() -> None:
2694
parser = argparse.ArgumentParser(prog="pn", description="PythonNative CLI")
2795
subparsers = parser.add_subparsers()
2896

0 commit comments

Comments
 (0)