Skip to content

Commit b815fba

Browse files
Merge ed12160 into master
2 parents cb35f49 + ed12160 commit b815fba

File tree

4 files changed

+33
-75
lines changed

4 files changed

+33
-75
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 4.3
2+
3+
- A much shorter help message now appears when running `vien` without parameters
4+
- Fixed: `call` printed debug message to stdout
5+
16
# 4.2
27

38
- Trying to `call` a non-existent file now prints a short error message

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
[![PyPI version shields.io](https://img.shields.io/pypi/v/vien.svg)](https://pypi.python.org/pypi/vien/)
2-
[![Generic badge](https://img.shields.io/badge/OS-MacOS%20|%20Ubuntu-blue.svg)](#)
3-
[![Generic badge](https://img.shields.io/badge/Python-3.7--3.9-blue.svg)](#)
2+
[![Generic badge](https://img.shields.io/badge/OS-Linux%20|%20macOS-blue.svg)](#)
3+
[![Generic badge](https://img.shields.io/badge/Python-3.7+-blue.svg)](#)
44

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

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

1110
It provides one-line shortcuts for:
1211

@@ -117,8 +116,8 @@ $ vien call main.py
117116

118117
## create
119118

120-
`vien shell` creates a virtual environment corresponding to the working
121-
directory.
119+
`vien shell` creates a virtual environment corresponding to the working
120+
directory.
122121

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

131-
If you have more than one Python version, provide one more argument,
132-
point to the proper interpreter the way you execute it.
130+
If you have more than one Python version, provide one more argument, point to
131+
the proper interpreter the way you execute it.
133132

134133
E.g. if you execute scripts like that
135134

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

152-
153-
154-
## shell
151+
## shell
155152

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

@@ -218,7 +215,7 @@ $ cd /path/to/myProject
218215
$ vien call main.py
219216
```
220217

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

224221
```bash
@@ -238,7 +235,7 @@ $ vien delete
238235

239236
## recreate
240237

241-
`vien recreate` old and creates new virtual environment.
238+
`vien recreate` old and creates new virtual environment.
242239

243240
If you decided to start from scratch:
244241

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

257-
258254
# Virtual environments location
259255

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

318314
# Shebang
319315

320-
On POSIX systems, you can make a `.py` file executable, with `vien` executing
321-
it inside a virtual environment.
316+
On POSIX systems, you can make a `.py` file executable, with `vien` executing it
317+
inside a virtual environment.
322318

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

338-
Now you can run the `runme.py` directly from command line. This will use the
339-
virtual environment associated with the `myProject`. The working directory can
334+
Now you can run the `runme.py` directly from command line. This will use the
335+
virtual environment associated with the `myProject`. The working directory can
340336
be anything.
341337

342338
``` bash

vien/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "4.2.0"
1+
__version__ = "4.3.0"
22
__copyright__ = "(c) 2020-2021 Artëm IG <github.com/rtmigo>"
33
__license__ = "BSD-3-Clause"
44

vien/main.py

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, exit_code: int):
3939
super().__init__(exit_code)
4040

4141

42-
class VenvExistsExit(VienExit):
42+
class VenvExistsExit(VienExit): # todo does it return error code?
4343
pass
4444

4545

@@ -80,43 +80,9 @@ def usage_doc():
8080
text = f"""{version_message()}
8181
8282
See a detailed intro at
83-
https://github.com/rtmigo/vien#readme
83+
https://github.com/rtmigo/vien_py#readme
8484
85-
86-
VIENDIR
87-
-------
88-
89-
VIEN maps project directory names to virtualenv paths.
90-
91-
/here/myProject -> $VIENDIR/myProject_venv
92-
/there/myProject -> $VIENDIR/myProject_venv
93-
/there/otherProject -> $VIENDIR/otherProject_venv
94-
95-
By default $VIENDIR is "~/.vien". You can redefine in with
96-
97-
export VIENDIR="/other/location"
98-
99-
The current $VIENDIR is
100-
{get_vien_dir()}
101-
102-
103-
QUICK START
104-
-----------
105-
106-
CREATE new virtualenv with python3 in $VIENDIR/myProject_venv:
107-
cd /abc/myProject
108-
vien create python3
109-
110-
RUN an interactive BASH SUBSHELL inside "myProject_venv":
111-
cd /abc/myProject
112-
vien shell
113-
114-
RUN a PYTHON SCRIPT inside "myProject_venv":
115-
cd /abc/myProject
116-
vien run python3 ./myProgram.py arg1 arg2 ...
117-
118-
HELP
119-
----"""
85+
"""
12086

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

154120

155-
def venv_dir_to_exe(venv_dir: Path) -> Path:
156-
c = venv_dir / "bin" / "python"
157-
if c.exists():
158-
return c
159-
c = venv_dir / "bin" / "python3"
160-
if c.exists():
161-
return c
162-
raise Exception(f"Cannot find the interpreter in {venv_dir}.")
121+
def venv_dir_to_python_exe(venv_dir: Path) -> Path:
122+
for sub in ("bin/python", "bin/python3"):
123+
p = venv_dir/sub
124+
if p.exists():
125+
return p
126+
raise Exception(f"Cannot find the Python interpreter in {venv_dir}.")
163127

164128

165129
def get_python_interpreter(argument: str) -> str:
@@ -181,7 +145,7 @@ def main_create(venv_dir: Path, version: str):
181145
if result.returncode == 0:
182146
print()
183147
print("The Python executable:")
184-
print(str(venv_dir_to_exe(venv_dir)))
148+
print(str(venv_dir_to_python_exe(venv_dir)))
185149
else:
186150
raise FailedToCreateVenvExit(venv_dir)
187151

@@ -191,7 +155,7 @@ def main_delete(venv_dir: Path):
191155
raise ValueError(venv_dir)
192156
if not venv_dir.exists():
193157
raise VenvDoesNotExistExit(venv_dir)
194-
python_exe = venv_dir_to_exe(venv_dir)
158+
python_exe = venv_dir_to_python_exe(venv_dir)
195159
print(f"Clearing {venv_dir}")
196160

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

356-
print(f"PROJ PATH: {proj_path}")
357-
358320
dirs = Dirs(proj_path).existing()
359321

360-
# print(parsed.p)
361-
# exit()
362-
# if not os.path.exists()
363322
_run(venv_dir=dirs.venv_dir, other_args=['python', str(file)] + other_args,
364-
prepend_py_path=str(proj_path) if proj_rel_path else None
365-
)
366-
# main_run(dirs.venv_dir, )
323+
prepend_py_path=str(proj_path) if proj_rel_path else None)
367324

368325

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

0 commit comments

Comments
 (0)