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

[conan_v2_mode] Deprecate old ways of reusing python code #6737

Merged
merged 7 commits into from Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions conans/client/conan_api.py
Expand Up @@ -60,6 +60,8 @@
from conans.search.search import search_recipes
from conans.tools import set_global_instances
from conans.unicode import get_cwd
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
from conans.util.env_reader import get_env
from conans.util.files import exception_message_safe, mkdir, save_files
from conans.util.log import configure_logger
from conans.util.tracer import log_command, log_exception
Expand Down Expand Up @@ -220,8 +222,9 @@ def __init__(self, cache_folder=None, output=None, user_io=None, http_requester=
# Migration system
migrator = ClientMigrator(self.cache_folder, Version(client_version), self.out)
migrator.migrate()
# FIXME Remove in Conan 2.0
sys.path.append(os.path.join(self.cache_folder, "python"))
if not get_env(CONAN_V2_MODE_ENVVAR, False):
# FIXME Remove in Conan 2.0
sys.path.append(os.path.join(self.cache_folder, "python"))
memsharded marked this conversation as resolved.
Show resolved Hide resolved

def create_app(self, quiet_output=None):
self.app = ConanApp(self.cache_folder, self.user_io, self.http_requester,
Expand Down
2 changes: 2 additions & 0 deletions conans/client/generators/virtualenv_python.py
@@ -1,4 +1,5 @@
from conans.client.generators.virtualrunenv import VirtualRunEnvGenerator
from conans.util.conan_v2_mode import conan_v2_behavior
jgsogo marked this conversation as resolved.
Show resolved Hide resolved


class VirtualEnvPythonGenerator(VirtualRunEnvGenerator):
Expand All @@ -7,6 +8,7 @@ class VirtualEnvPythonGenerator(VirtualRunEnvGenerator):
venv_name = "conanenvpython"

def __init__(self, conanfile):
conan_v2_behavior("'virtualenv_python' generator is deprecated")
jgsogo marked this conversation as resolved.
Show resolved Hide resolved
super(VirtualEnvPythonGenerator, self).__init__(conanfile)
ppath = conanfile.env.get("PYTHONPATH")
if ppath:
Expand Down
5 changes: 4 additions & 1 deletion conans/client/installer.py
Expand Up @@ -14,6 +14,7 @@
from conans.client.recorder.action_recorder import INSTALL_ERROR_BUILDING, INSTALL_ERROR_MISSING, \
INSTALL_ERROR_MISSING_BUILD_FOLDER
from conans.client.source import complete_recipe_sources, config_source
from conans.client.tools.env import no_op
from conans.client.tools.env import pythonpath
from conans.errors import (ConanException, ConanExceptionInUserConanfileMethod,
conanfile_exception_formatter)
Expand All @@ -26,6 +27,7 @@
from conans.model.ref import PackageReference
from conans.model.user_info import UserInfo
from conans.paths import BUILD_INFO, CONANINFO, RUN_LOG_NAME
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
from conans.util.env_reader import get_env
from conans.util.files import (clean_dirty, is_dirty, make_read_only, mkdir, rmdir, save, set_dirty,
set_dirty_context_manager)
Expand Down Expand Up @@ -547,7 +549,8 @@ def _call_package_info(self, conanfile, package_folder, ref):
conanfile.cpp_info.public_deps = public_deps
# Once the node is build, execute package info, so it has access to the
# package folder and artifacts
with pythonpath(conanfile): # Minimal pythonpath, not the whole context, make it 50% slower
conan_v2 = get_env(CONAN_V2_MODE_ENVVAR, False)
memsharded marked this conversation as resolved.
Show resolved Hide resolved
with pythonpath(conanfile) if not conan_v2 else no_op(): # Minimal pythonpath, not the whole context, make it 50% slower
with tools.chdir(package_folder):
with conanfile_exception_formatter(str(conanfile), "package_info"):
conanfile.package_folder = package_folder
Expand Down
1 change: 0 additions & 1 deletion conans/client/profile_loader.py
Expand Up @@ -140,7 +140,6 @@ def _load_profile(text, profile_path, default_folder):
# Apply the automatic PROFILE_DIR variable
if cwd:
profile_parser.vars["PROFILE_DIR"] = os.path.abspath(cwd).replace('\\', '/')
# Allows PYTHONPATH=$PROFILE_DIR/pythontools

# Replace the variables from parents in the current profile
profile_parser.apply_vars()
Expand Down
7 changes: 6 additions & 1 deletion conans/model/conan_file.py
Expand Up @@ -14,7 +14,9 @@
from conans.model.requires import Requirements
from conans.model.user_info import DepsUserInfo
from conans.paths import RUN_LOG_NAME
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
from conans.util.conan_v2_mode import conan_v2_behavior
from conans.util.env_reader import get_env


def create_options(conanfile):
Expand Down Expand Up @@ -72,8 +74,11 @@ def create_settings(conanfile, settings):
@contextmanager
def _env_and_python(conanfile):
with environment_append(conanfile.env):
with pythonpath(conanfile):
if get_env(CONAN_V2_MODE_ENVVAR, False):
yield
else:
with pythonpath(conanfile):
yield


def get_env_context_manager(conanfile, without_python=False):
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions conans/test/conan_v2/generators/test_virtualenv_python.py
@@ -0,0 +1,12 @@
from conans.test.utils.conan_v2_tests import ConanV2ModeTestCase


class VirtualenvPythonTestCase(ConanV2ModeTestCase):

def test_deprecate_virtualenv_python(self):
t = self.get_client()
t.run("new name/version@user/channel -b")
t.run("create . name/version@user/channel")
t.run("install name/version@user/channel -g virtualenv_python", assert_error=True)
self.assertIn("ERROR: Conan v2 incompatible: 'virtualenv_python' generator is deprecated",
t.out)
61 changes: 61 additions & 0 deletions conans/test/conan_v2/test_pythonpath.py
@@ -0,0 +1,61 @@
import textwrap

from conans.model.ref import ConanFileReference
from conans.test.utils.conan_v2_tests import ConanV2ModeTestCase
import six

class PythonBuildTest(ConanV2ModeTestCase):
conanfile = textwrap.dedent("""
from conans import ConanFile

class ConanToolPackage(ConanFile):
name = "conantool"
version = "1.0"
exports = "*"
build_policy = "missing"

def package(self):
self.copy("*")

def package_info(self):
self.env_info.PYTHONPATH.append(self.package_folder)
""")

tooling = textwrap.dedent("""
def bar(output):
output.info("Hello Bar")
""")

reuse = textwrap.dedent("""
from conans import ConanFile, tools

class ToolsTest(ConanFile):
name = "consumer"
version = "0.1"
requires = "conantool/1.0@conan/stable"

def build(self):
self.output.info("PYTHONPATH: {}".format(self.deps_env_info["conantool"].PYTHONPATH))

def package_info(self):
import tooling
tooling.bar(self.output)
""")

def test_deprecate_pythonpath(self):
conantool_ref = ConanFileReference.loads("conantool/1.0@conan/stable")
# Create a package that exports python code
t = self.get_client()
t.save({'conanfile.py': self.conanfile,
'tooling.py': self.tooling})
t.run("export . conan/stable")

# Try to reuse it
t.save({'conanfile.py': self.reuse}, clean_first=True)
t.run("create .", assert_error=True)
packages_path = t.cache.package_layout(conantool_ref).packages()
self.assertIn("consumer/0.1: PYTHONPATH: ['{}".format(packages_path), t.out)
if six.PY2:
self.assertIn("ImportError: No module named tooling", t.out)
else:
self.assertIn("ModuleNotFoundError: No module named 'tooling'", t.out)