def upload(conan_api): remote, user, password = get_remote(conan_api) conan_api.authenticate(user, password, remote) (_, conanfile) = parse_conanfile('./conanfile.py', ConanPythonRequire(None, None)) conan_api.upload(pattern="{}/{}@arobasmusic/{}".format( conanfile.name, conanfile.version, get_channel()), remote_name=remote)
def setUp(self): settings = Settings() self.profile = Profile() self.profile._settings = settings self.profile._user_options = None self.profile._env_values = None self.profile._dev_reference = None self.profile._package_settings = None self.conanfile_path = os.path.join(temp_folder(), "conanfile.py") output = TestBufferConanOutput() self.loader = ConanFileLoader(None, output, ConanPythonRequire(None, None))
def _build_and_check(self, tmp_dir, file_path, text_file, msg): loader = ConanFileLoader(None, TestBufferConanOutput(), ConanPythonRequire(None, None)) ret = loader.load_consumer(file_path, test_profile()) curdir = os.path.abspath(os.curdir) os.chdir(tmp_dir) try: ret.build() finally: os.chdir(curdir) content = load(text_file) self.assertEqual(content, msg)
def test_requires_init(self): loader = ConanFileLoader(None, Mock(), ConanPythonRequire(None, None)) tmp_dir = temp_folder() conanfile_path = os.path.join(tmp_dir, "conanfile.py") conanfile = """from conans import ConanFile class MyTest(ConanFile): requires = {} def requirements(self): self.requires("MyPkg/0.1@user/channel") """ for requires in ("''", "[]", "()", "None"): save(conanfile_path, conanfile.format(requires)) result = loader.load_consumer(conanfile_path, profile_host=create_profile()) result.requirements() self.assertEqual("MyPkg/0.1@user/channel", str(result.requires))
def _get_app(self): self.remote_manager = MockRemoteManager() cache = self.cache self.resolver = RangeResolver(self.cache, self.remote_manager) proxy = ConanProxy(cache, self.output, self.remote_manager) pyreq_loader = PyRequireLoader(proxy, self.resolver) pyreq_loader.enable_remotes(remotes=Remotes()) self.loader = ConanFileLoader(None, self.output, ConanPythonRequire(None, None), pyreq_loader=pyreq_loader) binaries = GraphBinariesAnalyzer(cache, self.output, self.remote_manager) self.manager = GraphManager(self.output, cache, self.remote_manager, self.loader, proxy, self.resolver, binaries) generator_manager = GeneratorManager() hook_manager = Mock() app_type = namedtuple("ConanApp", "cache out remote_manager hook_manager graph_manager" " binaries_analyzer generator_manager") app = app_type(self.cache, self.output, self.remote_manager, hook_manager, self.manager, binaries, generator_manager) return app
def test_inherit_short_paths(self): loader = ConanFileLoader(None, Mock(), ConanPythonRequire(None, None)) tmp_dir = temp_folder() conanfile_path = os.path.join(tmp_dir, "conanfile.py") conanfile = """from base_recipe import BasePackage class Pkg(BasePackage): pass """ base_recipe = """from conans import ConanFile class BasePackage(ConanFile): short_paths = True """ save(conanfile_path, conanfile) save(os.path.join(tmp_dir, "base_recipe.py"), base_recipe) conan_file = loader.load_basic(conanfile_path) self.assertEqual(conan_file.short_paths, True) result = loader.load_consumer(conanfile_path, profile_host=create_profile()) self.assertEqual(result.short_paths, True)
class ASTReplacementTest(unittest.TestCase): python_requires = ConanPythonRequire(None, None) scm_data = {'type': 'git', 'url': 'this-is-the-url', 'revision': '42'} conanfile = six.u("""{header} from conans import ConanFile class LibConan(ConanFile): name = "Lib" author = "{author}" scm = {{"type": "git", "url": "auto", "revision": "auto"}} {footer} """) def run(self, *args, **kwargs): self._tmp_folder = tempfile.mkdtemp(suffix='_conans') try: super(ASTReplacementTest, self).run(*args, **kwargs) finally: shutil.rmtree(self._tmp_folder, ignore_errors=False, onerror=try_remove_readonly) def _get_conanfile(self, header='', author="jgsogo", encoding="ascii", footer=""): tmp = os.path.join(self._tmp_folder, str(uuid.uuid4())) with codecs.open(tmp, 'w', encoding=encoding) as f: f.write( self.conanfile.format(header=header, author=author, footer=footer)) return tmp def _check_result(self, conanfile): content = load(conanfile) self.assertEqual(content.count(self.scm_data['url']), 1) self.assertEqual(content.count(self.scm_data['revision']), 1) self.assertIn(self.scm_data['url'], content) self.assertIn(self.scm_data['revision'], content) try: # Check it is loadable by Conan machinery _, conanfile = parse_conanfile( conanfile, python_requires=self.python_requires, generator_manager=None) except Exception as e: self.fail("Invalid conanfile: {}".format(e)) else: self.assertEqual(conanfile.scm, self.scm_data) def test_base(self): conanfile = self._get_conanfile() _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) @pytest.mark.skipif( not six.PY3, reason="Works only in Py3 (assumes utf-8 for source files)") def test_author_non_ascii(self): conanfile = self._get_conanfile(author=six.u("¡ÑÁí!"), encoding='utf-8') _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) def test_shebang_utf8(self): header = "#!/usr/bin/env python2\n# -*- coding: utf-8 -*-" conanfile = self._get_conanfile(author=six.u("¡Ñandú!"), header=header, encoding='utf-8') _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) def test_shebang_ascii(self): header = "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-" conanfile = self._get_conanfile(author="jgsogo", header=header, encoding='ascii') _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) def test_shebang_several(self): header = "#!/usr/bin/env python2\n# -*- coding: utf-8 -*-\n# -*- coding: utf-8 -*-" conanfile = self._get_conanfile(author=six.u("¡Ñandú!"), header=header, encoding='utf-8') _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) def test_multiline_statement(self): """ Statement with several lines below the scm attribute """ statement = "\n long_list = 'a', 'b', 'c' \\\n 'd', 'e'" conanfile = self._get_conanfile(footer=statement) _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) # Add comments below the SCM def test_comment_file_level(self): comment = "# This is a comment, file level" conanfile = self._get_conanfile(footer=comment) self.assertIn(comment, load(conanfile)) _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) self.assertIn(comment, load(conanfile)) def test_comment_class_level(self): comment = " # This is a comment, file level" conanfile = self._get_conanfile(footer=comment) self.assertIn(comment, load(conanfile)) _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) self.assertIn(comment, load(conanfile)) def test_two_comments(self): comment = " # line1\n # line2" conanfile = self._get_conanfile(footer=comment) self.assertIn(comment, load(conanfile)) _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) self.assertIn(comment, load(conanfile)) def test_multiline_comment(self): comment = ' """\n line1\n line2\n """' conanfile = self._get_conanfile(footer=comment) self.assertIn(comment, load(conanfile)) _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) # FIXME: We lost the multiline comment # self.assertIn(comment, load(conanfile)) # Something below the comment def test_comment_and_attribute(self): comment = ' # line1\n url=23' conanfile = self._get_conanfile(footer=comment) self.assertIn(comment, load(conanfile)) _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) self.assertIn(comment, load(conanfile)) def test_multiline_comment_and_attribute(self): comment = ' """\n line1\n line2\n """\n url=23' conanfile = self._get_conanfile(footer=comment) self.assertIn(comment, load(conanfile)) _replace_scm_data_in_conanfile(conanfile, self.scm_data) self._check_result(conanfile) # FIXME: We lost the multiline comment self.assertIn(" url=23", load(conanfile))