Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

note an alternative for running src packages locally. #1661

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ekohilas
Copy link
Contributor

@ekohilas ekohilas commented Nov 18, 2024

Upon converting a package to src structure, a user is left unable to run their code via the normal python command, python src/awesome_project/__main__.py

This PR adds an alternative approach that doesn't require an in file workaround.


📚 Documentation preview 📚: https://python-packaging-user-guide--1661.org.readthedocs.build/en/1661/discussions/src-layout-vs-flat-layout/#running-a-command-line-interface-from-source-with-src-layout

@sinoroc
Copy link
Contributor

sinoroc commented Nov 18, 2024

I don't think we should have this in the guide. The whole point of the src layout is to not do that, and by "that" I mean importing from the current working directory, because it is cause for shooting oneself in the foot.

If we want to have this, it should be a small foot note hidden somewhere no one looks. Well maybe not that bad, but it definitely should not be the first suggestion. The first suggestion should be to install (as editable).

@ekohilas
Copy link
Contributor Author

If we want to have this, it should be a small foot note hidden somewhere no one looks. Well maybe not that bad, but it definitely should not be the first suggestion. The first suggestion should be to install (as editable).

Ah thank you, I see your point.

I have updated to address that.

To run a command-line interface directly, you can install the package in
:doc:`Development Mode <setuptools:userguide/development_mode>` for testing purposes.

Since this can be unpractical in some situations, you can also either:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Since this can be unpractical in some situations, you can also either:
Since this can be impractical in some situations, you can also either:

cd src/
python -m awesome_package

Or prepend the package folder to Python's :py:data:`sys.path` when called via its
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are options, they should probably be bullet points. It's weird to have two consequent paragraphs ending with a colon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webknjaz
Copy link
Member

Honestly, I share @sinoroc's sentiment on including dark sorcery into this document. Runpy scripts usually need dependencies, that are declared in the packaging metadata. So it doesn't really make sense to showcase an execution method that is broken half the time, forcing the reader to track down what they have to install. OTOH, pip install -e . will always put both dependencies and the importables on $PYTHONPATH. Always correctly.
Should we really indulge a PYTHONPATH=src/ python -m awesome_package in this case? Wouldn't it create more confusion to an entire class of newcomers?

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.

4 participants