Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 100 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,102 @@
!/tests/bin/
*$py.class
*,cover
*.bak
*.egg
*.egg-info/
*.iws
*.launch
*.log
*.manifest
*.mo
*.pot
*.py[cod]
*.pyc
/build/
/dist/
*.pydevproject
*.sage.py
*.so
*.spec
*.swp
*.tmp
*~.nib
.Python
.buildpath
.cache
.cache-main
.classpath
.coverage
.coverage.*
.cproject
.eggs/
.env
.externalToolBuilders/
.factorypath
.hypothesis/
.idea/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/dataSources.xml
.idea/**/dataSources/
.idea/**/dynamic.xml
.idea/**/gradle.xml
.idea/**/libraries
.idea/**/mongoSettings.xml
.idea/**/sqlDataSources.xml
.idea/**/tasks.xml
.idea/**/uiDesigner.xml
.idea/**/workspace.xml
.idea/dictionaries
.idea/replstate.xml
.idea/sonarlint
.idea/vcs.xml
.idea_modules/
.installed.cfg
.ipynb_checkpoints
.loadpath
.metadata
.project
.pydevproject
.python-version
.recommenders
.recommenders/
.ropeproject
.settings/
.target
.texlipse
.tox/
.venv
.vscode
.webassets-cache
.worksheet
/out/
/site
ENV/
__pycache__/
atlassian-ide-plugin.xml
build/
celerybeat-schedule
cmake-build-debug/
com_crashlytics_export_strings.xml
coverage.xml
crashlytics-build.properties
crashlytics.properties
dags/*.py
develop-eggs/
dist/
downloads/
eggs/
env/
lib/
lib64/
local.properties
local_settings.py
nosetests.xml
parts/
pip-log.txt
sdist/
target/
tmp/
var/
venv/
wheels/
/virtualenv_api.egg-info/
6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include README.rst requirements.txt
exclude tests.py
recursive-exclude * __pycache__
recursive-exclude * *.pyc
recursive-exclude * *.pyo
recursive-exclude * *.orig
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Installation

The latest stable release is available on `PyPi`_:

::
.. code:: bash

$ pip install virtualenv-api

Expand All @@ -37,7 +37,7 @@ package is named ``virtualenvapi``.

Alternatively, you may fetch the latest version from git:

::
.. code:: bash

$ pip install git+https://github.com/sjkingo/virtualenv-api.git

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
six
virtualenv
19 changes: 16 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import os

from setuptools import find_packages, setup

from virtualenvapi import __version__

here = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(here, 'README.rst'), 'r') as fh:
long_description = fh.read()

with open(os.path.join(here,'requirements.txt'), 'r') as fh:
requirements = fh.read().split("\n")

setup(
name='virtualenv-api',
version=__version__,
license='BSD',
author='Sam Kingston and AUTHORS',
author_email='sam@sjkwi.com.au',
description='An API for virtualenv/pip',
long_description=open('README.rst', 'r').read(),
long_description=long_description,
long_description_content_type="text/x-rst",
url='https://github.com/sjkingo/virtualenv-api',
install_requires=['six'],
packages=find_packages(),
install_requires=requirements,
packages=find_packages(exclude=["tests", "tests.*"]),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
Expand All @@ -25,6 +36,8 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Software Development :: Libraries :: Python Modules',
],
include_package_data=True,
)
25 changes: 13 additions & 12 deletions virtualenvapi/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ def root(self):
"""The root directory that this virtual environment exists in."""
return os.path.split(self.path)[0]

@property
def name(self):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virtualenv can handle absolute path of a target directory, let's use it instead of relative one.

"""The name of this virtual environment (taken from its path)."""
return os.path.basename(self.path)

@property
def _logfile(self):
"""Absolute path of the log file for recording installation output."""
Expand All @@ -92,22 +87,28 @@ def _errorfile(self):
"""Absolute path of the log file for recording installation errors."""
return os.path.join(self.path, 'build.err')

@property
def _virtualenv(self):
"""The arguments used to call virtualenv."""

return [sys.executable, '-m', 'virtualenv']
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because now we can be sure that virtualenv is installed into the same environment as the current package, we can call it directly. Otherwise it is possible to receive some strange caused by wrong PATH value or too old virtualenv package.


def _create(self):
"""Executes `virtualenv` to create a new environment."""
if self.readonly:
raise VirtualenvReadonlyException()
args = ['virtualenv']

args = []
if self.system_site_packages:
args.append('--system-site-packages')
if self.python is None:
args.append(self.name)
else:
args.extend(['-p', self.python, self.name])
proc = subprocess.Popen(args, cwd=self.root, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if self.python is not None:
args.extend(['-p', self.python])

proc = subprocess.Popen(self._virtualenv + args + [self.path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = proc.communicate()
returncode = proc.returncode
if returncode:
raise VirtualenvCreationException((returncode, output, self.name))
raise VirtualenvCreationException((returncode, output, self.path))
self._write_to_log(output, truncate=True)
self._write_to_error(error, truncate=True)

Expand Down