venv-init 1.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- venv_init-1.1.1/.github/workflows/release.yml +54 -0
- venv_init-1.1.1/.gitignore +2 -0
- venv_init-1.1.1/LICENSE +21 -0
- venv_init-1.1.1/PKG-INFO +76 -0
- venv_init-1.1.1/README.md +59 -0
- venv_init-1.1.1/pyproject.toml +30 -0
- venv_init-1.1.1/src/venv_init/__init__.py +3 -0
- venv_init-1.1.1/src/venv_init/cli.py +169 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags:
|
|
7
|
+
- "v*"
|
|
8
|
+
pull_request:
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.13"
|
|
23
|
+
|
|
24
|
+
- name: Build package
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip build
|
|
27
|
+
python -m build
|
|
28
|
+
|
|
29
|
+
- name: Save package files
|
|
30
|
+
uses: actions/upload-artifact@v4
|
|
31
|
+
with:
|
|
32
|
+
name: python-package
|
|
33
|
+
path: dist/
|
|
34
|
+
|
|
35
|
+
publish:
|
|
36
|
+
needs: build
|
|
37
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
environment:
|
|
40
|
+
name: pypi
|
|
41
|
+
url: https://pypi.org/p/venv-init
|
|
42
|
+
permissions:
|
|
43
|
+
id-token: write
|
|
44
|
+
|
|
45
|
+
steps:
|
|
46
|
+
- name: Get package files
|
|
47
|
+
uses: actions/download-artifact@v4
|
|
48
|
+
with:
|
|
49
|
+
name: python-package
|
|
50
|
+
path: dist/
|
|
51
|
+
|
|
52
|
+
- name: Upload to PyPI
|
|
53
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
54
|
+
|
venv_init-1.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HaloMaster6482
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
venv_init-1.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: venv-init
|
|
3
|
+
Version: 1.1.1
|
|
4
|
+
Summary: Create and activate Python virtual environments from a simple CLI.
|
|
5
|
+
Project-URL: Homepage, https://github.com/HaloMaster6482/venv-init
|
|
6
|
+
Author: HaloMaster6482
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# venv-init
|
|
19
|
+
|
|
20
|
+
`venv-init` is a small command-line utility for creating and activating Python
|
|
21
|
+
virtual environments. On Windows, activation starts a PowerShell session that
|
|
22
|
+
sets a process-only execution policy before loading the environment's activation
|
|
23
|
+
script—no machine-wide policy change is made.
|
|
24
|
+
|
|
25
|
+
## Install from PyPI
|
|
26
|
+
|
|
27
|
+
```powershell
|
|
28
|
+
py -m pip install venv-init
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Upgrade an existing installation with:
|
|
32
|
+
|
|
33
|
+
```powershell
|
|
34
|
+
venv-init --update
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```text
|
|
40
|
+
venv-init --help
|
|
41
|
+
venv-init --version
|
|
42
|
+
venv-init --create [PATH]
|
|
43
|
+
venv-init --activate [PATH]
|
|
44
|
+
venv-init --update
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`PATH` defaults to `.venv` in the current directory. Create it first:
|
|
48
|
+
|
|
49
|
+
```powershell
|
|
50
|
+
venv-init --create
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The command asks which installed Python version to use. Press Enter to use the
|
|
54
|
+
same interpreter that is running `venv-init`, or enter a version such as `3.11`.
|
|
55
|
+
It shows a success message after creation and clear errors if the requested
|
|
56
|
+
Python or environment cannot be found.
|
|
57
|
+
|
|
58
|
+
Then activate it:
|
|
59
|
+
|
|
60
|
+
```powershell
|
|
61
|
+
venv-init --activate
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
On Windows, `--activate` opens a child PowerShell session and runs
|
|
65
|
+
`Set-ExecutionPolicy -Scope Process Bypass` before it runs `Activate.ps1`.
|
|
66
|
+
The virtual environment stays active until you run `deactivate` or close that
|
|
67
|
+
session. The execution-policy setting disappears when the session ends.
|
|
68
|
+
The PowerShell session also confirms when activation succeeds. `--update`
|
|
69
|
+
prints a confirmation when the upgrade completes.
|
|
70
|
+
|
|
71
|
+
On macOS and Linux, `--activate` prints the shell command to run, because a
|
|
72
|
+
program cannot activate an environment in its parent shell.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# venv-init
|
|
2
|
+
|
|
3
|
+
`venv-init` is a small command-line utility for creating and activating Python
|
|
4
|
+
virtual environments. On Windows, activation starts a PowerShell session that
|
|
5
|
+
sets a process-only execution policy before loading the environment's activation
|
|
6
|
+
script—no machine-wide policy change is made.
|
|
7
|
+
|
|
8
|
+
## Install from PyPI
|
|
9
|
+
|
|
10
|
+
```powershell
|
|
11
|
+
py -m pip install venv-init
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Upgrade an existing installation with:
|
|
15
|
+
|
|
16
|
+
```powershell
|
|
17
|
+
venv-init --update
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
venv-init --help
|
|
24
|
+
venv-init --version
|
|
25
|
+
venv-init --create [PATH]
|
|
26
|
+
venv-init --activate [PATH]
|
|
27
|
+
venv-init --update
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`PATH` defaults to `.venv` in the current directory. Create it first:
|
|
31
|
+
|
|
32
|
+
```powershell
|
|
33
|
+
venv-init --create
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The command asks which installed Python version to use. Press Enter to use the
|
|
37
|
+
same interpreter that is running `venv-init`, or enter a version such as `3.11`.
|
|
38
|
+
It shows a success message after creation and clear errors if the requested
|
|
39
|
+
Python or environment cannot be found.
|
|
40
|
+
|
|
41
|
+
Then activate it:
|
|
42
|
+
|
|
43
|
+
```powershell
|
|
44
|
+
venv-init --activate
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
On Windows, `--activate` opens a child PowerShell session and runs
|
|
48
|
+
`Set-ExecutionPolicy -Scope Process Bypass` before it runs `Activate.ps1`.
|
|
49
|
+
The virtual environment stays active until you run `deactivate` or close that
|
|
50
|
+
session. The execution-policy setting disappears when the session ends.
|
|
51
|
+
The PowerShell session also confirms when activation succeeds. `--update`
|
|
52
|
+
prints a confirmation when the upgrade completes.
|
|
53
|
+
|
|
54
|
+
On macOS and Linux, `--activate` prints the shell command to run, because a
|
|
55
|
+
program cannot activate an environment in its parent shell.
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling >= 1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "venv-init"
|
|
7
|
+
version = "1.1.1"
|
|
8
|
+
description = "Create and activate Python virtual environments from a simple CLI."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICEN[CS]E*"]
|
|
13
|
+
authors = [{name = "HaloMaster6482"}]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 5 - Production/Stable",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Operating System :: Microsoft :: Windows"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
venv-init = "venv_init.cli:main"
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/HaloMaster6482/venv-init"
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
include = ["venv_init*"]
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""Command-line interface for venv-init."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
from . import __version__
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _environment_path(value: str | None) -> Path:
|
|
16
|
+
"""Return the requested environment location, defaulting to .venv."""
|
|
17
|
+
return Path(value or ".venv").expanduser().resolve()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _choose_python() -> list[str] | None:
|
|
21
|
+
"""Prompt for a Python version and return its command invocation."""
|
|
22
|
+
current_version = f"{sys.version_info.major}.{sys.version_info.minor}"
|
|
23
|
+
try:
|
|
24
|
+
requested = input(f"Python version to use [current: {current_version}]: ").strip()
|
|
25
|
+
except (EOFError, KeyboardInterrupt):
|
|
26
|
+
print("\nCreation cancelled: no Python version was selected.", file=sys.stderr)
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
if not requested:
|
|
30
|
+
return [sys.executable]
|
|
31
|
+
|
|
32
|
+
if os.name == "nt":
|
|
33
|
+
candidate = ["py", f"-{requested}"]
|
|
34
|
+
else:
|
|
35
|
+
executable = shutil.which(f"python{requested}")
|
|
36
|
+
candidate = [executable] if executable else []
|
|
37
|
+
|
|
38
|
+
if not candidate:
|
|
39
|
+
print(f"Python {requested} was not found on PATH.", file=sys.stderr)
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
check = subprocess.run(
|
|
44
|
+
[*candidate, "--version"], capture_output=True, text=True, check=False
|
|
45
|
+
)
|
|
46
|
+
except OSError as error:
|
|
47
|
+
print(f"Could not start Python {requested}: {error}", file=sys.stderr)
|
|
48
|
+
return None
|
|
49
|
+
if check.returncode != 0:
|
|
50
|
+
detail = (check.stderr or check.stdout).strip()
|
|
51
|
+
print(f"Python {requested} is unavailable. {detail}", file=sys.stderr)
|
|
52
|
+
return None
|
|
53
|
+
return candidate
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def create_environment(path: Path) -> int:
|
|
57
|
+
"""Ask for a Python version, then create a virtual environment with it."""
|
|
58
|
+
if path.exists() and any(path.iterdir()):
|
|
59
|
+
print(f"Refusing to replace existing non-empty directory: {path}", file=sys.stderr)
|
|
60
|
+
return 1
|
|
61
|
+
|
|
62
|
+
python_command = _choose_python()
|
|
63
|
+
if python_command is None:
|
|
64
|
+
return 1
|
|
65
|
+
|
|
66
|
+
print(f"Creating virtual environment: {path}")
|
|
67
|
+
try:
|
|
68
|
+
result = subprocess.run([*python_command, "-m", "venv", str(path)], check=False)
|
|
69
|
+
except OSError as error:
|
|
70
|
+
print(f"Could not create virtual environment: {error}", file=sys.stderr)
|
|
71
|
+
return 1
|
|
72
|
+
if result.returncode != 0:
|
|
73
|
+
print("Virtual environment creation failed.", file=sys.stderr)
|
|
74
|
+
return result.returncode or 1
|
|
75
|
+
|
|
76
|
+
print(f"Virtual environment created successfully: {path}")
|
|
77
|
+
return 0
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def activate_environment(path: Path) -> int:
|
|
81
|
+
"""Activate *path* on Windows, or show the portable shell command."""
|
|
82
|
+
if not path.is_dir():
|
|
83
|
+
print(f"Virtual environment not found: {path}. Run --create first.", file=sys.stderr)
|
|
84
|
+
return 1
|
|
85
|
+
|
|
86
|
+
if os.name == "nt":
|
|
87
|
+
script = path / "Scripts" / "Activate.ps1"
|
|
88
|
+
if not script.is_file():
|
|
89
|
+
print(f"Activation script not found: {script}", file=sys.stderr)
|
|
90
|
+
return 1
|
|
91
|
+
|
|
92
|
+
# A child PowerShell is necessary: a CLI cannot modify its caller's shell.
|
|
93
|
+
escaped_script = str(script).replace("'", "''")
|
|
94
|
+
command = (
|
|
95
|
+
"$ErrorActionPreference = 'Stop'; "
|
|
96
|
+
"Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force; "
|
|
97
|
+
f". '{escaped_script}'; "
|
|
98
|
+
"Write-Host 'Virtual environment activated successfully. "
|
|
99
|
+
"Type deactivate when finished.'"
|
|
100
|
+
)
|
|
101
|
+
print("Starting an activated PowerShell session...")
|
|
102
|
+
try:
|
|
103
|
+
result = subprocess.call([
|
|
104
|
+
"powershell", "-NoExit", "-NoProfile", "-Command", command
|
|
105
|
+
])
|
|
106
|
+
except OSError as error:
|
|
107
|
+
print(f"Could not start PowerShell: {error}", file=sys.stderr)
|
|
108
|
+
return 1
|
|
109
|
+
if result:
|
|
110
|
+
print("Virtual environment activation failed.", file=sys.stderr)
|
|
111
|
+
return result
|
|
112
|
+
|
|
113
|
+
script = path / "bin" / "activate"
|
|
114
|
+
if not script.is_file():
|
|
115
|
+
print(f"Activation script not found: {script}", file=sys.stderr)
|
|
116
|
+
return 1
|
|
117
|
+
print(f"Activation command ready. Run this in your current shell:\n . '{script}'")
|
|
118
|
+
return 0
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def update_package() -> int:
|
|
122
|
+
"""Upgrade this package through the current Python interpreter."""
|
|
123
|
+
try:
|
|
124
|
+
result = subprocess.call([
|
|
125
|
+
sys.executable, "-m", "pip", "install", "--upgrade", "venv-init"
|
|
126
|
+
])
|
|
127
|
+
except OSError as error:
|
|
128
|
+
print(f"Could not update venv-init: {error}", file=sys.stderr)
|
|
129
|
+
return 1
|
|
130
|
+
if result:
|
|
131
|
+
print("venv-init update failed.", file=sys.stderr)
|
|
132
|
+
return result
|
|
133
|
+
print("venv-init updated successfully.")
|
|
134
|
+
return 0
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
138
|
+
parser = argparse.ArgumentParser(
|
|
139
|
+
prog="venv-init",
|
|
140
|
+
description="Create and activate Python virtual environments.",
|
|
141
|
+
)
|
|
142
|
+
actions = parser.add_mutually_exclusive_group()
|
|
143
|
+
actions.add_argument("--create", metavar="PATH", nargs="?", const=".venv",
|
|
144
|
+
help="create a virtual environment (default: .venv)")
|
|
145
|
+
actions.add_argument("--activate", metavar="PATH", nargs="?", const=".venv",
|
|
146
|
+
help="activate a virtual environment (default: .venv)")
|
|
147
|
+
actions.add_argument("--update", action="store_true",
|
|
148
|
+
help="upgrade venv-init from PyPI")
|
|
149
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
150
|
+
return parser
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def main(argv: list[str] | None = None) -> int:
|
|
154
|
+
parser = build_parser()
|
|
155
|
+
args = parser.parse_args(argv)
|
|
156
|
+
|
|
157
|
+
if args.create is not None:
|
|
158
|
+
return create_environment(_environment_path(args.create))
|
|
159
|
+
if args.activate is not None:
|
|
160
|
+
return activate_environment(_environment_path(args.activate))
|
|
161
|
+
if args.update:
|
|
162
|
+
return update_package()
|
|
163
|
+
|
|
164
|
+
parser.print_help()
|
|
165
|
+
return 0
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
raise SystemExit(main())
|