From 03ae5c6094e035e7d60b1b0530d284a823a9a2ed Mon Sep 17 00:00:00 2001 From: memsharded Date: Mon, 15 Apr 2019 14:58:40 +0200 Subject: [PATCH] fixing local flow with python requires --- conans/client/conan_api.py | 10 +++++++ .../python_requires/python_requires_test.py | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/conans/client/conan_api.py b/conans/client/conan_api.py index 42dac7ce871..0cd55c90476 100644 --- a/conans/client/conan_api.py +++ b/conans/client/conan_api.py @@ -400,6 +400,8 @@ def export_pkg(self, conanfile_path, name, channel, source_folder=None, build_fo package_folder=None, install_folder=None, profile_names=None, settings=None, options=None, env=None, force=False, user=None, version=None, cwd=None): + remotes = self._cache.registry.load_remotes() + self.python_requires.enable_remotes(remotes=remotes) settings = settings or [] options = options or [] env = env or [] @@ -675,6 +677,8 @@ def build(self, conanfile_path, source_folder=None, package_folder=None, build_f install_folder=None, should_configure=True, should_build=True, should_install=True, should_test=True, cwd=None): + remotes = self._cache.registry.load_remotes() + self.python_requires.enable_remotes(remotes=remotes) cwd = cwd or get_cwd() conanfile_path = _get_conanfile_path(conanfile_path, cwd, py=True) build_folder = _make_abs_path(build_folder, cwd) @@ -691,6 +695,9 @@ def build(self, conanfile_path, source_folder=None, package_folder=None, build_f @api_method def package(self, path, build_folder, package_folder, source_folder=None, install_folder=None, cwd=None): + remotes = self._cache.registry.load_remotes() + self.python_requires.enable_remotes(remotes=remotes) + cwd = cwd or get_cwd() conanfile_path = _get_conanfile_path(path, cwd, py=True) build_folder = _make_abs_path(build_folder, cwd) @@ -711,6 +718,9 @@ def package(self, path, build_folder, package_folder, source_folder=None, instal @api_method def source(self, path, source_folder=None, info_folder=None, cwd=None): + remotes = self._cache.registry.load_remotes() + self.python_requires.enable_remotes(remotes=remotes) + cwd = cwd or get_cwd() conanfile_path = _get_conanfile_path(path, cwd, py=True) source_folder = _make_abs_path(source_folder, cwd) diff --git a/conans/test/functional/python_requires/python_requires_test.py b/conans/test/functional/python_requires/python_requires_test.py index 5ff88b0d0d8..ade31040dbe 100644 --- a/conans/test/functional/python_requires/python_requires_test.py +++ b/conans/test/functional/python_requires/python_requires_test.py @@ -8,6 +8,7 @@ from conans.paths import CONANFILE from conans.test.utils.tools import TestClient, TestServer, \ NO_SETTINGS_PACKAGE_ID, create_local_git_repo +from conans.test.utils.conanfile import TestConanFile class PythonExtendTest(unittest.TestCase): @@ -605,3 +606,28 @@ def build(self): # - no mention to alias self.assertNotIn("alias", client.out) self.assertNotIn("alias2", client.out) + + def local_build_test(self): + client = TestClient() + client.save({"conanfile.py": "var=42\n"+str(TestConanFile("Tool", "0.1"))}) + client.run("export . Tool/0.1@user/channel") + + conanfile = """from conans import ConanFile, python_requires +pkg1 = python_requires("Tool/0.1@user/channel") +class MyConanfileBase(ConanFile): + def source(self): + self.output.info("Pkg1 source: %s" % pkg1.var) + def build(self): + self.output.info("Pkg1 build: %s" % pkg1.var) + def package(self): + self.output.info("Pkg1 package: %s" % pkg1.var) +""" + client.save({"conanfile.py": conanfile}) + client.run("source .") + self.assertIn("conanfile.py: Pkg1 source: 42", client.out) + client.run("install .") + client.run("build .") + self.assertIn("conanfile.py: Pkg1 build: 42", client.out) + client.run("package .") + self.assertIn("conanfile.py: Pkg1 package: 42", client.out) + client.run("export-pkg . pkg1/0.1@user/testing")