Skip to content

fix(apps): import top-level project files under their module name during discovery - #693

Open
irisfield wants to merge 1 commit into
runpod:mainfrom
irisfield:fix/flash-flat-project-discovery
Open

irisfield wants to merge 1 commit into
runpod:mainfrom
irisfield:fix/flash-flat-project-discovery

Conversation

@irisfield

Copy link
Copy Markdown

Fixes #692

Problem

Discovery imports a top-level file under a generated module name. When workers.py runs from app import app, Python imports app.py a second time as app, so the project ends up with two App("demo") objects. The resources register on the second one, and discovery keeps the first.

Fix

_module_name returns the file stem for a top-level file when import <stem> resolves to that same file, and _import_module imports those names with importlib.import_module. A sibling's from app import app then gets the module discovery already imported. The generated name is still used when the stem is not an identifier or belongs to a different module, for example a project file named json.py.

Tests

In tests/test_apps/test_discovery.py:

  • test_flat_project_sibling_import_shares_app, parametrized over workers.py and a_workers.py (sorting after and before app.py): one app, with its resource. Both cases fail without this change.
  • test_flat_module_named_like_installed_module_keeps_installed_module: a project json.py does not replace the installed json. This one passes before and after, and covers the fallback.

Live check

The project from #692, deployed to a CPU queue endpoint with workers=(0, 1) and no jobs sent. First rp flash deploy workers.py, then rp flash deploy from the project directory:

rp flash deploy output encode endpoint afterwards
runpod 2.1.0 from app.py, (no resources) deleted
this change from app.py, encode still there

This branch has not been deployed

No deployments
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.

rp flash deploy deletes the app's endpoints when the App is imported from another file

1 participant