@@ -11,6 +11,8 @@
Commands:
command Description
create create a venv
+ post_init
+ post-venv initialization
ensure Ensure that the specified package is installed.
--------------------------------------------------
@@ -25,6 +27,13 @@
--------------------------------------------------
+usage: mkvenv post_init [-h]
+
+options:
+ -h, --help show this help message and exit
+
+--------------------------------------------------
+
usage: mkvenv ensure [-h] [--online] [--dir DIR] dep_spec...
positional arguments:
@@ -189,6 +198,13 @@ def post_post_setup(self, context: SimpleNamespace) -> None:
with open(pth_file, "w", encoding="UTF-8") as file:
file.write(parent_libpath + os.linesep)
+ args = [
+ context.env_exe,
+ __file__,
+ "post_init",
+ ]
+ subprocess.run(args, check=True)
+
def get_value(self, field: str) -> str:
"""
Get a string value from the context namespace after a call to build.
@@ -727,6 +743,17 @@ def ensure(
raise Ouch(diagnose(dep_specs[0], online, wheels_dir, prog)) from exc
+def post_venv_setup() -> None:
+ """
+ This is intended to be run *inside the venv* after it is created.
+ """
+ logger.debug("post_venv_setup()")
+ # Generate a 'pip' script so the venv is usable in a normal
+ # way from the CLI. This only happens when we inherited pip from a
+ # parent/system-site and haven't run ensurepip in some way.
+ generate_console_scripts(["pip"])
+
+
def _add_create_subcommand(subparsers: Any) -> None:
subparser = subparsers.add_parser("create", help="create a venv")
subparser.add_argument(
@@ -737,6 +764,10 @@ def _add_create_subcommand(subparsers: Any) -> None:
)
+def _add_post_init_subcommand(subparsers: Any) -> None:
+ subparsers.add_parser("post_init", help="post-venv initialization")
+
+
def _add_ensure_subcommand(subparsers: Any) -> None:
subparser = subparsers.add_parser(
"ensure", help="Ensure that the specified package is installed."
@@ -790,6 +821,7 @@ def main() -> int:
)
_add_create_subcommand(subparsers)
+ _add_post_init_subcommand(subparsers)
_add_ensure_subcommand(subparsers)
args = parser.parse_args()
@@ -800,6 +832,8 @@ def main() -> int:
system_site_packages=True,
clear=True,
)
+ if args.command == "post_init":
+ post_venv_setup()
if args.command == "ensure":
ensure(
dep_specs=args.dep_specs,