Skip to content

Commit

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

- `call` is now faster as it launches Python directly without spawning an extra
shell process

# 4.3

- A much shorter help message now appears when running `vien` without parameters
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,16 @@ $ _

Now you're back.

With shell pipes, you can specify what the shell should execute right in the
command line.

``` bash
$ echo "which python3 && echo $PATH" | vien shell
```

## run

`vien run COMMAND` runs any shell command in the virtual environment.
`vien run COMMAND` runs a shell command in the virtual environment.

``` bash
$ cd /path/to/myProject
Expand Down
2 changes: 1 addition & 1 deletion vien/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.3.2"
__version__ = "4.4.0"
__copyright__ = "(c) 2020-2021 Artëm IG <github.com/rtmigo>"
__license__ = "BSD-3-Clause"
31 changes: 26 additions & 5 deletions vien/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def quote(arg: str) -> str:

def venv_dir_to_python_exe(venv_dir: Path) -> Path:
for sub in ("bin/python", "bin/python3"):
p = venv_dir/sub
p = venv_dir / sub
if p.exists():
return p
raise Exception(f"Cannot find the Python interpreter in {venv_dir}.")
Expand Down Expand Up @@ -302,10 +302,16 @@ def existing(self) -> Dirs:
return self


def _insert_into_pythonpath(insert_me: str) -> str:
# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH
# "The format is the same as the shell’s PATH: one or more directory
# pathnames separated by os.pathsep (e.g. colons on Unix or semicolons
# on Windows)"
return os.pathsep.join([insert_me] + sys.path)


def main_call(py_file: str, proj_rel_path: Optional[str],
other_args: List[str]):
# todo run python directly, without shell and activate

file = Path(py_file)
if not file.exists():
raise PyFileNotFoundExit(file)
Expand All @@ -319,8 +325,23 @@ def main_call(py_file: str, proj_rel_path: Optional[str],

dirs = Dirs(proj_path).existing()

_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)
# todo allow python options (before file name)

python_exe = venv_dir_to_python_exe(dirs.venv_dir)
args = [str(python_exe), str(file)] + other_args

env: Optional[Dict]
if proj_rel_path:
env = {
**os.environ,
'PYTHONPATH': _insert_into_pythonpath(str(proj_path))
}
else:
env = None

cp = subprocess.run(args, env=env)

raise ChildExit(cp.returncode)


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

0 comments on commit 14383cf

Please sign in to comment.