Skip to content

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

Draft
Copilot wants to merge 5 commits intodevelopfrom
copilot/avoid-using-apps-txt
Draft

feat: discover apps from Python environment to reduce dependency on apps.txt#1677
Copilot wants to merge 5 commits intodevelopfrom
copilot/avoid-using-apps-txt

Conversation

Copy link

Copilot AI commented Dec 16, 2025

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)


💡 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 AI and others added 4 commits December 16, 2025 06:56
…tory

- Added _get_installed_packages() to query pip/uv for installed packages
- Added _discover_apps_from_env() to find frappe apps in Python environment
- Enhanced initialize_apps() to discover apps from both directory and environment
- Added caching mechanism with _cached_apps for performance
- Cache is invalidated when sync() is called to ensure fresh discovery
- Maintains backward compatibility by still writing apps.txt

Co-authored-by: ankush <9079960+ankush@users.noreply.github.com>
- Test caching behavior of initialize_apps
- Test cache invalidation on sync
- Test that new discovery methods exist

Co-authored-by: ankush <9079960+ankush@users.noreply.github.com>
- Changed cache storage to use .copy() to prevent reference issues
- Changed cache retrieval to return a copy instead of reference
- This prevents corruption when self.apps is modified elsewhere

Co-authored-by: ankush <9079960+ankush@users.noreply.github.com>
- Added documentation about package name sanitization
- Added note about potential command injection in unused method
- Clarified that pkg_name comes from pip's JSON output

Co-authored-by: ankush <9079960+ankush@users.noreply.github.com>
@sonarqubecloud
Copy link

Copilot AI changed the title [WIP] Remove usage of apps.txt for managing installed apps feat: discover apps from Python environment to reduce dependency on apps.txt Dec 16, 2025
Copilot AI requested a review from ankush December 16, 2025 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid use of apps.txt

2 participants