Skip to content

Commit

Permalink
Merge ed12160 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored May 22, 2021
2 parents cb35f49 + ed12160 commit b815fba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 75 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 4.3

- A much shorter help message now appears when running `vien` without parameters
- Fixed: `call` printed debug message to stdout

# 4.2

- Trying to `call` a non-existent file now prints a short error message
Expand Down
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[![PyPI version shields.io](https://img.shields.io/pypi/v/vien.svg)](https://pypi.python.org/pypi/vien/)
[![Generic badge](https://img.shields.io/badge/OS-MacOS%20|%20Ubuntu-blue.svg)](#)
[![Generic badge](https://img.shields.io/badge/Python-3.7--3.9-blue.svg)](#)
[![Generic badge](https://img.shields.io/badge/OS-Linux%20|%20macOS-blue.svg)](#)
[![Generic badge](https://img.shields.io/badge/Python-3.7+-blue.svg)](#)

# [vien](https://github.com/rtmigo/vien_py#readme)

**VIEN** is a command-line tool for
managing [Python Virtual Environments](https://docs.python.org/3/library/venv.html)
.
**VIEN** is a command-line tool for managing
[Python Virtual Environments](https://docs.python.org/3/library/venv.html).

It provides one-line shortcuts for:

Expand Down Expand Up @@ -117,8 +116,8 @@ $ vien call main.py

## create

`vien shell` creates a virtual environment corresponding to the working
directory.
`vien shell` creates a virtual environment corresponding to the working
directory.

``` bash
$ cd /path/to/myProject
Expand All @@ -128,8 +127,8 @@ $ vien create
By default `vien` will try to use `python3` as the interpreter for the virtual
environment.

If you have more than one Python version, provide one more argument,
point to the proper interpreter the way you execute it.
If you have more than one Python version, provide one more argument, point to
the proper interpreter the way you execute it.

E.g. if you execute scripts like that

Expand All @@ -149,9 +148,7 @@ Or provide full path to the interpreter:
$ vien create /usr/local/opt/python@3.8/bin/python3
```



## shell
## shell

`vien shell` starts interactive bash session in the virtual environment.

Expand Down Expand Up @@ -218,7 +215,7 @@ $ cd /path/to/myProject
$ vien call main.py
```

The optional `-p` parameter allows you to specify the project directory relative
The optional `-p` parameter allows you to specify the project directory relative
to the parent directory of the file being run.

```bash
Expand All @@ -238,7 +235,7 @@ $ vien delete

## recreate

`vien recreate` old and creates new virtual environment.
`vien recreate` old and creates new virtual environment.

If you decided to start from scratch:

Expand All @@ -254,7 +251,6 @@ $ cd /path/to/myProject
$ vien recreate /usr/local/opt/python@3.10/bin/python3
```


# Virtual environments location

By default, `vien` places virtual environments in the `$HOME/.vien` directory.
Expand Down Expand Up @@ -317,8 +313,8 @@ subprocesses.

# Shebang

On POSIX systems, you can make a `.py` file executable, with `vien` executing
it inside a virtual environment.
On POSIX systems, you can make a `.py` file executable, with `vien` executing it
inside a virtual environment.

Insert the shebang line to the top of the file you want to run. The value of the
shebang depends on the location of the file relative to the project directory.
Expand All @@ -335,8 +331,8 @@ After inserting the shebang, make the file executable:
$ chmod +x runme.py
```

Now you can run the `runme.py` directly from command line. This will use the
virtual environment associated with the `myProject`. The working directory can
Now you can run the `runme.py` directly from command line. This will use the
virtual environment associated with the `myProject`. The working directory can
be anything.

``` bash
Expand Down
2 changes: 1 addition & 1 deletion vien/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "4.2.0"
__version__ = "4.3.0"
__copyright__ = "(c) 2020-2021 Artëm IG <github.com/rtmigo>"
__license__ = "BSD-3-Clause"

67 changes: 12 additions & 55 deletions vien/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, exit_code: int):
super().__init__(exit_code)


class VenvExistsExit(VienExit):
class VenvExistsExit(VienExit): # todo does it return error code?
pass


Expand Down Expand Up @@ -80,43 +80,9 @@ def usage_doc():
text = f"""{version_message()}
See a detailed intro at
https://github.com/rtmigo/vien#readme
https://github.com/rtmigo/vien_py#readme
VIENDIR
-------
VIEN maps project directory names to virtualenv paths.
/here/myProject -> $VIENDIR/myProject_venv
/there/myProject -> $VIENDIR/myProject_venv
/there/otherProject -> $VIENDIR/otherProject_venv
By default $VIENDIR is "~/.vien". You can redefine in with
export VIENDIR="/other/location"
The current $VIENDIR is
{get_vien_dir()}
QUICK START
-----------
CREATE new virtualenv with python3 in $VIENDIR/myProject_venv:
cd /abc/myProject
vien create python3
RUN an interactive BASH SUBSHELL inside "myProject_venv":
cd /abc/myProject
vien shell
RUN a PYTHON SCRIPT inside "myProject_venv":
cd /abc/myProject
vien run python3 ./myProgram.py arg1 arg2 ...
HELP
----"""
"""

doc = text.strip()
above_first_line = ("-" * len(doc.splitlines()[0]))
Expand Down Expand Up @@ -152,14 +118,12 @@ def quote(arg: str) -> str:
return json.dumps(arg)


def venv_dir_to_exe(venv_dir: Path) -> Path:
c = venv_dir / "bin" / "python"
if c.exists():
return c
c = venv_dir / "bin" / "python3"
if c.exists():
return c
raise Exception(f"Cannot find the interpreter in {venv_dir}.")
def venv_dir_to_python_exe(venv_dir: Path) -> Path:
for sub in ("bin/python", "bin/python3"):
p = venv_dir/sub
if p.exists():
return p
raise Exception(f"Cannot find the Python interpreter in {venv_dir}.")


def get_python_interpreter(argument: str) -> str:
Expand All @@ -181,7 +145,7 @@ def main_create(venv_dir: Path, version: str):
if result.returncode == 0:
print()
print("The Python executable:")
print(str(venv_dir_to_exe(venv_dir)))
print(str(venv_dir_to_python_exe(venv_dir)))
else:
raise FailedToCreateVenvExit(venv_dir)

Expand All @@ -191,7 +155,7 @@ def main_delete(venv_dir: Path):
raise ValueError(venv_dir)
if not venv_dir.exists():
raise VenvDoesNotExistExit(venv_dir)
python_exe = venv_dir_to_exe(venv_dir)
python_exe = venv_dir_to_python_exe(venv_dir)
print(f"Clearing {venv_dir}")

result = subprocess.run([python_exe, "-m", "venv", str(venv_dir)])
Expand Down Expand Up @@ -353,17 +317,10 @@ def main_call(py_file: str, proj_rel_path: Optional[str],
else:
proj_path = Path('.')

print(f"PROJ PATH: {proj_path}")

dirs = Dirs(proj_path).existing()

# print(parsed.p)
# exit()
# if not os.path.exists()
_run(venv_dir=dirs.venv_dir, other_args=['python', str(file)] + other_args,
prepend_py_path=str(proj_path) if proj_rel_path else None
)
# main_run(dirs.venv_dir, )
prepend_py_path=str(proj_path) if proj_rel_path else None)


def main_entry_point(args: Optional[List[str]] = None):
Expand Down

0 comments on commit b815fba

Please sign in to comment.