Skip to content

Commit

Permalink
Merge pull request #26 from dougollerenshaw/fix_examples_in_app
Browse files Browse the repository at this point in the history
Fix examples in app
  • Loading branch information
dougollerenshaw authored Sep 20, 2024
2 parents 9a37fac + 4796553 commit 9a1f5f7
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ build/
codeaide.spec

# Ignore dist directory
dist/
dist/

# Ignore .dmg files
*.dmg
118 changes: 118 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# CodeAide

CodeAide is a chat application that leverages LLMs to generate code based on users' natural language requests and allows users to run the code directly from the application.

## Building the Application

Follow these steps to build CodeAide as a standalone application for macOS:

Prerequisites

- Python 3.7 or higher
- pip (Python package installer)
- Homebrew (for installing create-dmg)

### Step 1: Install Required Python Packages

```
pip install PyQt5 pyinstaller
```

### Step 2: Package the Application

1. Navigate to your project directory:
```
cd path/to/CodeAIde
```
2. Run PyInstaller:
```
pyinstaller --windowed --onefile --add-data "codeaide/examples.yaml:codeaide" codeaide.py
```
This command creates a single executable file in the `dist` folder.
Note: Make sure the path to examples.yaml is correct. If you're in the root of your project, it should be "codeaide/examples.yaml" as shown above.
### Step 3: Create an Application Bundle
1. Create the necessary directories:
```
mkdir -p CodeAide.app/Contents/MacOS
mkdir -p CodeAide.app/Contents/Resources
```
2. Move your executable:
```
mv dist/codeaide CodeAide.app/Contents/MacOS/CodeAide
```
3. Create an `Info.plist` file in `CodeAide.app/Contents/`:
```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>CodeAide</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.codeaide</string>
<key>CFBundleName</key>
<string>CodeAide</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
</dict>
</plist>
```

4. (Optional) Add an icon:
- Create a .icns file for your app icon
- Place it in `CodeAide.app/Contents/Resources/icon.icns`

### Step 4: Create the DMG

1. Install create-dmg:
```
brew install create-dmg
```
2. Create the DMG:
```
create-dmg \
--volname "CodeAide Installer" \
--window-pos 200 120 \
--window-size 800 400 \
--icon-size 100 \
--icon "CodeAide.app" 200 190 \
--hide-extension "CodeAide.app" \
--app-drop-link 600 185 \
"CodeAide.dmg" \
"CodeAide.app"
```
### Step 5: Test The Application
Always test the DMG on a clean macOS installation to ensure it works as expected.
Troubleshooting
If you encounter issues with resource files not being found:
1. Ensure all necessary files (like `examples.yaml`) are included in the PyInstaller command with the correct path.
2. Check the console output for any error messages.
3. Verify that the paths in `general_utils.py` are correct for both development and packaged environments.
Updating the Application
When updating the application:
1. Increment the version number in `Info.plist`.
2. Rebuild the application following the steps above.
3. Create a new DMG with the updated version.
Notes
- This README assumes you're building on macOS. The process may differ for other operating systems.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ The following features do not currently exist, but adding them in the future wou
Contributions to CodeAIde are welcome! Please feel free to submit a Pull Request.
For detailed instructions on how to build CodeAide as a standalone application, please refer to the [BUILD.md](BUILD.md) file in the root of this repository.
## License
This project is licensed under the MIT License - see the license file for details.
Expand Down
18 changes: 15 additions & 3 deletions codeaide/utils/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,38 @@

def get_project_root():
"""Get the project root directory."""
# Always use UTILS_DIR as the starting point
return os.path.abspath(os.path.join(UTILS_DIR, "..", ".."))


def get_resource_path(relative_path):
"""Get absolute path to resource, works for dev and for PyInstaller"""
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = get_project_root()
return os.path.join(base_path, relative_path)


def get_examples_file_path():
"""Get the path to the examples.yaml file."""
return os.path.join(get_project_root(), "codeaide", "examples.yaml")
return get_resource_path("codeaide/examples.yaml")


def load_examples():
"""Load and return all examples from the YAML file."""
examples_file = get_examples_file_path()
print(f"Attempting to load examples from: {examples_file}") # Debug print
if not os.path.exists(examples_file):
print(f"Examples file not found: {examples_file}")
return []

try:
with open(examples_file, "r", encoding="utf-8") as file:
data = yaml.safe_load(file)
return data.get("examples", [])
examples = data.get("examples", [])
print(f"Loaded {len(examples)} examples") # Debug print
return examples
except yaml.YAMLError as e:
print(f"YAML Error: {str(e)}")
return []
Expand Down

0 comments on commit 9a1f5f7

Please sign in to comment.