Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
**/__pycache__/

**/node_modules/
target/
.venv/
.idea/

.generated_template
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

## Environment setup

Make sure you have installed `Python`, `uv`, `Node.js` and `pnpm` as documented.

Also, you need `bash`. If you are on Windows, you can use [Git for Windows](https://gitforwindows.org/).

```bash
# install dev dependencies and tools
uv sync

# activate venv
.venv\Scripts\activate


```
86 changes: 55 additions & 31 deletions copier.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,66 @@
_subdirectory: "templates/"

project_name:
type: str
help: Project name
default: pytauri-app
type: str
help: Project name
default: pytauri-app

package_name:
type: str
default: "{{ project_name | replace('-', '_')}}"
when: false
type: str
default: "{{ project_name | replace('-', '_')}}"
when: false

identifier:
type: str
help: Identifier
default: "com.username.{{ project_name }}"
type: str
help: Identifier
default: "com.username.{{ project_name }}"

with_rust:
type: bool
help: Do you want to use Rust?
default: false

template:
type: str
help: Choose your UI template
choices:
Vue: vue
React: react
Svelte: svelte
default: vue
type: str
help: Choose your UI template
choices:
Vue: vue
React: react
Svelte: svelte
default: vue

frontend_path:
type: str
default: "{% if with_rust == true %}./{% else %}./app/{% endif %}"
when: false

_message_after_copy: |
Template created! To get started run:
cd {{ project_name }}
pnpm install
uv venv --python-preference only-system
{%- if _copier_conf.os == "windows" %}
.venv\Scripts\activate
{%- else %}
source .venv/bin/activate
{%- endif %}
uv sync

For Desktop development, run:
pnpm tauri dev

For building a standalone app, see the `scripts/` folder.
{% if with_rust == true %}
Template created! To get started run:
cd {{ project_name }}
pnpm install
uv venv --python-preference only-system
{%- if _copier_conf.os == "windows" %}
.venv\Scripts\activate
{%- else %}
source .venv/bin/activate
{%- endif %}
uv sync

For Desktop development, run:
pnpm tauri dev

For building a standalone app, see the `scripts/` folder.
{% else %}
Template created! To get started run:
cd {{ project_name }}
pnpm install
pnpm build
uv venv
{%- if _copier_conf.os == "windows" %}
.venv\Scripts\activate
{%- else %}
source .venv/bin/activate
{%- endif %}
uv sync
{% endif %}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies = [
# [build-system]
"setuptools >= 80",
"setuptools-scm >= 8",
"copier>=9.10.3",
]

[tool.uv]
Expand Down
21 changes: 21 additions & 0 deletions scripts/create_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import shutil
from pathlib import Path

from copier import run_copy

if __name__ == "__main__":
TEMPLATE_DIR = Path(__file__).parent.parent
OUTPUT_DIR = Path(__file__).parent.parent / ".generated_template" / "pytauri-app"

kwargs = {
"project_name": "pytauri-app",
"identifier": "com.username.pytauri-app",
"template": "vue",
"with_rust": "false",
}

# Clean up old templates to ensure a new, clean one.
if OUTPUT_DIR.exists():
shutil.rmtree(OUTPUT_DIR)

run_copy(str(TEMPLATE_DIR), str(OUTPUT_DIR), vcs_ref="HEAD", data=kwargs)
1 change: 1 addition & 0 deletions templates/{{ '.' }}/{{ project_name }}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ dist-ssr

/.venv/
/target/
/dist/
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[project]
name = "{{ project_name }}"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
authors = [
{ name = "you" }
]
requires-python = ">=3.9"
dependencies = [
"pytauri-wheel>=0.8.0",
"pydantic == 2.*",
"anyio == 4.*"
]

[build-system]
requires = ["uv_build>=0.9.2,<0.10.0"]
build-backend = "uv_build"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys
from os import environ
from pathlib import Path

from anyio.from_thread import start_blocking_portal
from pydantic import BaseModel
from pytauri import Commands
from pytauri_wheel.lib import builder_factory, context_factory

SRC_TAURI_DIR = Path(__file__).parent.parent.parent / "app" / "src-tauri"


# If the DEV_SERVER env. variable is set, use that server for development (allows hot-reloading). Otherwise, use the built assets to serve the frontend.
DEV_SERVER = environ.get("DEV_SERVER") # Default: http://localhost:1420

if DEV_SERVER is not None:
tauri_config = {
"build": {
"frontendDist": DEV_SERVER,
},
}
else:
tauri_config = None


class Person(BaseModel):
name: str


commands: Commands = Commands()


@commands.command()
async def greet(body: Person) -> str:
return f"Hello, {body.name}! You've been greeted from Python {sys.version}!"


def main() -> int:
with start_blocking_portal("asyncio") as portal:
app = builder_factory().build(
context=context_factory(SRC_TAURI_DIR, tauri_config=tauri_config),
invoke_handler=commands.generate_handler(portal),
plugins=[],
)
exit_code = app.run_return()
return exit_code
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""The main entry point for the Tauri app."""

import sys
from multiprocessing import freeze_support

from {{ package_name }} import main

# - If you don't use `multiprocessing`, you can remove this line.
# - If you do use `multiprocessing` but without this line,
# you will get endless spawn loop of your application process.
# See: <https://pyinstaller.org/en/v6.11.1/common-issues-and-pitfalls.html#multi-processing>.
freeze_support()

sys.exit(main())
Loading
Loading