From 6599a8cfd3fe4424c0e38e2475d699780fd1752e Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 3 Jan 2022 12:47:37 +0000 Subject: [PATCH 1/5] Add simple, explicit CLI to install a .whl file --- src/installer/__main__.py | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/installer/__main__.py diff --git a/src/installer/__main__.py b/src/installer/__main__.py new file mode 100644 index 00000000..7e7c396f --- /dev/null +++ b/src/installer/__main__.py @@ -0,0 +1,60 @@ +import argparse + +from . import install +from .destinations import SchemeDictionaryDestination +from .sources import WheelFile + +def main(): + ap = argparse.ArgumentParser("python -m installer") + ap.add_argument("wheel_file", help="Path to a .whl file to install") + + 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, + '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() From 6eaf6e5cc57b28a6149a481b0dd146dfd3ff5454 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Jan 2022 13:14:15 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/installer/__main__.py | 43 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/installer/__main__.py b/src/installer/__main__.py index 7e7c396f..f2b231c1 100644 --- a/src/installer/__main__.py +++ b/src/installer/__main__.py @@ -4,46 +4,50 @@ from .destinations import SchemeDictionaryDestination from .sources import WheelFile + def main(): ap = argparse.ArgumentParser("python -m installer") ap.add_argument("wheel_file", help="Path to a .whl file to install") ap.add_argument( - "--interpreter", required=True, - help="Interpreter path to be used in scripts" + "--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" + "--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" + "--purelib", + required=True, + help="Directory for platform-independent Python modules", ) dest_args.add_argument( - '--platlib', required=True, - help="Directory for platform-dependent Python modules" + "--platlib", + required=True, + help="Directory for platform-dependent Python modules", ) dest_args.add_argument( - '--headers', required=True, help="Directory for C header files" + "--headers", required=True, help="Directory for C header files" ) dest_args.add_argument( - '--scripts', required=True, help="Directory for executable scripts" + "--scripts", required=True, help="Directory for executable scripts" ) dest_args.add_argument( - '--data', required=True, help="Directory for external data files" + "--data", required=True, help="Directory for external data files" ) args = ap.parse_args() - destination = SchemeDictionaryDestination({ - 'purelib': args.purelib, - 'platlib': args.platlib, - 'headers': args.headers, - 'scripts': args.scripts, - 'data': args.data, + destination = SchemeDictionaryDestination( + { + "purelib": args.purelib, + "platlib": args.platlib, + "headers": args.headers, + "scripts": args.scripts, + "data": args.data, }, interpreter=args.interpreter, script_kind=args.script_kind, @@ -56,5 +60,6 @@ def main(): additional_metadata={}, ) -if __name__ == '__main__': + +if __name__ == "__main__": main() From 1cffdcd6eecf1535f89a72eb59e33ac3bb114d61 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 3 Jan 2022 14:02:11 +0000 Subject: [PATCH 3/5] Add mising docstrings --- src/installer/__main__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/installer/__main__.py b/src/installer/__main__.py index f2b231c1..a89aa158 100644 --- a/src/installer/__main__.py +++ b/src/installer/__main__.py @@ -1,3 +1,4 @@ +"""CLI - run as python -m installer""" import argparse from . import install @@ -6,6 +7,7 @@ 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") From bc84d6a7ec43ac9b111ab875465d5195b30b5752 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 3 Jan 2022 14:04:26 +0000 Subject: [PATCH 4/5] Add periods to docstrings --- src/installer/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/installer/__main__.py b/src/installer/__main__.py index a89aa158..ab968174 100644 --- a/src/installer/__main__.py +++ b/src/installer/__main__.py @@ -1,4 +1,4 @@ -"""CLI - run as python -m installer""" +"""CLI - run as python -m installer.""" import argparse from . import install @@ -7,7 +7,7 @@ def main(): - """Entry point for CLI""" + """Entry point for CLI.""" ap = argparse.ArgumentParser("python -m installer") ap.add_argument("wheel_file", help="Path to a .whl file to install") From 4a23b5e09de5fa018c26e117a027a78f8c975518 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 4 Jan 2022 18:11:53 +0000 Subject: [PATCH 5/5] Make --platlib optional --- src/installer/__main__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/installer/__main__.py b/src/installer/__main__.py index ab968174..719ecbf7 100644 --- a/src/installer/__main__.py +++ b/src/installer/__main__.py @@ -29,8 +29,8 @@ def main(): ) dest_args.add_argument( "--platlib", - required=True, - help="Directory for platform-dependent Python modules", + help="Directory for platform-dependent Python modules (same as purelib " + "if not specified)", ) dest_args.add_argument( "--headers", required=True, help="Directory for C header files" @@ -46,7 +46,7 @@ def main(): destination = SchemeDictionaryDestination( { "purelib": args.purelib, - "platlib": args.platlib, + "platlib": args.platlib if args.platlib is not None else args.purelib, "headers": args.headers, "scripts": args.scripts, "data": args.data,