refract-venv 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 YakShavingCatHerder
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.
@@ -0,0 +1,515 @@
1
+ Metadata-Version: 2.4
2
+ Name: refract-venv
3
+ Version: 0.1.0
4
+ Summary: Lightweight centralized virtual environment manager for Python
5
+ Author: YakShavingCatHerder
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/YakShavingCatHerder/refract
8
+ Project-URL: Repository, https://github.com/YakShavingCatHerder/refract
9
+ Project-URL: Issues, https://github.com/YakShavingCatHerder/refract/issues
10
+ Keywords: virtualenv,venv,cli,python,developer-tools
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Environment :: Console
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Operating System :: MacOS
21
+ Classifier: Operating System :: POSIX
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Dynamic: license-file
26
+
27
+ <img width="1228" height="407" alt="Screenshot 2026-08-18 at 20 58 54" src="https://github.com/user-attachments/assets/c9759315-d5ed-4844-b3d4-612b71d779e5" />
28
+
29
+ **Lightweight Virtual Environment Manager for Python**
30
+
31
+ Refract centralizes your Python virtual environments in a single location, providing simple commands to create, manage, and switch between project contexts—without the complexity of traditional virtual environment tools.
32
+
33
+ ## Demo
34
+
35
+ ![refract demo](demo/refract.gif)
36
+
37
+ ## Features
38
+
39
+ - **Centralized Management**: All environments stored in `~/.refract/envs/`
40
+ - **Simple Commands**: Intuitive syntax that's easy to remember
41
+ - **Global Access**: Use `refract` from anywhere in your system
42
+ - **Zero Dependencies**: Only requires Python standard library
43
+ - **Seamless Switching**: Instant environment activation with new shell sessions
44
+ - **Colored Prompts**: Clear visual indication of active environment in shell prompt
45
+ - **Clean Organization**: Automatic directory structure management
46
+
47
+ ## Table of Contents
48
+
49
+ - [Demo](#demo)
50
+ - [Installation](#installation)
51
+ - [Quick Start](#quick-start)
52
+ - [Commands Reference](#commands-reference)
53
+ - [Usage Examples](#usage-examples)
54
+ - [Troubleshooting](#troubleshooting)
55
+ - [Contributing](#contributing)
56
+
57
+ ## Installation
58
+
59
+ Refract itself depends only on Python's standard library. The `refract` command and `refract install` (shell integration) are separate steps.
60
+
61
+ **macOS and Linux only.** Windows is not supported.
62
+
63
+ ### Prerequisites
64
+
65
+ - Python 3.10 or higher
66
+ - bash or zsh
67
+
68
+ pip is optional. pipx is optional.
69
+
70
+ ### From source (Python 3 only)
71
+
72
+ Best for minimal servers that may not have pip:
73
+
74
+ ```bash
75
+ git clone git@github.com:YakShavingCatHerder/refract.git
76
+ cd refract
77
+ ./install.sh
78
+ source ~/.zshrc # bash: source ~/.bashrc
79
+ ```
80
+
81
+ This copies `refract.py` to `~/.local/bin/refract`, then runs `refract install`.
82
+
83
+ ### From source with pip
84
+
85
+ ```bash
86
+ git clone git@github.com:YakShavingCatHerder/refract.git
87
+ cd refract
88
+ ./install.sh --pip
89
+ source ~/.zshrc # bash: source ~/.bashrc
90
+ ```
91
+
92
+ ### From source with pipx (optional)
93
+
94
+ ```bash
95
+ ./install.sh --pipx
96
+ source ~/.zshrc # bash: source ~/.bashrc
97
+ ```
98
+
99
+ ### From PyPI
100
+
101
+ The distribution name is `refract-venv`. The command is `refract`.
102
+
103
+ ```bash
104
+ pip install refract-venv
105
+ refract install
106
+ source ~/.zshrc # bash: source ~/.bashrc
107
+ ```
108
+
109
+ If you already use pipx for CLI tools:
110
+
111
+ ```bash
112
+ pipx install refract-venv
113
+ refract install
114
+ source ~/.zshrc # bash: source ~/.bashrc
115
+ ```
116
+
117
+ ### What `refract install` does
118
+
119
+ - Creates `~/.refract/` and `refract.json` (default colorway: green/black)
120
+ - Installs prompt integration in `~/.zshrc` and `~/.bashrc`
121
+ - Installs the shell wrapper in both files (reloads after `refract colorway`)
122
+ - Tells you to restart or source your shell
123
+
124
+ It does **not** install the `refract` executable. Re-running it is idempotent: existing snippets are updated, not duplicated.
125
+
126
+ ### Uninstall
127
+
128
+ From a source checkout:
129
+
130
+ ```bash
131
+ ./uninstall.sh
132
+ ```
133
+
134
+ If you installed the package:
135
+
136
+ ```bash
137
+ pip uninstall refract-venv
138
+ # or: pipx uninstall refract-venv
139
+ ```
140
+
141
+ Virtual environments in `~/.refract/envs/` are left in place. Remove them with `rm -rf ~/.refract`.
142
+
143
+ ## Quick Start
144
+
145
+ After installation, you can immediately start using refract:
146
+
147
+ ```bash
148
+ # Create your first environment
149
+ refract init myproject
150
+
151
+ # List all environments
152
+ refract list
153
+
154
+ # Activate an environment
155
+ refract use myproject
156
+
157
+ # Remove an environment when done
158
+ refract rm myproject
159
+ ```
160
+
161
+ ## Commands Reference
162
+
163
+ `refract init <name>`
164
+
165
+ Creates a new virtual environment with the specified name.
166
+
167
+ **Parameters:**
168
+ - `environment_name`: Must be a valid Python identifier (letters, numbers, underscores only)
169
+
170
+ **Example:**
171
+ ```bash
172
+ $ refract init django_project
173
+ Created new virtualenv at /path/to/.refract/envs/django_project
174
+ ```
175
+
176
+ **What happens:**
177
+ - Creates a new virtual environment in `~/.refract/envs/<name>/`
178
+ - Uses Python's built-in `venv` module
179
+ - Validates the environment name format
180
+ - Prevents duplicate environment creation
181
+ ---------------
182
+ `refract list`
183
+
184
+ Displays all available virtual environments.
185
+
186
+ **Example Output:**
187
+ ```bash
188
+ $ refract list
189
+ Available virtualenvs:
190
+ * django_project
191
+ * flask_api
192
+ * data_analysis
193
+ * machine_learning
194
+ ```
195
+
196
+ **What happens:**
197
+ - Scans `~/.refract/envs/` directory
198
+ - Lists all subdirectories as available environments
199
+ - Shows helpful message if no environments exist
200
+
201
+ ---------------
202
+ `refract use <name>`
203
+
204
+ Activates the specified virtual environment by opening a new shell session.
205
+
206
+ **Example:**
207
+ ```bash
208
+ $ refract use django_project
209
+ [refract] Switching to environment 'django_project'...
210
+ ```
211
+
212
+ **What happens:**
213
+ 1. Validates the environment exists
214
+ 2. Creates a temporary activation script that:
215
+ - Sources your shell profile files (`.bash_profile`, `.zshrc`, etc.)
216
+ - Activates the virtual environment
217
+ - Opens a new shell session with the environment active
218
+ - Sets up colored prompt showing the active refract environment with `[refract:name]` prefix
219
+ 3. Runs the script in a new shell process
220
+ 4. Removes the temporary script as a cleanup process
221
+
222
+ **After activation, you'll see:**
223
+ ```bash
224
+ [refract:django_project] user@machine ~ %
225
+ ```
226
+ ---------------
227
+ `refract rm <name>`
228
+
229
+ Removes the specified virtual environment.
230
+
231
+ **Example:**
232
+ ```bash
233
+ $ refract rm old_project
234
+ Removed environment 'old_project'
235
+ ```
236
+
237
+ **What happens:**
238
+ - Validates the environment exists
239
+ - Completely removes the environment directory
240
+ - Provides confirmation message
241
+ ---------------
242
+ `refract current`
243
+
244
+ Shows the currently active refract environment.
245
+
246
+ **Example:**
247
+ ```bash
248
+ $ refract current
249
+ Currently in refract environment: django_project
250
+ ```
251
+
252
+ **What happens:**
253
+ - Checks for the `REFRACT_ENV` environment variable
254
+ - Displays the active environment name in light gray if one is active
255
+ - Shows "No refract environment currently active" if none is active
256
+ ---------------
257
+ `refract install`
258
+
259
+ Initializes Refract config and shell integration. The executable must already be on your PATH (via `./install.sh`, `pip`, or `pipx`).
260
+
261
+ **What happens:**
262
+ - Creates `~/.refract/` and `refract.json` if needed
263
+ - Writes prompt hooks and the shell wrapper into `~/.zshrc` and `~/.bashrc`
264
+ - Does not create a symlink or install the `refract` command
265
+
266
+ ## Usage Examples
267
+
268
+ ### Example 1: Web Development Workflow
269
+
270
+ ```
271
+ # Create environments for different projects
272
+ $ refract init frontend
273
+ Created new virtualenv at /Users/path/.refract/envs/frontend
274
+
275
+ $ refract init backend
276
+ Created new virtualenv at /Users/path/.refract/envs/backend
277
+
278
+ # List all environments
279
+ $ refract list
280
+ Available virtualenvs:
281
+ * frontend
282
+ * backend
283
+
284
+ # Switch to frontend work
285
+ $ refract use frontend
286
+ [refract] Switching to environment 'frontend'...
287
+
288
+ # In the new shell session:
289
+ [refract:frontend] $ npm install
290
+ [refract:frontend] $ npm start
291
+
292
+ # Switch to backend work (in another terminal)
293
+ $ refract use backend
294
+ [refract] Switching to environment 'backend'...
295
+
296
+ # In the new shell session:
297
+ [refract:backend] $ pip install django
298
+ [refract:backend] $ python manage.py runserver
299
+ ```
300
+
301
+ ### Example 2: Data Science Workflow
302
+ ```
303
+ # Create specialized environments
304
+ $ refract init data_analysis
305
+ $ refract init ml_experiment
306
+ $ refract init visualization
307
+
308
+ # Switch between different analysis contexts
309
+ $ refract use data_analysis
310
+ [refract:data_analysis] $ pip install pandas numpy matplotlib
311
+
312
+ $ refract use ml_experiment
313
+ [refract:ml_experiment] $ pip install scikit-learn tensorflow
314
+
315
+ $ refract use visualization
316
+ [refract:visualization] $ pip install plotly seaborn bokeh
317
+ ```
318
+
319
+ ### Example 3: Project Cleanup
320
+ ```bash
321
+ # List all environments
322
+ $ refract list
323
+ Available virtualenvs:
324
+ * old_project
325
+ * experiment_1
326
+ * experiment_2
327
+ * current_project
328
+
329
+ # Remove completed experiments
330
+ $ refract rm experiment_1
331
+ Removed environment 'experiment_1'
332
+
333
+ $ refract rm experiment_2
334
+ Removed environment 'experiment_2'
335
+
336
+ # Verify cleanup
337
+ $ refract list
338
+ Available virtualenvs:
339
+ * old_project
340
+ * current_project
341
+ ```
342
+ ---------------
343
+
344
+ ### Directory Structure
345
+
346
+ Refract creates and manages the following structure:
347
+
348
+ ```
349
+ ~/.refract/
350
+ ├── envs/ # All virtual environments
351
+ │ ├── project_a/
352
+ │ │ ├── bin/
353
+ │ │ ├── lib/
354
+ │ │ └── ...
355
+ │ ├── project_b/
356
+ │ │ ├── bin/
357
+ │ │ ├── lib/
358
+ │ │ └── ...
359
+ │ └── ...
360
+ └── refract.json # Configuration file
361
+ ```
362
+
363
+ ### Colored Prompts Feature
364
+
365
+ Refract automatically modifies your shell prompt to show the active environment:
366
+
367
+ - **Format**: `[refract:environment_name]` appears at the beginning of your prompt
368
+ - **Color**: Green background with black text by default to make current venv easily visible
369
+ - **Shell Support**: Works with both bash and zsh
370
+ - **Environment Variable**: Sets `REFRACT_ENV` for programmatic access
371
+
372
+ ## Troubleshooting
373
+
374
+ ### Common Issues
375
+
376
+ #### "command not found: refract"
377
+
378
+ **Problem**: The `refract` command isn't available globally.
379
+
380
+ **Solution**:
381
+ ```bash
382
+ # From a source checkout, install the command then shell integration
383
+ ./install.sh
384
+
385
+ # If the command exists but shell hooks do not
386
+ refract install
387
+
388
+ # Make sure ~/.local/bin is on PATH
389
+ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
390
+ source ~/.zshrc
391
+ ```
392
+
393
+ #### Refract environment is active, but prompt prefix is missing
394
+
395
+ **Problem**: `refract use <name>` activates the environment, but `[refract:<name>]` is not shown in your prompt.
396
+
397
+ **Why this happens**: Some shell themes/frameworks rebuild the prompt and can override custom prompt text.
398
+
399
+ **How to verify activation**:
400
+ ```bash
401
+ echo $REFRACT_ENV
402
+ which python
403
+ ```
404
+
405
+ If active, `REFRACT_ENV` should contain your environment name and `which python` should point to `~/.refract/envs/<name>/bin/python`.
406
+
407
+ #### "Permission denied: refract"
408
+
409
+ **Problem**: The installed script does not have execute permissions.
410
+
411
+ **Solution**:
412
+ ```bash
413
+ chmod +x ~/.local/bin/refract
414
+ ```
415
+
416
+ #### "Environment 'name' does not exist"
417
+
418
+ **Problem**: Trying to use an environment that hasn't been created.
419
+
420
+ **Solution**:
421
+ ```bash
422
+ # Check available environments
423
+ refract list
424
+
425
+ # Create the environment first
426
+ refract init name
427
+ ```
428
+
429
+ #### "Environment name must be a valid identifier"
430
+
431
+ **Problem**: Using invalid characters in environment names.
432
+
433
+ **Solution**: Use only letters, numbers, and underscores:
434
+ ```bash
435
+ # Valid names
436
+ refract init my_project
437
+ refract init project123
438
+ refract init _private
439
+
440
+ # Invalid names
441
+ refract init my-project # hyphens not allowed
442
+ refract init "my project" # spaces not allowed
443
+ refract init my.project # dots not allowed
444
+ ```
445
+
446
+ ### Debug Mode
447
+
448
+ Enable debug output to troubleshoot issues:
449
+
450
+ ```bash
451
+ refract --debug list
452
+ ```
453
+
454
+ This will show additional information about paths and configuration.
455
+
456
+ ### Manual Environment Management
457
+
458
+ If you need to manually manage environments:
459
+
460
+ ```bash
461
+ # List all environments
462
+ ls ~/.refract/envs/
463
+
464
+ # Remove an environment manually
465
+ rm -rf ~/.refract/envs/environment_name
466
+
467
+ # Check refract configuration
468
+ cat ~/.refract/refract.json
469
+ ```
470
+
471
+ ## Contributing
472
+
473
+ ### Development Setup
474
+
475
+ 1. Clone the repository
476
+ 2. Install from source:
477
+ ```bash
478
+ ./install.sh --pip
479
+ ```
480
+ ### Testing
481
+
482
+ CLI tests use a temporary `HOME` and require `refract` on PATH (install the wheel or run `./install.sh --pip` first):
483
+
484
+ ```bash
485
+ python -m unittest discover -s tests -v -p 'test_cli.py'
486
+ ```
487
+
488
+ `./install.sh` methods are tested in CI with `REFRACT_TEST_INSTALL_SH=1`.
489
+
490
+ Regenerate the README GIF with [VHS](https://github.com/charmbracelet/vhs):
491
+
492
+ ```bash
493
+ ./demo/record.sh
494
+ ```
495
+
496
+ ### Code Style
497
+
498
+ - Follow PEP 8 guidelines
499
+ - Use descriptive variable names
500
+ - Add docstrings to functions
501
+ - Include error handling
502
+
503
+ ## License
504
+
505
+ This project is licensed under the MIT License - see the LICENSE file for details.
506
+
507
+ ## Acknowledgments
508
+
509
+ - Built with 1 dependency: Python's standard library
510
+ - Inspired by the need for simpler, cli-native management of virtual environments; perfect for deploying to lightweight servers when needed
511
+ - Thanks to the Python community for the excellent `venv` module; this isn't a diss, just a specific use-case ;)
512
+
513
+ ---
514
+
515
+ **Happy coding with refract! **