mirror of
https://github.com/rio-labs/rio.git
synced 2025-12-30 09:49:44 -06:00
migrate scripts to uv
This commit is contained in:
@@ -7,7 +7,7 @@ Rio even better. Ready to jump in? We recommend checking out the
|
||||
how things work. All our code lives on GitHub, so you can easily see what's
|
||||
happening and get involved.
|
||||
|
||||
**Quick tip:** [A quick chat on discord](https://discord.gg/7ejXaPwhyH) with a
|
||||
**Quick tip:** [A quick chat on discord](https://discord.gg/7ejXaPwhyH) with a
|
||||
maintainer before diving into a big pull request can save you time. That way,
|
||||
you can make sure your idea aligns with Rio's goals! We're very active on
|
||||
discord - you can expect to get an answer in minutes when we aren't asleep.
|
||||
@@ -31,23 +31,23 @@ changes, or close it.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- You have [Python](https://www.python.org/) version 3.10 or higher
|
||||
- You have [Python](https://www.python.org/) version 3.10 or higher
|
||||
installed
|
||||
- You have [Rye](https://rye.astral.sh/) version 0.33.0 or higher
|
||||
installed
|
||||
- You have [Node.js](https://nodejs.org/) version 20.0 or higher installed
|
||||
- You are familiar with [Git](https://git-scm.com/)
|
||||
- You have [Uv](https://docs.astral.sh/uv/getting-started/installation/)
|
||||
version 0.6.5 or higher installed
|
||||
- You have [Node.js](https://nodejs.org/) version 20.0 or higher installed
|
||||
- You are familiar with [Git](https://git-scm.com/)
|
||||
|
||||
### Project structure
|
||||
|
||||
- `frontend/` - TypeScript code for the Rio frontend
|
||||
- `raw-icons/` - In addition to the official material icons, Rio ships with some
|
||||
- `frontend/` - TypeScript code for the Rio frontend
|
||||
- `raw-icons/` - In addition to the official material icons, Rio ships with some
|
||||
of its own. This directory contains any and all custom icons.
|
||||
- `rio/` - Python code for the Rio backend
|
||||
- `scripts/` - Contains scripts which are tangentially related to Rio, but not
|
||||
- `rio/` - Python code for the Rio backend
|
||||
- `scripts/` - Contains scripts which are tangentially related to Rio, but not
|
||||
used during runtime. For example, you can find benchmarking and publishing
|
||||
scripts here
|
||||
- `tests/` - Contains tests for Rio
|
||||
- `tests/` - Contains tests for Rio
|
||||
|
||||
### Development Setup
|
||||
|
||||
@@ -70,13 +70,13 @@ git clone git@github.com:YOUR_USERNAME/rio.git
|
||||
cd rio
|
||||
```
|
||||
|
||||
Use rye to install all Python dependencies:
|
||||
Use uv to install all Python dependencies:
|
||||
|
||||
```bash
|
||||
rye sync --all-features
|
||||
uv sync --all-extras
|
||||
```
|
||||
|
||||
(`--all-features` will install everything necessary for local apps to work in
|
||||
(`--all-extras` will install everything necessary for local apps to work in
|
||||
addition to websites. Since some of this functionality is tested in the test
|
||||
suite, tests would fail without installing these dependencies.)
|
||||
|
||||
@@ -97,17 +97,10 @@ Install dev dependencies using `npm`:
|
||||
npm install
|
||||
```
|
||||
|
||||
The previous command doesn't reliably install `sass` for some reason. To be
|
||||
on the safe side, install it manually:
|
||||
|
||||
```bash
|
||||
npm install sass
|
||||
```
|
||||
|
||||
Now build the frontend:
|
||||
|
||||
```bash
|
||||
rye run dev-build
|
||||
uv run scripts/build_frontend.py
|
||||
```
|
||||
|
||||
## Conventions & Consistency
|
||||
@@ -118,10 +111,10 @@ of things. The only thing worse than a bad solution is two good ones.
|
||||
|
||||
To avoid this, we've decided on a few conventions used throughout Rio:
|
||||
|
||||
- Event handlers are always written in present tense: `on_change`, `on_move`,
|
||||
- Event handlers are always written in present tense: `on_change`, `on_move`,
|
||||
etc., NOT past tense (`on_changed`, `on_moved`).
|
||||
|
||||
- Whenever a value has physical units attached, prefer to use SI base units. For
|
||||
- Whenever a value has physical units attached, prefer to use SI base units. For
|
||||
example, durations are measured in seconds, not milliseconds.
|
||||
|
||||
Occasionally it can make sense to break this rule. For example, when
|
||||
@@ -135,17 +128,17 @@ To avoid this, we've decided on a few conventions used throughout Rio:
|
||||
be preferable to all of the above. This way times can be expressed in any
|
||||
unit the user prefers.
|
||||
|
||||
- Avoid negatives. For example, use `is_visible` instead of `is_hidden`. Nobody
|
||||
- Avoid negatives. For example, use `is_visible` instead of `is_hidden`. Nobody
|
||||
likes to think around corners. Here's some more examples
|
||||
|
||||
- `is_visible` instead of `is_hidden`
|
||||
- `is_sensitive` instead of `is_insensitive`
|
||||
- `is_active` instead of `is_disabled`
|
||||
- `is_visible` instead of `is_hidden`
|
||||
- `is_sensitive` instead of `is_insensitive`
|
||||
- `is_active` instead of `is_disabled`
|
||||
|
||||
Along the same lines, **absolutely avoid double negatives**. Never, ever,
|
||||
ever use names like `is_not_hidden` or `dont_hide_something`.
|
||||
Along the same lines, **absolutely avoid double negatives**. Never, ever,
|
||||
ever use names like `is_not_hidden` or `dont_hide_something`.
|
||||
|
||||
- Python code follows Python naming conventions, such as all_lower_case for
|
||||
- Python code follows Python naming conventions, such as all_lower_case for
|
||||
variables and functions, and CamelCase for classes.
|
||||
|
||||
JavaScript, TypeScript & JSON follow JavaScript naming conventions, such as
|
||||
@@ -153,7 +146,7 @@ To avoid this, we've decided on a few conventions used throughout Rio:
|
||||
|
||||
Files use all_lower_case.
|
||||
|
||||
- When naming a dictionary after its contents, name it `keys_to_values`, rather
|
||||
- When naming a dictionary after its contents, name it `keys_to_values`, rather
|
||||
than e.g. `values_by_key`. For example, `ids_to_instances` or `names_to_id`.
|
||||
It is of course also perfectly fine to use a different name if it makes more
|
||||
sense in your particular context.
|
||||
@@ -162,7 +155,7 @@ To avoid this, we've decided on a few conventions used throughout Rio:
|
||||
that don't stick to this convention. Feel free to report and/or change them if
|
||||
you spot any.
|
||||
|
||||
- _In general,_ avoid importing values from modules. Import the modules
|
||||
- _In general,_ avoid importing values from modules. Import the modules
|
||||
themselves, then include the module name when accessing values. Also avoid
|
||||
renaming modules when imported.
|
||||
|
||||
@@ -205,7 +198,7 @@ To avoid this, we've decided on a few conventions used throughout Rio:
|
||||
import components as comps
|
||||
```
|
||||
|
||||
- **Use type hints!** They don't take long to type, but help out **you**, anyone
|
||||
else reading your code, and most importantly, your type checker. They really
|
||||
pay off in the long run. Not to mention that they force you to think about
|
||||
your data models a bit more critically, leading to better code.
|
||||
- **Use type hints!** They don't take long to type, but help out **you**, anyone
|
||||
else reading your code, and most importantly, your type checker. They really
|
||||
pay off in the long run. Not to mention that they force you to think about
|
||||
your data models a bit more critically, leading to better code.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import typing as t
|
||||
from pathlib import Path
|
||||
|
||||
import rio.utils
|
||||
@@ -10,7 +11,21 @@ OUTPUT_DIR = PROJECT_ROOT_DIR / "rio" / "frontend files"
|
||||
ASSETS_DIR = OUTPUT_DIR / "assets"
|
||||
|
||||
|
||||
def build(*extra_args: str) -> None:
|
||||
def main() -> None:
|
||||
if "--release" in sys.argv:
|
||||
mode = "release"
|
||||
else:
|
||||
mode = "dev"
|
||||
|
||||
build(mode=mode)
|
||||
|
||||
|
||||
def build(mode: t.Literal["dev", "release"]) -> None:
|
||||
if mode == "release":
|
||||
extra_args = []
|
||||
else:
|
||||
extra_args = ["--mode", "development", "--minify", "false"]
|
||||
|
||||
# Build with vite
|
||||
npx(
|
||||
"vite",
|
||||
@@ -30,13 +45,13 @@ def build(*extra_args: str) -> None:
|
||||
)
|
||||
|
||||
|
||||
def dev_build() -> None:
|
||||
build("--mode", "development", "--minify", "false")
|
||||
|
||||
|
||||
def npx(*args: str | Path) -> None:
|
||||
subprocess.run(
|
||||
["npx", *map(str, args)],
|
||||
check=True,
|
||||
shell=sys.platform == "win32",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -5,6 +5,7 @@ import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import build_frontend
|
||||
import revel
|
||||
|
||||
import rio.cli.project_setup
|
||||
@@ -20,7 +21,7 @@ def main() -> None:
|
||||
ensure_no_uncommitted_changes()
|
||||
ensure_up_to_date_with_remote()
|
||||
|
||||
build_frontend()
|
||||
build_frontend.build(mode="release")
|
||||
ensure_tests_pass()
|
||||
|
||||
revel.success("Everything is in order.")
|
||||
@@ -68,15 +69,10 @@ def ensure_up_to_date_with_remote() -> None:
|
||||
revel.fatal("Local branch is not up-to-date with remote")
|
||||
|
||||
|
||||
def build_frontend() -> None:
|
||||
subprocess.run(
|
||||
["rye", "run", "build"],
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
def ensure_tests_pass() -> None:
|
||||
process = subprocess.run(["rye", "test", "--", "-x", "--disable-warnings"])
|
||||
process = subprocess.run(
|
||||
["uv", "run", "pytest", "tests", "--", "-x", "--disable-warnings"]
|
||||
)
|
||||
|
||||
if process.returncode == 0:
|
||||
revel.print("Everything is in order. Publishing...")
|
||||
@@ -174,8 +170,8 @@ def make_new_release() -> None:
|
||||
subprocess.run(["git", "push"], check=True)
|
||||
|
||||
# Publish
|
||||
subprocess.run(["rye", "build", "--clean"], check=True)
|
||||
subprocess.run(["rye", "publish"], check=True)
|
||||
subprocess.run(["uv", "build"], check=True)
|
||||
subprocess.run(["uv", "publish"], check=True)
|
||||
|
||||
# Create a tag
|
||||
version = str(get_version())
|
||||
|
||||
Reference in New Issue
Block a user