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

Add simple, explicit CLI to install a .whl file #92

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/installer/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""CLI - run as python -m installer."""
import argparse

from . import install
from .destinations import SchemeDictionaryDestination
from .sources import WheelFile


def main():
"""Entry point for CLI."""
ap = argparse.ArgumentParser("python -m installer")
ap.add_argument("wheel_file", help="Path to a .whl file to install")

Choose a reason for hiding this comment

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

Does this support installing the wheel file if passed as a glob, like dist/*.whl?

Copy link
Member

Choose a reason for hiding this comment

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

No, it won't be unglobbed in Python, but why would it not be unglobbed in the shell?

Choose a reason for hiding this comment

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

Currently we invoke python setup.py install while in the package directory, maybe we should make the wheel_file argument optional and autodetect the dist folder and install from there if present and a .whl file is there.

Copy link
Member Author

Choose a reason for hiding this comment

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

It will work if the shell expands the glob to a single wheel. At present, it won't accept multiple wheels to install - that's easy enough to do if necessary, but I wanted to start with the simplest thing.

maybe we should make the wheel_file argument optional and autodetect...

I think the crucial 'what to install' input should be 100% explicit. That's in keeping with the general pattern of this library. If you know there's a single wheel under dist, and you're running it from a shell, you can pass dist/*.whl and let the shell expand it.

Choose a reason for hiding this comment

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

it won't accept multiple wheels to install

Oh, not wanting it to do that, just pick up a single wheel from dist actually.

If you know there's a single wheel under dist, and you're running it from a shell, you can pass dist/*.whl and let the shell expand it.

Yeah, was going to do something like that otherwise, figured would be kinda nice to have similar semantics to existing install methods. Maybe have it use only the newest file in dist/*.whl would make sense or something if a glob is passed?


ap.add_argument(
"--interpreter", required=True, help="Interpreter path to be used in scripts"
)
ap.add_argument(
"--script-kind",
required=True,
choices=["posix", "win-ia32", "win-amd64", "win-arm", "win-arm64"],
help="Kind of launcher to create for each script",
)

dest_args = ap.add_argument_group("Destination directories")
dest_args.add_argument(
"--purelib",
required=True,
help="Directory for platform-independent Python modules",
)
dest_args.add_argument(
"--platlib",
required=True,
help="Directory for platform-dependent Python modules",
)
dest_args.add_argument(
"--headers", required=True, help="Directory for C header files"
)
dest_args.add_argument(
"--scripts", required=True, help="Directory for executable scripts"
)
dest_args.add_argument(
"--data", required=True, help="Directory for external data files"
)
args = ap.parse_args()

destination = SchemeDictionaryDestination(
{
"purelib": args.purelib,
"platlib": args.platlib,
takluyver marked this conversation as resolved.
Show resolved Hide resolved
"headers": args.headers,
"scripts": args.scripts,
"data": args.data,
},
interpreter=args.interpreter,
script_kind=args.script_kind,
)

with WheelFile.open(args.wheel_file) as source:
install(
source=source,
destination=destination,
additional_metadata={},
)


if __name__ == "__main__":
main()