Skip to content

Commit

Permalink
[Release] Update the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
reboot-dev-bot committed Apr 4, 2024
1 parent 922069b commit a8aaef6
Show file tree
Hide file tree
Showing 20 changed files with 508 additions and 243 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Directory created from using the 'rsm' CLI tool.
.rsm/
/.rsm/

# The recommended virtualenv directory.
/.venv/
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.13
20 changes: 12 additions & 8 deletions .rsmrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
# `.rsmrc` as the working directory so that any paths that we specify
# below are relative to it.
protoc --working-directory=.
dev --working-directory=.
dev --protoc-watch
dev run --working-directory=.
dev run --protoc-watch

# Generate code from our '.proto' files in 'api/'.
protoc --output-directory=api/
Expand All @@ -39,19 +39,23 @@ protoc api/
protoc -- --resemble_python_out=backend/api --resemble_react_out=web/src/api

# Watch if any generated files are modified.
dev --watch=backend/api/**/*.py
dev run --watch=backend/api/**/*.py

# Watch if any of our source files are modified.
dev --watch=backend/src/**/*.py
dev run --watch=backend/src/**/*.py

# PYTHONPATH must be explicitly set to pick up generated code.
dev --env=PYTHONPATH=backend/api/
dev run --env=PYTHONPATH=backend/api/

# Tell `rsm` that this is a Python application.
dev --python
dev run --python

# Save state between chaos restarts.
dev --name=hello
dev run --name=hello

# Run the application!
dev backend/src/main.py
dev run backend/src/main.py

# When running `rsm dev expunge`, the state we want to remove is that of the
# "hello" application, since that's what we were running with `rsm dev run`.
dev expunge --name=hello
64 changes: 24 additions & 40 deletions .tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,30 @@ ls -l api/ backend/src/ web/ 2> /dev/null > /dev/null || {
exit 1
}

# Create and activate a virtual environment so that we don't pollute the
# system's Python installation.
VENV="./.resemble-hello-venv"
python -m venv $VENV
source $VENV/bin/activate

# If `REBOOT_RESEMBLE_WHL_FILE` is set, have it refer to an absolute non-symlink
# (= canonical) path.
if [ -v REBOOT_RESEMBLE_WHL_FILE ]; then
REBOOT_RESEMBLE_WHL_FILE=$(readlink --canonicalize $REBOOT_RESEMBLE_WHL_FILE)
# Convert symlinks to files that we need to mutate into copies.
for file in "requirements.lock" "requirements-dev.lock" "pyproject.toml"; do
cp "$file" "${file}.tmp"
rm "$file"
mv "${file}.tmp" "$file"
done

# Use the published Resemble pip package by default, but allow the test system
# to override them with a different value.
if [ -n "$REBOOT_RESEMBLE_WHL_FILE" ]; then
# Install the `reboot-resemble` package from the specified path explicitly, over-
# writing the version from `pyproject.toml`.
rye remove --no-sync reboot-resemble
rye remove --no-sync --dev reboot-resemble
rye add --dev reboot-resemble --absolute --path=$REBOOT_RESEMBLE_WHL_FILE
fi

# Normally, tests will use the published Resemble PyPI package; this is what
# happens when this test is run from `.github/workflows/*.yml`.
#
# However, when there is a need to test changes to the Resemble package itself,
# the test system can override the default and use an explicit local wheel file
# instead.
REBOOT_RESEMBLE_PACKAGE=${REBOOT_RESEMBLE_WHL_FILE:-"reboot-resemble"}

# Manually install the Resemble pip package before installing the
# requirements.txt. This allows us to install unreleased versions of
# the Resemble package during tests.
pip install $REBOOT_RESEMBLE_PACKAGE

# Save the pip show info on the package so that we can compare it after
# installing the rest of the requirements, to check that our custom whl hasn't
# been overwritten.
resemble_info=$(pip show reboot-resemble)

pip install -r backend/src/requirements.txt

# Double check that we haven't reinstalled another version of the
# reboot-resemble package.
if [ "$resemble_info" != "$(pip show reboot-resemble)" ]; then
echo "ERROR: reboot-resemble whl overwritten by pip install. Are the package versions out of sync?"
exit 1
fi
# Create and activate a virtual environment.
rye sync --no-lock
source .venv/bin/activate

rsm protoc

mypy --python-executable=$VENV/bin/python backend/
mypy backend/

pytest backend/

Expand All @@ -62,6 +44,11 @@ pytest backend/
# We will only do this if this machine has the `docker` command installed. That
# means this is skipped on e.g. GitHub's Mac OS X runners.
if command -v docker &> /dev/null; then
if [ -n "$REBOOT_RESEMBLE_WHL_FILE" ]; then
# If `REBOOT_RESEMBLE_WHL_FILE` is set, have it refer to an absolute non-symlink
# (= canonical) path.
REBOOT_RESEMBLE_WHL_FILE=$(readlink --canonicalize $REBOOT_RESEMBLE_WHL_FILE)
fi
# Since Docker can't follow symlinks to files outside the build context, we
# can't build the Docker image in a directory where the Dockerfile is a symlink.
# That situation occurs when e.g. running this test on Bazel. Follow the symlink
Expand All @@ -71,6 +58,3 @@ if command -v docker &> /dev/null; then
popd
fi


# Clean up.
rm -rf ./.resemble-hello-venv
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ filegroup(
# Files that may be created by activity in this directory, such
# as manually following the steps of the `README.md` file, but which
# are not part of the "source code" of this repository.
".venv/**/*",
".resemble-hello-venv/**/*",
".pytest_cache/**/*",
"api/gen/**/*.js",
Expand Down
21 changes: 11 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ RUN mkdir $NVM_DIR && \
# Our container will run as `root`, so the root user must load `nvm` on login.
RUN echo ". $NVM_DIR/nvm.sh" >> /root/.bashrc

### Our application.

# First ONLY copy and install the requirements, so that changes outside
# `requirements.txt` don't force a re-install of all dependencies.
#
# Note that this will install the Resemble library and CLI.
COPY requirements.lock requirements.txt
RUN pip install -r requirements.txt

### Unpublished Resemble package.
# If you plan to use this Dockerfile for your own project, you may omit this
# section; it is useful only for Reboot's internal development. Outside of
Expand All @@ -70,17 +79,9 @@ COPY .unpublished-*-wheel/*.whl .unpublished-resemble-wheel/
# If `.unpublished-resemble-wheel/` was empty or did not exist, the following
# `ls` will fail and instead of `pip install` we'll run `echo`, which means this
# RUN has no effects in that case.
RUN (ls ./.unpublished-resemble-wheel/*.whl && pip install ./.unpublished-resemble-wheel/*.whl) \
RUN (ls ./.unpublished-resemble-wheel/*.whl && pip install --force-reinstall ./.unpublished-resemble-wheel/*.whl) \
|| echo "No unpublished wheels to install."

### Our application.

# First ONLY copy and install the requirements, so that changes outside
# `requirements.txt` don't force a re-install of all dependencies.
#
# Note that this will install the Resemble library and CLI.
COPY backend/src/requirements.txt requirements.txt
RUN pip install -r requirements.txt
### End of interlude.

# Next, copy the API definition and generate Resemble code. This step is also
# separate so it is only repeated if the `api/` code changes.
Expand Down
Loading

0 comments on commit a8aaef6

Please sign in to comment.