From d1821cb466eb80d7ad343820fa55b8c347699bc2 Mon Sep 17 00:00:00 2001 From: Phil Miesle Date: Thu, 12 Dec 2024 12:01:05 +0000 Subject: [PATCH] ref: improving development environment and instructions (#5180) * improving development environment and instructions * minor edits as requested * fix typo in DEVELOPMENT.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Gabriel Luiz Freitas Almeida Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .devcontainer/Dockerfile | 50 +++--- .devcontainer/README.md | 60 +++++++ .devcontainer/demo/README.md | 15 -- .devcontainer/demo/devcontainer.json | 33 ---- .devcontainer/devcontainer.json | 61 +++++-- CONTRIBUTING.md | 59 +------ DEVELOPMENT.md | 233 +++++++++++++++++++++++++++ Makefile | 37 +++-- 8 files changed, 391 insertions(+), 157 deletions(-) create mode 100644 .devcontainer/README.md delete mode 100644 .devcontainer/demo/README.md delete mode 100644 .devcontainer/demo/devcontainer.json create mode 100644 DEVELOPMENT.md diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 352c2766a..cb71de06c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,29 +1,35 @@ -# Source: https://github.com/a5chin/python-uv -FROM debian:bookworm-slim AS builder +FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim -ENV CARGO_HOME="/opt/.cargo" +# Set timezone +ENV TZ=UTC -SHELL [ "/bin/bash", "-o", "pipefail", "-c" ] +# Set up work directory +WORKDIR /workspace -WORKDIR /opt +# Install additional dev dependencies +RUN apt-get update && apt-get install -y \ + zsh \ + curl \ + git \ + build-essential \ + npm \ + lsof \ + procps \ + vim \ + less \ + net-tools \ + sudo \ + && apt-get clean && rm -rf /var/lib/apt/lists/* -# The installer requires curl (and certificates) to download the release archive -# hadolint ignore=DL3008 -RUN apt-get update && \ - apt-get install -y --no-install-recommends ca-certificates curl +# Create the vscode user and group with the expected UID and GID (1000) +RUN groupadd -g 1000 langflow && \ + useradd -m -u 1000 -g 1000 -s /bin/zsh langflow && \ + echo "langflow ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers -# Run uv installer -RUN curl -LsSf https://astral.sh/uv/install.sh | sh +# Set default shell to Zsh +SHELL ["/bin/zsh", "-c"] +RUN echo 'export PS1="%~ %# "' >> /home/langflow/.zshrc -FROM mcr.microsoft.com/vscode/devcontainers/base:bookworm - - -ENV CARGO_HOME="/opt/.cargo" -ENV PATH="$CARGO_HOME/bin/:$PATH" -ENV PYTHONUNBUFFERED=True -ENV UV_LINK_MODE=copy - -WORKDIR /opt - -COPY --from=builder --chown=vscode: $CARGO_HOME $CARGO_HOME \ No newline at end of file +# Set the default user +USER langflow diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 000000000..1ec113bc3 --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,60 @@ +# Langflow Demo Codespace Readme + +These instructions will walk you through the process of running a Langflow demo via GitHub Codespaces. + +If you want a faster and easier demo experience with Langflow, DataStax Langflow is a hosted environment with zero setup: [Sign up for a free account.](https://astra.datastax.com/signup?type=langflow) + +## Create a Codespace in GitHub + +To setup the demo in Codespace: + +1. Navigate to the Langflow repo +2. On the "Code <>" button, select the "Codespaces" tab +3. Click the green "Create codespace on..." button (or "+" icon if you want more options) to create a new Codespace + +## Wait for everything to install + +After the codespace is opened, there will be two phases to the process. It will take ≈5-10 minutes to complete. + +* **Phase 1**: Building Container; you can click on the "Building Codespace" link to watch the logs +* **Phase 2**: Building Langflow; the terminal will now show `Running postCreateCommand...`, similar to: + +``` +✔ Finishing up... +⠸ Running postCreateCommand... + › sudo chown -R langflow .venv .mypy_cache src/frontend/node_modules src/frontend/build src/backend/base/langflow/frontend && make install_frontend && mak… +``` + +Once completed, this terminal window will close. + +You now need to manually build the frontend. Open a new Terminal and run command: + +```bash +make build_frontend +``` + +This will take a short period of time, you should have a message similar to `Building frontend static files` and the command will complete successfully. + +Installation is now complete. + +## Start up the Service + +Open a new Terminal, and type `uv run langflow run`. + +The service will start, and you will may notice a dialog in the lower right indicating there is a port available to connect to. However, the service will not be ready until you see the welcome banner: + +``` +╭───────────────────────────────────────────────────────────────────╮ +│ Welcome to ⛓ Langflow │ +│ │ +│ │ +│ Collaborate, and contribute at our GitHub Repo 🌟 │ +│ │ +│ We collect anonymous usage data to improve Langflow. │ +│ You can opt-out by setting DO_NOT_TRACK=true in your environment. │ +│ │ +│ Access http://127.0.0.1:7860 │ +╰───────────────────────────────────────────────────────────────────╯ +``` + +At this point you can connect to the service via the port, or if the dialog is gone you can find the "Forwarded Address" on the "Ports" tab (which is next the "Terminal" tab). If there is no port forwarded, you can click the "Forward a Port" button on the "Ports" tab, and forward `7860`. \ No newline at end of file diff --git a/.devcontainer/demo/README.md b/.devcontainer/demo/README.md deleted file mode 100644 index 0a828a009..000000000 --- a/.devcontainer/demo/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Langflow Demo Codespace Readme - -These instructions will walk you through the process of running a Langflow demo via GitHub Codespaces. - -## Setup - -### Create a Codespace in GitHub - -To setup the demo, simply navigate to the Langflow repo, click the "+" button, and select "Create new Codespace". This will automatically create a new codespace in your browser, which you can use for the demo. - -### Wait for everything to install - -After the codespace is opened, you should see a new Terminal window in VS Code where langflow is installed. Once the install completes, `langflow` will launch the webserver and your application will be available via devcontainer port. - -Note: VS Code should prompt you with a button to push once the port is available. diff --git a/.devcontainer/demo/devcontainer.json b/.devcontainer/demo/devcontainer.json deleted file mode 100644 index 0fb998b81..000000000 --- a/.devcontainer/demo/devcontainer.json +++ /dev/null @@ -1,33 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/universal -{ - "name": "Langflow Demo Container", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/python:3.10", - "features": { - "ghcr.io/devcontainers/features/aws-cli:1": {}, - "ghcr.io/devcontainers/features/docker-in-docker": {}, - "ghcr.io/devcontainers/features/node": {} - }, - "customizations": { - "vscode": { - "extensions": [ - "actboy168.tasks", - "GitHub.copilot", - "ms-python.python", - "eamodio.gitlens", - "GitHub.vscode-pull-request-github" - ] - } - }, - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "pipx install 'langflow>=0.0.33' && langflow --host 0.0.0.0" - // Configure tool-specific properties. - // "customizations": {}, - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 88c165013..5ad55243d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,25 +1,14 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/universal { "name": "Langflow Dev Container", "build": { "context": "..", "dockerfile": "Dockerfile" }, - // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/node": {}, "ghcr.io/dhoeric/features/hadolint:1": {} }, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "make install_frontend && make install_backend", - "postStartCommand": "make init", - - // Configure tool-specific properties. + "postCreateCommand": "sudo chown -R langflow .venv .mypy_cache src/frontend/node_modules src/frontend/build src/backend/base/langflow/frontend && make install_frontend && make install_backend", "customizations": { "vscode": { "extensions": [ @@ -44,8 +33,48 @@ } } }, - - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" - "remoteUser": "vscode" + "remoteUser": "langflow", + "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind", + "workspaceFolder": "/workspace", + "forwardPorts": [7860, 3000], + "containerEnv": { + "FRONTEND_START_FLAGS": "--host" + }, + "mounts": [ + { + "source": "${localWorkspaceFolderBasename}-frontend-node_modules", + "target": "/workspace/src/frontend/node_modules", + "type": "volume" + }, + { + "source": "${localWorkspaceFolderBasename}-frontend-build", + "target": "/workspace/src/frontend/build", + "type": "volume" + }, + { + "source": "${localWorkspaceFolderBasename}-backend-frontend", + "target": "/workspace/src/backend/base/langflow/frontend", + "type": "volume" + }, + { + "source": "${localWorkspaceFolderBasename}-venv", + "target": "/workspace/.venv", + "type": "volume" + }, + { + "source": "${localWorkspaceFolderBasename}-mypy-cache", + "target": "/workspace/.mypy_cache", + "type": "volume" + }, + { + "source": "${localWorkspaceFolderBasename}-dist", + "target": "/workspace/dist", + "type": "volume" + }, + { + "source": "${localWorkspaceFolderBasename}-backend-dist", + "target": "/workspace/src/backend/base/dist", + "type": "volume" + } + ] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 960f6522a..dd70327c7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,64 +33,9 @@ so that more people can benefit from it. ## Contributing code and documentation -You can develop Langflow locally via uv + NodeJS. +You can develop Langflow locally and contribute to the Project! -### Clone the Langflow Repository - -Navigate to the [Langflow GitHub repository](https://github.com/langflow-ai/langflow) and press "Fork" in the upper right-hand corner. - -Add the new remote to your local repository on your local machine: - -```bash -git remote add fork https://github.com//langflow.git -``` - -We also provide a .vscode/launch.json file for debugging the backend in VSCode, which is a lot faster than using docker compose. - -### Prepare the environment - -Setting up hooks: - -```bash -make init -``` - -This will set up the development environment by installing backend and frontend dependencies, building the frontend static files, and initializing the project. It runs `make install_backend`, `make install_frontend`, `make build_frontend`, and finally `uv run langflow run` to start the application. - -It is advised to run `make lint`, `make format`, and `make unit_tests` before pushing to the repository. - -### Run locally (uv and Node.js) - -Langflow can run locally by cloning the repository and installing the dependencies. We recommend using a virtual environment to isolate the dependencies from your system. - -Before you start, make sure you have the following installed: - -- uv (>=0.4) -- Node.js - -Then, in the root folder, install the dependencies and start the development server for the backend: - -```bash -make backend -``` - -And the frontend: - -```bash -make frontend -``` - -### Run documentation - -The documentation is built using [Docusaurus](https://docusaurus.io/). To run the documentation locally, run the following commands: - -```bash -cd docs -npm install -npm run start -``` - -The documentation will be available at `localhost:3000` and all the files are located in the `docs/docs` folder. +See [DEVELOPMENT.md](DEVELOPMENT.md) for instructions on setting up and using a development envrionment. ## Opening a pull request diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 000000000..0696dc9f7 --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,233 @@ +# Setting up a Development Environment + +This document details how to set up a local development environment that will allow you to contribute changes to the project! + +## Base Requirements + +* The project is hosted on GitHub, so you need an account there (and if you are reading this, you likely do!) +* An IDE such as Microsoft VS Code IDE https://code.visualstudio.com/ + +## Set up Git Repository Fork + +You will push changes to a fork of the Langflow repository, and from there create a Pull Request into the project repository. + +Fork the [Langflow GitHub repository](https://github.com/langflow-ai/langflow/fork), and follow the instructions to create a new fork. + +On your new fork, click the "<> Code" button to get a URL to clone using your preferred method, and clone the repostory; for example using `https`: + +```bash +git clone https://github.com//langflow.git +``` + +Finally, add the Project repository as `upstream`: + +```bash +cd langflow +git remote add upstream https://github.com/langflow-ai/langflow.git +git remote set-url --push upstream no_push +``` + +> **Windows/WSL Users**: You may find that files "change", specifically the file mode e.g. "changed file mode 100755 → 100644". You can workaround this problem with `git config core.filemode false`. + +## Set up Environment + +There are two options available to you: the 'easy' and recommended option is to use a Development Container ("[Dev Container](https://containers.dev/)"), or you can choose to use your own OS / environment. + +### Option 1 (Preferred): Use a Dev Container + +Open this repository as a Dev Container per your IDEs instructions. + +#### Microsoft VS Code + +* See [Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers) +* You may also find it helpful to [share `git` credentials](https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials) with the container + + +### Option 2: Use Your Own Environment + +Install Pre-Requisites: + +* **Operating System**: macOS or Linux; Windows users ***MUST*** develop under WSL. +* **`git`**: The project uses the ubiquitous `git` tool for change control. +* **`make`**: The project uses `make` to coordidinate packaging. +* **`uv`**: This project uses `uv` (`>=0.4`), a Python package and project manager from Astral. Install instructions at https://docs.astral.sh/uv/getting-started/installation/. +* **`npm`**: The frontend files are built with Node.js (`v22.12 LTS`) and `npm` (`v10.9`). Install instructions at https://nodejs.org/en/download/package-manager. + - Windows (WSL) users: ensure `npm` is installed within WSL environment; `which npm` should resolve to a Linux location, not a Windows location. + +### Initial Environment Validation + +Setup and validate the initial environment by running: + +```bash +make init +``` + +This will set up the development environment by installing backend and frontend dependencies, building the frontend static files, and initializing the project. It runs `make install_backend`, `make install_frontend`, `make build_frontend`, and finally `uv run langflow run` to start the application. + +Once the application is running, the command output should look similar to: + +``` +╭───────────────────────────────────────────────────────────────────╮ +│ Welcome to ⛓ Langflow │ +│ │ +│ │ +│ Collaborate, and contribute at our GitHub Repo 🌟 │ +│ │ +│ We collect anonymous usage data to improve Langflow. │ +│ You can opt-out by setting DO_NOT_TRACK=true in your environment. │ +│ │ +│ Access http://127.0.0.1:7860 │ +╰───────────────────────────────────────────────────────────────────╯ +``` + +At this point, validate you can access the UI by opening the URL shown. + +This is how the application would normally run: the (static) front-end pages are compiled, and then this "frontend" is served by the FastAPI server; the "backend" APIs are also serviced by the FastAPI server. + +However, as a developer, you will want to proceed to the next step. Shutdown Langflow by hitting `Control (or Command)-C`. + +## Completing Development environment Setup + +There are some other steps to consider before you are ready to begin development. + +### Optional pre-commit hooks + +Pre-commit hooks will help keep your changes clean and well-formatted. + +> **Note:** With these installed, the `git commit` command needs to run within the Python environment; your syntax needs to change to `uv run git commit`. + + Install pre-commit hooks by running the following commands: + +```bash +uv sync --dev +uv run pre-commit install +``` + +## Run Langflow in "Development" Mode + +With the above validation, you can now run the backend (FastAPI) and frontend (Node) services in a way that will "hot-reload" your changes. In this mode, the FastAPI server requires a Node.js server to serve the frontend pages rather than serving them directly. + +> ***Note***: You will likely have multiple terminal sessions active in the normal development workflow. These will be annotated as *Backend Terminal*, *Frontend Terminal*, *Documentation Terminal*, and *Build Terminal*. + +### Debug Mode + +A debug configuration is provided for VS Code users: this can be launched from the Debug tab (the backend debug mode can be launched directly via the F5 key). You may prefer to start services in this mode. You may still want to read the following subsections to understand expected console output and service readiness. + +### Start the Backend Service + +The backend service runs as a FastAPI service on Python, and is responsible for servicing API requests. In the *Backend Terminal*, start the backend service: + +```bash +make backend +``` + +You will get output similar to: + +``` +INFO: Will watch for changes in these directories: ['/home/phil/git/langflow'] +INFO: Loading environment from '.env' +INFO: Uvicorn running on http://0.0.0.0:7860 (Press CTRL+C to quit) +INFO: Started reloader process [22330] using WatchFiles +Starting Langflow ... +``` + +At which point you can check http://localhost:7860/health in a browser; when the backend service is ready it will return a document like: + +```json +{"status":"ok"} +``` + +### Start the Frontend Service + +The frontend (User Interface) is, in shipped code (i.e. via `langflow run`), statically-compiled files that the backend FastAPI service provides to clients via port `7860`. In development mode, these are served by a Node.js service on port `3000`. In the *Frontend Terminal*, start the frontend service: + +```bash +make frontend +``` + +You will get output similar to: + +``` + VITE v5.4.11 ready in 552 ms + + ➜ Local: http://localhost:3000/ + ➜ Network: use --host to expose + ➜ press h + enter to show help +``` + +At this point, you can navigate to http://localhost:3000/ in a browser and access the Langflow User Interface. + +### Build and Display Documentation + +If you are contributing changes to documentation (always welcome!), these are built (using [Docusaurus](https://docusaurus.io/)) and served separately, also using Node.js. + +In the *Documentation Terminal* (from the project root directory), run the following: + +```bash +cd docs +npm install +npm run start +``` + +If the frontend service is running on port `3000` you might be prompted `Would you like to run the app on another port instead?`, in which case answer "yes". You will get output similar to: + +``` +[SUCCESS] Docusaurus website is running at: http://localhost:3001/ +``` + +At which point you can navigate to http://localhost:3001/ in a browser and view the documentation. Documentation updates will be visible as they are saved, though sometimes the browser page will also need to be refreshed. + +## Adding or Modifying a Component + +Components reside in folders under `src/backend/base/langflow`, and their unit tests under `src/backend/base/tests/unit/components`. + +### Adding a Component + +Add the component to the appropriate subdirectory, and add the component to the `__init__.py` file (alphabetical ordering on the `import` and the `__all__` list). Assuming the backend and frontend services are running, the backend service will restart as these files are changed. The new component will be visible after the backend is restarted, _*and*_ after you hit "refresh" in the browser. + +> Tip: It is faster to copy-paste the component code from your editor into the UI *without* saving in the source code in the editor, and once you are satisfied it is working you can save (restarting the backend) and refresh the browser to confirm it is present. + +You should try to add a unit test for your component, though templates and best practices for this is a work in progress. At the very least, please create a Markdown file in the unit test subdirectory associated with your component (create the directory if not present), with the same filename as the component but with a `.md` extension. Within this should be the steps you have taken to manually test the component. + +### Modifying a Component + +Modifying a component is much the same as adding a component: it is generally easier to make changes in the UI and then save the file in the repository. Please be sure to review and modify unit tests; if there is not a unit test for the component, the addition of one that at least covers your changes would be much appreciated! + +> Note: if you have an old version of the component on the canvas when changes are saved and the backend service restarts, that component should show "Updates Available" when the canvas is reloaded (i.e. a browser refresh). [Issue 5179](https://github.com/langflow-ai/langflow/issues/5179) indicates this behavior is not consistent, at least in a development setting. + +## Building and Testing Changes + +When you are ready to commit, and before you commit, you should consider the following: + +* `make lint` +* `make format_backend` and `make format_frontend` will run code formatters on their respective codebases +* `make unit_tests` runs the (backend) unit tests (see "Quirks" below for more about testing). + +Once these changes are ready, it is helpful to rebase your changes on top of `upstream`'s `main` branch, to ensure you have the latest code version! Of course if you have had to merge changes into your component you may want to re-lint/format/unit_test. + +As a final validation, stop the backend and frontend services and run `make init`; this will do a clean build and the UI should be available in port `7860` (as it has invoked `langflow run`). Open a **new** browser tab to this service and do a final check of your changes by adding your new/modified component onto the canvas from the Components list. + +## Committing, Pushing, and Pull Requests + +Once you are happy your changes are complete, commit them and push the changes to your own fork (this will be `origin` if you followed the above instructions). You can then raise a Pull Request into the Project repository on the GitHub interface or within your IDE. + +> Tip: Remember that if you have pre-commit hooks enabled, you need to run the `git` command as `uv run git` to activate the necessary Python environment! + +## Some Quirks! + +You may observe some quirky things: + +### Testing + +* Backend test `src/backend/tests/unit/test_database.py` can fail when running with `make tests` but passes when running manually + * You can validate this by running the test cases sequentially: `uv run pytest src/backend/tests/unit/test_database.py` +* There are some other test targets: `integration_tests`, `coverage`, `tests_frontend` but these require additional setup not covered in this document. + +### Files That Change + +There are some files that change without you having made changes: + +* Files in `src/backend/base/langflow/initial_setup/starter_projects` modify after `langflow run`; these are formatting changes. Feel free to commit (or ignore) them. +* `uv.lock` and `src/frontend/package-lock.json` files can be modified by `make` targets; changes should not be committed by individual contributors. + * You can exclude these from consideration in git: `git update-index --assume-unchanged uv.lock src/frontend/package-lock.json` + * You can re-include these from consideration in git: `git update-index --no-assume-unchanged uv.lock src/frontend/package-lock.json` diff --git a/Makefile b/Makefile index b928ccc0a..f31fe3eeb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all init format lint build build_frontend install_frontend run_frontend run_backend dev help tests coverage clean_python_cache clean_npm_cache clean_all +.PHONY: all init format_backend format_frontend format lint build build_frontend install_frontend run_frontend run_backend dev help tests coverage clean_python_cache clean_npm_cache clean_all # Configurations VERSION=$(shell grep "^version" pyproject.toml | sed 's/.*\"\(.*\)\"$$/\1/') @@ -27,6 +27,12 @@ all: help # UTILITIES ###################### +# Some directories may be mount points as in devcontainer, so we need to clear their +# contents rather than remove the entire directory. But we must also be mindful that +# we are not running in a devcontainer, so need to ensure the directories exist. +# See https://code.visualstudio.com/remote/advancedcontainers/improve-performance +CLEAR_DIRS = $(foreach dir,$1,$(shell mkdir -p $(dir) && find $(dir) -mindepth 1 -delete)) + # increment the patch version of the current package patch: ## bump the version in langflow and langflow-base @echo 'Patching the version' @@ -68,8 +74,8 @@ install_frontend: ## install the frontend dependencies build_frontend: ## build the frontend static files @echo 'Building frontend static files' @cd src/frontend && CI='' npm run build > /dev/null 2>&1 - @rm -rf src/backend/base/langflow/frontend - @cp -r src/frontend/build src/backend/base/langflow/frontend + $(call CLEAR_DIRS,src/backend/base/langflow/frontend) + @cp -r src/frontend/build/. src/backend/base/langflow/frontend init: check_tools clean_python_cache clean_npm_cache ## initialize the project @make install_backend @@ -88,13 +94,14 @@ clean_python_cache: find . -type f -name '*.py[cod]' -exec rm -f {} + find . -type f -name '*~' -exec rm -f {} + find . -type f -name '.*~' -exec rm -f {} + - find . -type d -empty -delete + $(call CLEAR_DIRS,.mypy_cache ) @echo "$(GREEN)Python cache cleaned.$(NC)" clean_npm_cache: @echo "Cleaning npm cache..." cd src/frontend && npm cache clean --force - rm -rf src/frontend/node_modules src/frontend/build src/backend/base/langflow/frontend src/frontend/package-lock.json + $(call CLEAR_DIRS,src/frontend/node_modules src/frontend/build src/backend/base/langflow/frontend) + rm -f src/frontend/package-lock.json @echo "$(GREEN)NPM cache and frontend directories cleaned.$(NC)" clean_all: clean_python_cache clean_npm_cache # clean all caches and temporary directories @@ -179,11 +186,15 @@ fix_codespell: ## run codespell to fix spelling errors @poetry install --with spelling poetry run codespell --toml pyproject.toml --write -format: ## run code formatters - @uv run ruff check . --fix +format_backend: ## backend code formatters + @uv run ruff check . --fix --ignore EXE002 @uv run ruff format . --config pyproject.toml + +format_frontend: ## frontend code formatters @cd src/frontend && npm run format +format: format_backend format_frontend ## run code formatters + unsafe_fix: @uv run ruff check . --fix --unsafe-fixes @@ -194,11 +205,11 @@ install_frontendci: @cd src/frontend && npm ci > /dev/null 2>&1 install_frontendc: - @cd src/frontend && rm -rf node_modules package-lock.json && npm install > /dev/null 2>&1 + @cd src/frontend && $(call CLEAR_DIRS,node_modules) && rm -f package-lock.json && npm install > /dev/null 2>&1 run_frontend: ## run the frontend @-kill -9 `lsof -t -i:3000` - @cd src/frontend && npm start + @cd src/frontend && npm start $(if $(FRONTEND_START_FLAGS),-- $(FRONTEND_START_FLAGS)) tests_frontend: ## run frontend tests ifeq ($(UI), true) @@ -272,16 +283,14 @@ else endif build_and_run: setup_env ## build the project and run it - rm -rf dist - rm -rf src/backend/base/dist + $(call CLEAR_DIRS,dist src/backend/base/dist) make build uv run pip install dist/*.tar.gz uv run langflow run build_and_install: ## build the project and install it @echo 'Removing dist folder' - rm -rf dist - rm -rf src/backend/base/dist + $(call CLEAR_DIRS,dist src/backend/base/dist) make build && uv run pip install dist/*.whl && pip install src/backend/base/dist/*.whl --force-reinstall build: setup_env ## build the frontend static files and package the project @@ -300,7 +309,7 @@ endif build_langflow_base: cd src/backend/base && uv build $(args) - rm -rf src/backend/base/langflow/frontend + $(call CLEAR_DIRS,src/backend/base/langflow/frontend) build_langflow_backup: uv lock && uv build