-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
4,371 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Bug Report | ||
about: Incorrect or unexpected behavior | ||
title: "[BUG]" | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
|
||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Desktop (please complete the following information if applicable):** | ||
|
||
- OS: [e.g. iOS] | ||
- Browser: [e.g. chrome, safari] | ||
- Version: [e.g. 22] | ||
|
||
**Smartphone (please complete the following information if applicable):** | ||
|
||
- Device: [e.g. iPhone6] | ||
- OS: [e.g. iOS8.1] | ||
- Browser: [e.g. stock browser, safari] | ||
- Version: [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
name: Feature Request | ||
about: Functionality you want that is not yet supported | ||
title: "[FEATURE REQUEST]" | ||
labels: enhancement | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: lint | ||
run-name: ${{ github.actor }} is linting the package | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
pull_request: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set Up Python Environment | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Install Poetry | ||
uses: snok/[email protected] | ||
|
||
- name: Install dependencies | ||
run: poetry install --with dev | ||
|
||
- name: Run Ruff | ||
run: poetry run ruff check . | ||
|
||
- name: Run MyPy | ||
run: poetry run mypy . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: release | ||
run-name: ${{ github.actor }} is uploading a new release to PyPI | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set Up Python 3.10 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install Poetry | ||
uses: snok/[email protected] | ||
env: | ||
ACTIONS_ALLOW_UNSECURE_COMMANDS: "true" | ||
|
||
- name: Get release version | ||
run: echo "RELEASE_VERSION=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV | ||
|
||
- name: Build And Publish Python Package | ||
run: poetry publish --build | ||
env: | ||
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: tests | ||
run-name: ${{ github.actor }} is testing the package | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
pull_request: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.11", "3.12"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set Up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Poetry | ||
uses: snok/[email protected] | ||
|
||
- name: Install dependencies | ||
run: poetry install --with dev | ||
|
||
- name: Run Tests | ||
run: poetry run pytest tests/ --cov=./ --cov-report=xml | ||
|
||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
directory: ./ | ||
env_vars: OS,PYTHON | ||
fail_ci_if_error: true | ||
files: ./coverage.xml,!./cache | ||
flags: tests | ||
name: codecov-umbrella | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
verbose: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Local files | ||
.DS_Store | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"recommendations": [ | ||
"charliermarsh.ruff", | ||
"DavidAnson.vscode-markdownlint", | ||
"eamodio.gitlens", | ||
"github.vscode-github-actions", | ||
"ms-toolsai.jupyter", | ||
"ms-toolsai.jupyter-keymap", | ||
"ms-toolsai.jupyter-renderers", | ||
"ms-python.mypy", | ||
"ms-python.python", | ||
"ms-python.vscode-pylance", | ||
"ms-toolsai.vscode-jupyter-cell-tags", | ||
"ms-toolsai.vscode-jupyter-slideshow" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Pytest", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"module": "pytest", | ||
"args": [ | ||
"-vv", | ||
"-s", | ||
"${file}" // Runs tests in the current file, you can customize this | ||
], | ||
"console": "integratedTerminal", | ||
"justMyCode": false | ||
}, | ||
{ | ||
"name": "Python Debugger: Current File", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "integratedTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"files.autoSave": "onFocusChange", | ||
"editor.formatOnSave": true, | ||
"editor.formatOnSaveMode": "file", | ||
"files.insertFinalNewline": true, | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true, | ||
"[python]": { | ||
"editor.rulers": [88], | ||
"editor.tabSize": 4, | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": "explicit" | ||
}, | ||
"editor.defaultFormatter": "charliermarsh.ruff" | ||
}, | ||
"[json]": { | ||
"editor.tabSize": 2, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[yml]": { | ||
"editor.tabSize": 2, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[markdown]": { | ||
"editor.formatOnSave": false | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"""This module contains all functionality related to the Mirascope CLI.""" | ||
|
||
from .main import app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"""The Mirascope CLI commands module""" | ||
from .add import add_command | ||
from .init import init_command | ||
from .remove import remove_command | ||
from .status import status_command | ||
from .use import use_command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
"""The add command for the Mirascope CLI.""" | ||
import os | ||
|
||
from typer import Argument | ||
|
||
from ..constants import CURRENT_REVISION_KEY, LATEST_REVISION_KEY | ||
from ..enums import MirascopeCommand | ||
from ..schemas import MirascopeCliVariables | ||
from ..utils import ( | ||
check_status, | ||
get_prompt_versions, | ||
get_user_mirascope_settings, | ||
parse_prompt_file_name, | ||
prompts_directory_files, | ||
run_format_command, | ||
update_version_text_file, | ||
write_prompt_to_template, | ||
) | ||
|
||
|
||
def add_command( | ||
prompt_file_name: str = Argument( | ||
help="Prompt file to add", | ||
autocompletion=prompts_directory_files, | ||
parser=parse_prompt_file_name, | ||
default="", | ||
), | ||
): | ||
"""Adds the given prompt to the specified version directory. | ||
The contents of the prompt in the user's prompts directory are copied to the version | ||
directory with the next revision number, and the version file is updated with the | ||
new revision. | ||
Args: | ||
prompt_file_name: The name of the prompt file to add. | ||
Raises: | ||
FileNotFoundError: If the file is not found in the specified prompts directory. | ||
""" | ||
mirascope_settings = get_user_mirascope_settings() | ||
version_directory_path = mirascope_settings.versions_location | ||
prompt_directory_path = mirascope_settings.prompts_location | ||
version_file_name = mirascope_settings.version_file_name | ||
auto_tag = mirascope_settings.auto_tag | ||
# Check status before continuing | ||
used_prompt_path = check_status(mirascope_settings, prompt_file_name) | ||
if not used_prompt_path: | ||
print("No changes detected.") | ||
return | ||
prompt_versions_directory = os.path.join(version_directory_path, prompt_file_name) | ||
|
||
# Check if prompt file exists | ||
if not os.path.exists(f"{prompt_directory_path}/{prompt_file_name}.py"): | ||
raise FileNotFoundError( | ||
f"Prompt {prompt_file_name}.py not found in {prompt_directory_path}" | ||
) | ||
# Create prompt versions directory if it doesn't exist | ||
if not os.path.exists(prompt_versions_directory): | ||
os.makedirs(prompt_versions_directory) | ||
version_file_path = os.path.join(prompt_versions_directory, version_file_name) | ||
versions = get_prompt_versions(version_file_path) | ||
|
||
# Open user's prompt file | ||
user_prompt_file = os.path.join(prompt_directory_path, f"{prompt_file_name}.py") | ||
with open(user_prompt_file, "r+", encoding="utf-8") as file: | ||
# Increment revision id | ||
if versions.latest_revision is None: | ||
# first revision | ||
revision_id = "0001" | ||
else: | ||
# default branch with incrementation | ||
latest_revision_id = versions.latest_revision | ||
revision_id = f"{int(latest_revision_id)+1:04}" | ||
# Create revision file | ||
revision_file = os.path.join( | ||
prompt_versions_directory, f"{revision_id}_{prompt_file_name}.py" | ||
) | ||
custom_variables = MirascopeCliVariables( | ||
prev_revision_id=versions.current_revision, | ||
revision_id=revision_id, | ||
) | ||
prompt_file = file.read() | ||
|
||
if auto_tag: | ||
new_prompt_file = write_prompt_to_template( | ||
prompt_file, MirascopeCommand.USE, custom_variables | ||
) | ||
# Replace contents of user's prompt file with new prompt file with tags | ||
file.seek(0) | ||
file.write(new_prompt_file) | ||
file.truncate() | ||
# Reset file pointer to beginning of file for revision file read | ||
file.seek(0) | ||
run_format_command(user_prompt_file) | ||
with open( | ||
revision_file, | ||
"w+", | ||
encoding="utf-8", | ||
) as file2: | ||
file2.write( | ||
write_prompt_to_template( | ||
prompt_file, MirascopeCommand.ADD, custom_variables | ||
) | ||
) | ||
keys_to_update = { | ||
CURRENT_REVISION_KEY: revision_id, | ||
LATEST_REVISION_KEY: revision_id, | ||
} | ||
update_version_text_file(version_file_path, keys_to_update) | ||
if revision_file: | ||
run_format_command(revision_file) | ||
print("Adding " f"{prompt_versions_directory}/{revision_id}_{prompt_file_name}.py") |
Oops, something went wrong.