Metadata-Version: 2.4
Name: tn-venv-create-activate
Version: 0.1.0
Summary: A tn-venv plugin that activates the new environment when creating a new one
Author-email: Evan Yang <quantbit@126.com>
License: Tokenoodle-Everything License
        
        Version: 1.0
        
        Copyright (c) 2026 Tokenoodle-Everything Organization
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, and sublicense the Software,
        subject to the following conditions:
        
        1. The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        2. THE SOFTWARE MAY NOT BE USED FOR ANY COMMERCIAL PURPOSE.
        Commercial purposes include, but are not limited to: selling the Software,
        using the Software within a paid service, monetizing products built upon the Software,
        using the Software for business revenue-generating activities, and integrating the Software
        into commercial products.
        
        3. This license is non-transferable. Any distribution of modified copies of the Software
        must use this exact license and retain this notice; you may not relicense the Software
        or modified derivatives under a different license.
        
        4. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
        INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
        PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
        LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
        TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
        OR OTHER DEALINGS IN THE SOFTWARE.
        
        This is NOT an OSI-approved open source license.
Project-URL: Homepage, https://github.com/tokenoodle-everything/tn-venv-create-activate
Project-URL: Source, https://github.com/tokenoodle-everything/tn-venv-create-activate
Keywords: tn-venv,virtualenv,plugin,activate,shell
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: License.txt
Dynamic: license-file

# tn-venv-create-activate

A [tn-venv](https://github.com/tokenoodle-everything/tn-venv) plugin that
activates the new environment when creating a new one.

```console
$ tn-venv .venv
==> creating virtual environment at C:\project\.venv
==> activating C:\project\.venv in a new powershell shell — type 'exit' to leave
(.venv) PS C:\project>          # ← you land here, already activated
(.venv) PS C:\project> exit     # ← back to your original shell, untouched
```

## Install

```bash
pip install tn-venv-create-activate
```

## Why a subshell?

A child process cannot rewrite the environment block of its parent shell —
that is why plain `tn-venv` can only *print* an activation hint. The
standard workaround (used by `pipenv shell` and `poetry shell`) is to spawn
a fresh interactive shell with the environment already activated, which is
exactly what this plugin does at the end of every successful creation.
Exiting the subshell returns you to your original, unmodified shell.

## Installation

```console
$ pip install tn-venv-create-activate
```

The plugin registers itself through the `tn_venv.plugins` entry-point
group, so any `tn-venv` invocation in the same Python environment picks it
up automatically — no configuration needed.

## How it works

After the environment has been created, the activation scripts written, and
pip seeded (`session_end` hook), the plugin detects the shell you are
typing in and spawns it with the environment activated:

| shell      | mechanism                                                     |
| ---------- | ------------------------------------------------------------- |
| cmd.exe    | `cmd.exe /K activate.bat`                                     |
| PowerShell | `powershell`/`pwsh -NoExit -File Activate.ps1`                |
| bash       | `bash --rcfile <temp rc that sources activate> -i`            |
| zsh        | `ZDOTDIR` temp dir whose `.zshrc` sources yours, then `activate` |
| fish       | `fish -i -C "source activate.fish"`                           |
| other      | `PATH`/`VIRTUAL_ENV` set directly, shell spawned interactively |

Script-based modes get the full feature set of the generated activation
scripts (`deactivate`, prompt prefix, `PYTHONHOME` bookkeeping). The
generic fallback still gives you a working prompt where `python`/`pip`
resolve into the new environment, but without a `deactivate` helper — use
`exit`, which always works.

The plugin stays out of the way when it should:

- non-interactive sessions (pipelines, CI, the tn-venv GUI host) are left
  alone — stdin/stdout must both be TTYs;
- if the target environment is already the active one, nothing happens;
- if the shell cannot be detected, a warning with the manual activation
  path is printed instead.

## Configuration

| Variable                       | Effect                                                        |
| ------------------------------ | ------------------------------------------------------------- |
| `TN_VENV_CREATE_ACTIVATE`      | `0` / `no` / `false` / `off` disables the plugin (e.g. in CI) |
| `TN_VENV_CREATE_ACTIVATE_SHELL` | Force the shell: a name (`cmd`, `powershell`, `pwsh`, `bash`, `zsh`, `fish`, …) or a full path |

Shell detection without the override walks the process tree to find the
nearest ancestor that is a known shell, then falls back to `$SHELL`
(POSIX), `%ComSpec%` (Windows), and finally `/bin/sh`.

## License

Tokenoodle-Everything License 1.0 — see [License.txt](License.txt).
This is **not** an OSI-approved license; commercial use is prohibited.
