Skip to content

Commit

Permalink
chore(migration from pdm to uv): fix commands
Browse files Browse the repository at this point in the history
  • Loading branch information
nightblure committed Dec 19, 2024
1 parent b8d362c commit 8eeac89
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Setting up the environment
--------------------------

1. Install `Pizza Delivery Man <https://pdm.fming.dev/latest/>`_
2. Run ``pdm install -G:all`` to create a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ and install
2. Run ``uv sync --all-groups`` to create a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ and install
the dependencies
3. If you're working on the documentation and need to build it locally, install the extra dependencies with ``pdm install -G:docs``
3. If you're working on the documentation and need to build it locally, install the extra dependencies with `` uv sync --group docs``
4. Install `pre-commit <https://pre-commit.com/>`_
5. Run ``pre-commit install`` to install pre-commit hooks

Expand Down Expand Up @@ -57,7 +57,7 @@ To run or build the docs locally, you need to first install the required depende

.. code-block:: console
pdm install -G:docs
uv sync --group docs
Then you can serve the documentation with ``make docs-serve``, or build them with ``make docs``

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ stop-infra:
docker compose -f docker-compose.infra.yml down --remove-orphans

post_install:
pdm run python scripts/pre-build.py --install-packages
uv run python scripts/pre-build.py --install-packages

pre_build:
pdm run python scripts/pre-build.py --build-assets
uv run python scripts/pre-build.py --build-assets
# =============================================================================
# Tests, Linting, Coverage
# =============================================================================
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ make install

```bash
cp .env.local.example .env
pdm run start-infra # this starts a database and redis instance only
make start-infra # this starts a database and redis instance only
# this will start the SAQ worker, Vite development process, and Litestar
pdm run app run
uv run app run

# to stop the database and redis, run
pdm run stop-infra
make stop-infra
```

### Docker
Expand Down
10 changes: 5 additions & 5 deletions deploy/docker/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ RUN apt-get update \
## ------------------------- Python build base -------------------------------------- ##
## ---------------------------------------------------------------------------------- ##
FROM python-base AS build-base
ARG PDM_INSTALL_ARGS="-G:all"
ENV PDM_INSTALL_ARGS="${PDM_INSTALL_ARGS}" \
ARG UV_INSTALL_ARGS="--all-groups"
ENV UV_INSTALL_ARGS="${UV_INSTALL_ARGS}" \
GRPC_PYTHON_BUILD_WITH_CYTHON=1 \
PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH"
## -------------------------- add build packages ----------------------------------- ##
Expand All @@ -53,8 +53,8 @@ COPY scripts ./scripts/
COPY public ./public/
COPY resources ./resources/
RUN python -m venv --copies /workspace/app/.venv \
&& /workspace/app/.venv/bin/pip install cython pdm nodeenv \
&& pdm install ${PDM_INSTALL_ARGS} --no-self
&& /workspace/app/.venv/bin/pip install cython uv nodeenv \
&& uv install ${UV_INSTALL_ARGS}
COPY src ./src/

## ---------------------------------------------------------------------------------- ##
Expand Down Expand Up @@ -82,7 +82,7 @@ WORKDIR /workspace/app
COPY docs/ docs/
COPY tests/ tests/
COPY src src/
RUN pdm install $PDM_INSTALL_ARGS
RUN uv install $UV_INSTALL_ARGS
STOPSIGNAL SIGINT
EXPOSE 8000
ENTRYPOINT ["tini","--" ]
Expand Down
12 changes: 6 additions & 6 deletions deploy/docker/run/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ RUN apt-get update \
## ------------------------- Python build base -------------------------------------- ##
## ---------------------------------------------------------------------------------- ##
FROM python-base AS build-base
ARG PDM_INSTALL_ARGS=""
ENV PDM_INSTALL_ARGS="${PDM_INSTALL_ARGS}" \
ARG UV_INSTALL_ARGS=""
ENV UV_INSTALL_ARGS="${UV_INSTALL_ARGS}" \
GRPC_PYTHON_BUILD_WITH_CYTHON=1 \
PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH"
## -------------------------- add build packages ----------------------------------- ##
Expand All @@ -53,11 +53,11 @@ COPY scripts ./scripts/
COPY public ./public/
COPY resources ./resources/
RUN python -m venv --copies /workspace/app/.venv \
&& /workspace/app/.venv/bin/pip install --quiet pdm nodeenv cython \
&& pdm install ${PDM_INSTALL_ARGS} --no-self \
&& pdm export ${PDM_INSTALL_ARGS} --without-hashes --prod --output=requirements.txt
&& /workspace/app/.venv/bin/pip install --quiet uv nodeenv cython \
&& uv install ${UV_INSTALL_ARGS} \
&& uv export ${UV_INSTALL_ARGS} --no-hashes --no-dev --output-file=requirements.txt
COPY src ./src/
RUN pdm build
RUN uv build


## ---------------------------------------------------------------------------------- ##
Expand Down
16 changes: 8 additions & 8 deletions deploy/docker/run/Dockerfile.distroless
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ARG PYTHON_RUN_IMAGE=gcr.io/distroless/cc:nonroot
## ------------------------- Python base -------------------------------------------- ##
## ---------------------------------------------------------------------------------- ##
FROM python:${PYTHON_BUILDER_IMAGE} as python-base
ARG PDM_INSTALL_ARGS=""
ENV PDM_INSTALL_ARGS="${PDM_INSTALL_ARGS}" \
ARG UV_INSTALL_ARGS=""
ENV UV_INSTALL_ARGS="${UV_INSTALL_ARGS}" \
GRPC_PYTHON_BUILD_WITH_CYTHON=1 \
PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH" \
PIP_DEFAULT_TIMEOUT=100 \
Expand Down Expand Up @@ -37,8 +37,8 @@ RUN apt-get update \
## ------------------------- Python build base -------------------------------------- ##
## ---------------------------------------------------------------------------------- ##
FROM python-base AS build-base
ARG PDM_INSTALL_ARGS=""
ENV PDM_INSTALL_ARGS="${PDM_INSTALL_ARGS}" \
ARG UV_INSTALL_ARGS=""
ENV UV_INSTALL_ARGS="${UV_INSTALL_ARGS}" \
GRPC_PYTHON_BUILD_WITH_CYTHON=1 \
PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH"
## -------------------------- add development packages ------------------------------ ##
Expand All @@ -56,15 +56,15 @@ COPY pyproject.toml uv.lock README.md .pre-commit-config.yaml LICENSE Makefile \
tailwind.config.cjs postcss.config.cjs components.json \
./
RUN python -m venv --copies /workspace/app/.venv \
&& /workspace/app/.venv/bin/pip install --quiet pdm nodeenv cython mypy
&& /workspace/app/.venv/bin/pip install --quiet uv nodeenv cython mypy
COPY scripts ./scripts/
COPY public ./public/
COPY resources ./resources/
RUN pdm install ${PDM_INSTALL_ARGS} --no-self \
&& pdm export ${PDM_INSTALL_ARGS} --without-hashes --prod --output=requirements.txt
RUN uv sync ${UV_INSTALL_ARGS} --no-self \
&& uv export ${UV_INSTALL_ARGS} --no-hashes --no-dev --output-file=requirements.txt
COPY src ./src/

RUN pdm build
RUN uv build
VOLUME /workspace/app
## ---------------------------------------------------------------------------------- ##
## -------------------------------- runtime build ----------------------------------- ##
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Upgrade Project Dependencies

This command will upgrade all components of the application at the same time. It automatically executes:

- ``pdm upgrade``
- ``uv lock --upgrade``
- ``npm update``
- ``pre-commit autoupdate``

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To install an environment, with all development packages run:
This command does the following:

- Install ``pdm`` if it is not available in the path.
- Install ``uv`` if it is not available in the path.
- Create a virtual environment with all dependencies configured
- Build assets to be hosted by production asset server

Expand Down
4 changes: 2 additions & 2 deletions docs/usage/startup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Additionally, when you start the application with ``VITE_HOT_RELOAD`` set to tru

.. code-block:: bash
(.venv) cody@localtop:~/Code/Litestar/litestar-fullstack$ pdm run app run -p 8089
(.venv) cody@localtop:~/Code/Litestar/litestar-fullstack$ uv run app run -p 8089
Using Litestar app from env: 'app.asgi:app'
Loading environment configuration from .env
Starting Granian server process ───────────────────────────────────────────────────────
Expand Down Expand Up @@ -59,7 +59,7 @@ Production
^^^^^^^^^^

If ``VITE_DEV_MODE`` is false, the server will look for the static assets that are produced from the ``npm run build`` command.
This command is automatically executed and the assets are bundled when running ``pdm build``.
This command is automatically executed and the assets are bundled when running ``uv build``.

To manually rebuild assets, use the following:

Expand Down
6 changes: 3 additions & 3 deletions nixpacks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ providers = ['python', 'node'] # force python as the only provider, otherwise ra
# set up some variables to minimize annoyance
[variables]
LITESTAR_SKIP_NODEENV_INSTALL = 'true' # skip using nodeenv. nix handles that for us.
NIXPACKS_PDM_VERSION = '2.15.3' # set pdm version to install
NIXPACKS_UV_VERSION = '0.5.10' # set uv version to install
NIXPACKS_PYTHON_VERSION = '3.12' # set python version to install
NPM_CONFIG_FUND = 'false' # the fund notification is is also pretty useless in a production environment
NPM_CONFIG_UPDATE_NOTIFIER = 'false' # the node update notification is relatively useless in a production environment
Expand All @@ -15,8 +15,8 @@ nixPkgs = ['...'] # add nodejs since it is needed to build the frontend

[phases.install]
cmds = [
'python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -U mypy cython setuptools pdm==$NIXPACKS_PDM_VERSION && pdm install --prod',
] # custom install command allows for setting pdm version above
'python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -U mypy cython setuptools uv==NIXPACKS_UV_VERSION && uv sync --frozen --no-dev',
] # custom install command allows for setting uv version above

[start]
cmd = '/opt/venv/bin/app database upgrade --no-prompt && /opt/venv/bin/app run --wc 2 --host 0.0.0.0 --port $PORT'
2 changes: 1 addition & 1 deletion scripts/post-builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

def package_standalone_app(options: argparse.Namespace) -> None:
subprocess.run(
["/usr/bin/env", "pdm", "export", "--without-hashes", "--prod", "--output", "dist/requirements.txt"],
["/usr/bin/env", "uv", "export", "--no-hashes", "--no-dev", "--output-file", "dist/requirements.txt"],
check=False,
)
with Path(PROJECT_ROOT / "dist/requirements.txt").open("+a") as f:
Expand Down

0 comments on commit 8eeac89

Please sign in to comment.