fix: Improve Python project detection and entrypoint resolution#1010
Open
fix: Improve Python project detection and entrypoint resolution#1010
Conversation
b1954c2 to
27ca7f5
Compare
There was a problem hiding this comment.
Pull request overview
This pull request enhances Python project detection in the Apify CLI to support standard Python package layouts without requiring specific directory names. The changes enable automatic package discovery and provide better error messages for common configuration issues.
Changes:
- Implemented flexible Python project detection based on
pyproject.toml,requirements.txt, or presence of.pyfiles - Added automatic package discovery that searches for valid Python packages in the current directory and
src/subdirectory - Introduced smart entrypoint resolution that automatically selects the entrypoint when exactly one package is found
- Enhanced error messages with clear guidance for scenarios including no packages found, multiple packages found, and mixed Python/Node.js projects
- Maintained backwards compatibility with existing projects using
src/__main__.py
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/lib/hooks/useCwdProject.ts |
Core implementation of enhanced Python project detection including helper functions for package discovery, validation, and entrypoint resolution; added mixed project detection |
test/lib/hooks/useCwdProject.test.ts |
Comprehensive new test suite covering flat packages, src container structures, subpackages, multiple packages error cases, edge cases, and mixed project detection |
test/local/__fixtures__/commands/run/python/prints-error-message-on-project-with-no-detected-start.test.ts |
Updated to remove requirements.txt to properly test the "no detection" scenario with the new detection logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
09d051e to
9a23d04
Compare
fix: remove references to unsupported --entrypoint flag The --entrypoint flag doesn't exist yet, so remove mentions of it from error messages. Updated messages now guide users to fix their project structure instead. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> fix: prefer Node.js over Python when both indicators exist When a project has both package.json and Python indicators (like requirements.txt), prefer Node.js detection instead of throwing an error. This simplifies the user experience for mixed projects. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- dirExists now actually checks for directories using stat().isDirectory() - Warn when detected package is missing __main__.py (python -m will fail) - Rename suggestion handles all invalid chars, not just hyphens - Add tests for src/ as a package and __main__.py warning - Document JS precedence over Python with detailed comment - Fix tests to reflect that requirements.txt no longer affects detection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
__init__.pyfiles.Python project detection
__init__.py..venv) and underscore-prefixed directories (__pycache__,_internal) as they shouldn't be main entrypoints.src/is itself a package (has__init__.py), treat nested directories as subpackages, not separate top-level packages.Actor name derivation
Runtime precedence
package.json) takes precedence over Python indicators when both exist.Error handling
__init__.py— suggests renaming the directory (e.g., my-package/ → my_package/)__init__.py— suggests adding__init__.py__init__.py— suggests both renaming and adding__init__.pyTest plan
__init__.py+ .py | .py only | no .py} = 24 cases, plus 5 individual cases:src/errorCo-Authored-By: Claude Opus 4.6 noreply@anthropic.com