Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aragilar committed Jun 1, 2017
1 parent 1946ee2 commit 6774553
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 21 deletions.
5 changes: 0 additions & 5 deletions .hgignore

This file was deleted.

18 changes: 14 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Installable via pip.
|Documentation Status| |Build Status| |Coverage Status|

Docs at http://venv_tools.rtfd.org.
venv_tools is a collection of tools for managing python virtual environments.

.. image:: https://drone.io/bitbucket.org/aragilar/venv_tools/status.png
:target: https://drone.io/bitbucket.org/aragilar/venv_tools/latest
The advantages of venv_tools are:

* Almost no dependencies
* Simple
* Extensible

.. |Documentation Status| image:: https://readthedocs.org/projects/venv_tools/badge/?version=latest
:target: http://venv_tools.readthedocs.org/en/latest/?badge=latest
.. |Build Status| image:: https://travis-ci.org/aragilar/venv_tools.svg?branch=master
:target: https://travis-ci.org/aragilar/venv_tools
.. |Coverage Status| image:: https://codecov.io/github/aragilar/venv_tools/coverage.svg?branch=master
:target: https://codecov.io/github/aragilar/venv_tools?branch=master
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
with open('README.rst') as f:
long_description = f.read()

deps = ["requests", "virtualenv"]

setuptools.setup(
name="venv_tools",
version = versioneer.get_version(),
packages = setuptools.find_packages(),
install_requires = deps,
install_requires = ["virtualenv"],
author = "James Tocknell",
author_email = "aragilar@gmail.com",
description = "A bunch of tools for using venvs (and virtualenvs) from python.",
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ deps=
setuptools==35.0.2
commands=
flake8 --exclude={envsitepackagesdir}/venv_tools/_version.py {envsitepackagesdir}/venv_tools
basepython=python3

[testenv:pylint]
deps=
pylint
setuptools==35.0.2
commands=
pylint {envsitepackagesdir}/venv_tools
basepython=python3

[testenv:check-manifest]
deps=
Expand Down
12 changes: 7 additions & 5 deletions venv_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
:copyright: (c) 2014 by James Tocknell.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import

import os
import os.path
import tempfile
Expand All @@ -19,7 +17,8 @@
import warnings

from ._utils import (
pathprepend, get_default_venv_builder, is_venv, BIN_DIR, PYTHON_FILENAME
pathprepend, get_default_venv_builder, is_venv, BIN_DIR, PYTHON_FILENAME,
abspath_python_exe,
)

from ._version import get_versions
Expand Down Expand Up @@ -186,7 +185,8 @@ class TemporaryVenv(object):
this should not be relied upon. A warning will be raised if it is
detected that this is running inside a venv.
:param str path_to_python_exe: The absolute path to the python executable.
:param str python_exe: The path to the python executable (relative or
absolute), or the name of the executable on the system path.
:param bool use_virtualenv: Use virtualenv instead of the default to create
the venv.
:param venv_builder: An object which creates a venv. It must define a
Expand All @@ -197,9 +197,11 @@ class TemporaryVenv(object):
:type venv_builder: `venv.EnvBuilder or similar`
"""
def __init__(
self, venv_builder=None, use_virtualenv=False, path_to_python_exe=None,
self, venv_builder=None, use_virtualenv=False, python_exe=None,
**kwargs
):
path_to_python_exe = abspath_python_exe(python_exe)

self._kwargs = kwargs
self._venv_builder = (
venv_builder or
Expand Down
35 changes: 33 additions & 2 deletions venv_tools/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
:copyright: (c) 2014 by James Tocknell.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import

import os
import os.path as pth
import sys
Expand Down Expand Up @@ -118,3 +116,36 @@ def is_venv(path):
Checks whether `path` is a virtualenv/venv.
"""
return is_pep_405_venv(path) or is_virtualenv(path)


def abspath_python_exe(python_exe):
"""
Discover absolute path to python executable given by `python_exe`.
"""
if python_exe is None:
return sys.executable
full_path = pth.abspath(python_exe)
if is_executable(full_path):
return full_path
try:
return abspath_path_executable(python_exe)
except FileNotFoundError:
return RuntimeError("Cannot find " + python_exe)


def is_executable(path):
"""
Check whether `path` is an executable file.
"""
return pth.isfile(path) and os.access(path, os.X_OK)


def abspath_path_executable(executable):
"""
Discover absolute path of executable `executable` on system path.
"""
for path in os.environ["PATH"].split(os.pathsep):
full_path = pth.join(path, executable)
if is_executable(full_path):
return full_path
raise FileNotFoundError(executable + " is not on current path")
2 changes: 0 additions & 2 deletions venv_tools/_venv_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
:copyright: (c) 2014 by James Tocknell.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import

import sys
import shlex
import subprocess
Expand Down

0 comments on commit 6774553

Please sign in to comment.