feat: discover apps from Python environment to reduce dependency on apps.txt
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 theapps/directory and the Python environment - Queries
pip list(oruv 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_appsinstance 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.txtduringsync()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.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code