Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for pypy2 and pypy3 #1482

Merged
merged 8 commits into from
Jan 9, 2020
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ dist
/src/virtualenv/version.py
/src/virtualenv/out
/*env*
.python-version
33 changes: 23 additions & 10 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ schedules:
always: true

variables:
PYTEST_ADDOPTS: "-v -v -ra --showlocals --durations=15"
PYTEST_XDIST_PROC_NR: 'auto'
PYTEST_ADDOPTS: "-vv --durations=10"
CI_RUN: 'yes'
UPGRADE_ADVISORY: 'yes'

Expand All @@ -47,6 +46,10 @@ jobs:
image: [linux, windows, macOs]
py27:
image: [linux, windows, macOs]
pypy:
image: [linux, windows, macOs]
pypy3:
image: [linux, windows, macOs]
fix_lint:
image: [linux, windows]
docs:
Expand All @@ -58,28 +61,38 @@ jobs:
dev: null
before:
- script: 'sudo apt-get update -y && sudo apt-get install fish csh'
condition: and(succeeded(), eq(variables['image_name'], 'linux'), in(variables['TOXENV'], 'py38', 'py37', 'py36', 'py35', 'py27'))
condition: and(succeeded(), eq(variables['image_name'], 'linux'), in(variables['TOXENV'], 'py38', 'py37', 'py36', 'py35', 'py27', 'pypy', 'pypy3'))
displayName: install fish and csh via apt-get
- script: 'brew update -vvv && brew install fish tcsh'
condition: and(succeeded(), eq(variables['image_name'], 'macOs'), in(variables['TOXENV'], 'py38', 'py37', 'py36', 'py35', 'py27'))
condition: and(succeeded(), eq(variables['image_name'], 'macOs'), in(variables['TOXENV'], 'py38', 'py37', 'py36', 'py35', 'py27', 'pypy', 'pypy3'))
displayName: install fish and csh via brew
- task: UsePythonVersion@0
condition: and(succeeded(), in(variables['TOXENV'], 'py38', 'py37', 'py36', 'py35'))
displayName: provision cpython 2
inputs:
versionSpec: '2.7'
- task: UsePythonVersion@0
condition: and(succeeded(), in(variables['TOXENV'], 'py27'))
displayName: provision python 3
displayName: provision cpython 3
inputs:
versionSpec: '3.8'
- task: UsePythonVersion@0
condition: and(succeeded(), in(variables['TOXENV'], 'py38', 'py37', 'py36', 'py35'))
displayName: provision python 2
condition: and(succeeded(), in(variables['TOXENV'], 'pypy'))
displayName: provision pypy 3
inputs:
versionSpec: '2.7'
versionSpec: 'pypy3'
- task: UsePythonVersion@0
condition: and(succeeded(), in(variables['TOXENV'], 'pypy3'))
displayName: provision pypy 2
inputs:
versionSpec: 'pypy2'
coverage:
with_toxenv: 'coverage' # generate .tox/.coverage, .tox/coverage.xml after test run
for_envs: [py38, py37, py36, py35, py27]
for_envs: [py38, py37, py36, py35, py27, pypy, pypy3]

- ${{ if startsWith(variables['Build.SourceBranch'], 'refs/tags/') }}:
- template: publish-pypi.yml@tox
parameters:
external_feed: 'gb'
pypi_remote: 'pypi-gb'
dependsOn: [fix_lint, embed, cross_python3, cross_python3, docs, report_coverage, dev, package_readme]
dependsOn: [fix_lint, embed, docs, report_coverage, dev, package_readme]
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ virtualenv.create =
cpython3-win = virtualenv.interpreters.create.cpython.cpython3:CPython3Windows
cpython2-posix = virtualenv.interpreters.create.cpython.cpython2:CPython2Posix
cpython2-win = virtualenv.interpreters.create.cpython.cpython2:CPython2Windows
pypy2-posix = virtualenv.interpreters.create.pypy.pypy2:PyPy2Posix
pypy2-win = virtualenv.interpreters.create.pypy.pypy2:Pypy2Windows
pypy3-posix = virtualenv.interpreters.create.pypy.pypy3:PyPy3Posix
pypy3-win = virtualenv.interpreters.create.pypy.pypy3:Pypy3Windows
venv = virtualenv.interpreters.create.venv:Venv
virtualenv.seed =
none = virtualenv.seed.none:NoneSeeder
Expand Down Expand Up @@ -106,3 +110,4 @@ markers =
pwsh
xonsh
junit_family = xunit2
addopts = --tb=auto -ra --showlocals
2 changes: 1 addition & 1 deletion src/virtualenv/activation/xonosh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def templates(self):

@classmethod
def supports(cls, interpreter):
return True if interpreter.version_info >= (3, 5) else False
return interpreter.version_info >= (3, 5)
40 changes: 32 additions & 8 deletions src/virtualenv/info.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
from __future__ import absolute_import, unicode_literals

import logging
import os
import platform
import sys
import tempfile

from appdirs import user_config_dir, user_data_dir

from virtualenv.util.path import Path

IS_PYPY = hasattr(sys, "pypy_version_info")
IMPLEMENTATION = platform.python_implementation()
IS_PYPY = IMPLEMENTATION == "PyPy"
IS_CPYTHON = IMPLEMENTATION == "CPython"
PY3 = sys.version_info[0] == 3
IS_WIN = sys.platform == "win32"


_DATA_DIR = Path(user_data_dir(appname="virtualenv", appauthor="pypa"))
_CONFIG_DIR = Path(user_config_dir(appname="virtualenv", appauthor="pypa"))
_FS_CASE_SENSITIVE = _CFG_DIR = _DATA_DIR = None


def get_default_data_dir():
from virtualenv.util.path import Path

global _DATA_DIR
if _DATA_DIR is None:
_DATA_DIR = Path(user_data_dir(appname="virtualenv", appauthor="pypa"))
return _DATA_DIR


def get_default_config_dir():
return _CONFIG_DIR
from virtualenv.util.path import Path

global _CFG_DIR
if _CFG_DIR is None:
_CFG_DIR = Path(user_config_dir(appname="virtualenv", appauthor="pypa"))
return _CFG_DIR


def is_fs_case_sensitive():
global _FS_CASE_SENSITIVE

if _FS_CASE_SENSITIVE is None:
with tempfile.NamedTemporaryFile(prefix="TmP") as tmp_file:
_FS_CASE_SENSITIVE = not os.path.exists(tmp_file.name.lower())
logging.debug(
"filesystem under is %r%s case-sensitive", tmp_file.name, "" if _FS_CASE_SENSITIVE else " not"
)
return _FS_CASE_SENSITIVE


__all__ = ("IS_PYPY", "PY3", "IS_WIN", "get_default_data_dir", "get_default_config_dir")
__all__ = ("IS_PYPY", "PY3", "IS_WIN", "get_default_data_dir", "get_default_config_dir", "_FS_CASE_SENSITIVE")
105 changes: 15 additions & 90 deletions src/virtualenv/interpreters/create/cpython/common.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,29 @@
from __future__ import absolute_import, unicode_literals

import abc
from os import X_OK, access, chmod

import six

from virtualenv.interpreters.create.via_global_ref import ViaGlobalRef
from virtualenv.util.path import Path, copy, ensure_dir, symlink
from virtualenv.interpreters.create.support import PosixSupports, WindowsSupports
from virtualenv.interpreters.create.via_global_ref.via_global_self_do import ViaGlobalRefSelfDo
from virtualenv.util.path import Path


@six.add_metaclass(abc.ABCMeta)
class CPython(ViaGlobalRef):
def __init__(self, options, interpreter):
super(CPython, self).__init__(options, interpreter)
self.copier = symlink if self.symlinks is True else copy

class CPython(ViaGlobalRefSelfDo):
@classmethod
def supports(cls, interpreter):
return interpreter.implementation == "CPython"

def create(self):
for directory in self.ensure_directories():
ensure_dir(directory)
self.set_pyenv_cfg()
self.pyenv_cfg.write()
true_system_site = self.system_site_package
try:
self.system_site_package = False
self.setup_python()
finally:
if true_system_site != self.system_site_package:
self.system_site_package = true_system_site

def ensure_directories(self):
dirs = [self.dest_dir, self.bin_dir]
dirs.extend(self.site_packages)
return dirs

def setup_python(self):
python_dir = Path(self.interpreter.system_executable).parent
for name in self.exe_names():
self.add_executable(python_dir, self.bin_dir, name)

@abc.abstractmethod
def lib_name(self):
raise NotImplementedError

@property
def lib_base(self):
raise NotImplementedError
return interpreter.implementation == "CPython" and super(CPython, cls).supports(interpreter)

@property
def lib_dir(self):
return self.dest_dir / self.lib_base

@property
def system_stdlib(self):
return Path(self.interpreter.system_prefix) / self.lib_base

def exe_names(self):
yield Path(self.interpreter.system_executable).name

def add_exe_method(self):
if self.copier is symlink:
return self.symlink_exe
return self.copier

@staticmethod
def symlink_exe(src, dest):
symlink(src, dest)
dest_str = str(dest)
if not access(dest_str, X_OK):
chmod(dest_str, 0o755) # pragma: no cover

def add_executable(self, src, dest, name):
src_ex = src / name
if src_ex.exists():
add_exe_method_ = self.add_exe_method()
add_exe_method_(src_ex, dest / name)
def exe_base(self):
return "python"


@six.add_metaclass(abc.ABCMeta)
class CPythonPosix(CPython):
class CPythonPosix(CPython, PosixSupports):
"""Create a CPython virtual environment on POSIX platforms"""

@classmethod
def supports(cls, interpreter):
return super(CPythonPosix, cls).supports(interpreter) and interpreter.os == "posix"

@property
def bin_name(self):
return "bin"
Expand All @@ -100,23 +36,14 @@ def lib_name(self):
def lib_base(self):
return Path(self.lib_name) / self.interpreter.python_name

def setup_python(self):
"""Just create an exe in the provisioned virtual environment skeleton directory"""
super(CPythonPosix, self).setup_python()
def link_exe(self):
host = Path(self.interpreter.system_executable)
major, minor = self.interpreter.version_info.major, self.interpreter.version_info.minor
target = self.bin_dir / next(self.exe_names())
for suffix in ("python", "python{}".format(major), "python{}.{}".format(major, minor)):
path = self.bin_dir / suffix
if not path.exists():
symlink(target, path, relative_symlinks_ok=True)
return {host: sorted({host.name, "python", "python{}".format(major), "python{}.{}".format(major, minor)})}


@six.add_metaclass(abc.ABCMeta)
class CPythonWindows(CPython):
@classmethod
def supports(cls, interpreter):
return super(CPythonWindows, cls).supports(interpreter) and interpreter.os == "nt"

class CPythonWindows(CPython, WindowsSupports):
@property
def bin_name(self):
return "Scripts"
Expand All @@ -129,8 +56,6 @@ def lib_name(self):
def lib_base(self):
return Path(self.lib_name)

def exe_names(self):
yield Path(self.interpreter.system_executable).name
for name in ["python", "pythonw"]:
for suffix in ["exe"]:
yield "{}.{}".format(name, suffix)
def link_exe(self):
host = Path(self.interpreter.system_executable)
return {p: [p.name] for p in (host.parent / n for n in ("python.exe", "pythonw.exe", host.name)) if p.exists()}
47 changes: 4 additions & 43 deletions src/virtualenv/interpreters/create/cpython/cpython2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,17 @@

import six

from virtualenv.util.path import Path, copy
from virtualenv.interpreters.create.via_global_ref.python2 import Python2

from .common import CPython, CPythonPosix, CPythonWindows

HERE = Path(__file__).absolute().parent


@six.add_metaclass(abc.ABCMeta)
class CPython2(CPython):
class CPython2(CPython, Python2):
"""Create a CPython version 2 virtual environment"""

def set_pyenv_cfg(self):
"""
We directly inject the base prefix and base exec prefix to avoid site.py needing to discover these
from home (which usually is done within the interpreter itself)
"""
super(CPython2, self).set_pyenv_cfg()
self.pyenv_cfg["base-prefix"] = self.interpreter.system_prefix
self.pyenv_cfg["base-exec-prefix"] = self.interpreter.system_exec_prefix

@classmethod
def supports(cls, interpreter):
return super(CPython2, cls).supports(interpreter) and interpreter.version_info.major == 2

def setup_python(self):
super(CPython2, self).setup_python() # install the core first
self.fixup_python2() # now patch

def add_exe_method(self):
return copy

def fixup_python2(self):
"""Perform operations needed to make the created environment work on Python 2"""
# 1. add landmarks for detecting the python home
self.add_module("os")
# 2. install a patched site-package, the default Python 2 site.py is not smart enough to understand pyvenv.cfg,
# so we inject a small shim that can do this
copy(HERE / "site.py", self.lib_dir / "site.py")

def add_module(self, req):
for ext in self.module_extensions:
file_path = "{}.{}".format(req, ext)
self.copier(self.system_stdlib / file_path, self.lib_dir / file_path)

@property
def module_extensions(self):
return ["py", "pyc"]
def modules(self):
return ["os"] # add landmarks for detecting the python home


class CPython2Posix(CPython2, CPythonPosix):
Expand All @@ -61,9 +25,6 @@ def fixup_python2(self):
# linux needs the lib-dynload, these are builtins on Windows
self.add_folder("lib-dynload")

def add_folder(self, folder):
self.copier(self.system_stdlib / folder, self.lib_dir / folder)


class CPython2Windows(CPython2, CPythonWindows):
"""CPython 2 on Windows"""
7 changes: 3 additions & 4 deletions src/virtualenv/interpreters/create/cpython/cpython3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

import six

from virtualenv.interpreters.create.support import Python3Supports
from virtualenv.util.path import Path, copy

from .common import CPython, CPythonPosix, CPythonWindows


@six.add_metaclass(abc.ABCMeta)
class CPython3(CPython):
@classmethod
def supports(cls, interpreter):
return super(CPython3, cls).supports(interpreter) and interpreter.version_info.major == 3
class CPython3(CPython, Python3Supports):
""""""


class CPython3Posix(CPythonPosix, CPython3):
Expand Down
Loading