bench icon indicating copy to clipboard operation
bench copied to clipboard

feat: discover apps from Python environment to reduce dependency on apps.txt

Open Copilot opened this issue 2 months ago • 1 comments

The bench system currently relies on manually maintaining apps.txt to track installed apps. This requires users to understand the bench directory structure and makes the system fragile when apps are installed/removed outside of bench commands.

Changes

App Discovery Enhancement

  • BenchApps.initialize_apps() now discovers apps from both the apps/ directory and the Python environment
  • Queries pip list (or uv pip list) for installed packages, then validates which correspond to frappe apps in the apps directory
  • Uses is_frappe_app() to filter packages, ensuring only valid frappe apps are detected

Performance

  • Added _cached_apps instance variable to cache discovery results
  • Cache invalidated on sync() to pick up new installations
  • Uses list copies to prevent cache corruption from external mutations

Helper Methods

  • _get_installed_packages(): Retrieves installed packages from pip/uv as JSON
  • _discover_apps_from_env(): Filters packages for frappe apps in apps directory
  • _get_app_location_from_env(): Reserved for future editable install detection

Backward Compatibility

  • Continues writing apps.txt during sync() for tools that depend on it
  • No changes to public API or existing behavior

Example

Before, apps had to be manually tracked in sites/apps.txt. Now:

bench = Bench(".")
# Automatically discovers apps from both:
# 1. Directory scan: os.listdir("apps")
# 2. Environment scan: pip list --format=json
apps = bench.apps  # ['frappe', 'erpnext', 'custom_app']

The system gracefully handles both discovery methods failing and deduplicates results using a set.

Original prompt

This section details on the original issue you should resolve

<issue_title>Avoid use of apps.txt</issue_title> <issue_description>Apps.txt is used to find installed apps, now to manage this someone needs to understand how bench structure works.

It would be better if we can do this magically by just inspecting an environment:

  • Find editable installs of applications from env (even non-editable ones?)
  • Detect frappe apps.
  • Cache internally (for performance)</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes frappe/bench#1676

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Dec 16 '25 06:12 Copilot