def test_scm_serialization(self): data = {"url": "myurl", "revision": "23", "username": "******", "password": "******", "type": "svn", "verify_ssl": True, "subfolder": "mysubfolder"} conanfile = namedtuple("ConanfileMock", "scm")(data) scm_data = SCMData(conanfile) the_json = str(scm_data) data2 = json.loads(the_json) self.assertEqual(data, data2)
def test_scmdata_string(self): fake_class = namedtuple("Conanfile", ["scm"]) conanfile = fake_class(scm=self.data) self.assertEqual( str(SCMData(conanfile)), '{"password": "******", "revision": "123",' ' "shallow": False, "type": "weir\\"d",' ' "url": "http://my.url", "username": "******"d"}')
def scm_serialization_test(self): data = {"url": "myurl", "revision": "myrevision", "username": "******", "password": "******", "type": "git", "verify_ssl": True, "subfolder": "mysubfolder"} conanfile = namedtuple("ConanfileMock", "scm")(data) scm_data = SCMData(conanfile) expected_output = '{"password": "******", "revision": "myrevision",' \ ' "subfolder": "mysubfolder", "type": "git", "url": "myurl",' \ ' "username": "******"}' self.assertEqual(str(scm_data), expected_output)
def _do_actual_test(self, scm_data, after_scm, after_recipe): target_conanfile = self.conanfile.format(url=scm_data['url'], revision=scm_data['revision'], after_scm=after_scm, after_recipe=after_recipe) save(self.conanfile_path, content=self.conanfile.format(url='auto', revision='auto', after_scm=after_scm, after_recipe=after_recipe)) scm_data = SCMData(conanfile=namedtuple('_', 'scm')(scm=scm_data)) _replace_scm_data_in_conanfile(self.conanfile_path, scm_data) self.assertEqual(load(self.conanfile_path), target_conanfile) _parse_conanfile(conan_file_path=self.conanfile_path) # Check that the resulting file is valid python code.
def _capture_export_scm_data(conanfile, src_path, destination_folder, output, paths, conan_ref): scm_src_file = paths.scm_folder(conan_ref) if os.path.exists(scm_src_file): os.unlink(scm_src_file) try: scm_data = SCMData(conanfile) except ConanException: return else: if not (scm_data.capture_origin or scm_data.capture_revision): return scm = SCM(scm_data, src_path) if scm_data.url == "auto": origin = scm.get_remote_url() if not origin: raise ConanException("Repo origin cannot be deduced by 'auto'") if os.path.exists(origin): output.warn("Repo origin looks like a local path: %s" % origin) origin = origin.replace("\\", "/") output.success("Repo origin deduced by 'auto': %s" % origin) scm_data.url = origin if scm_data.revision == "auto": scm_data.revision = scm.get_revision() output.success("Revision deduced by 'auto': %s" % scm_data.revision) # Generate the scm_folder.txt file pointing to the src_path save(scm_src_file, src_path.replace("\\", "/")) scm_data.replace_in_file(os.path.join(destination_folder, "conanfile.py"))
def config_source_local(dest_dir, conanfile, conanfile_folder, output): output.info('Configuring sources in %s' % dest_dir) conanfile.source_folder = dest_dir with tools.chdir(dest_dir): try: with conanfile_exception_formatter(str(conanfile), "source"): with get_env_context_manager(conanfile): conanfile.build_folder = None conanfile.package_folder = None try: scm_data = SCMData(conanfile) except ConanException: pass else: dest_dir = os.path.join(dest_dir, scm_data.subfolder) capture = scm_data.capture_origin or scm_data.capture_revision local_sources_path = conanfile_folder if capture else None _fetch_scm(scm_data, dest_dir, local_sources_path, output) conanfile.source() except ConanExceptionInUserConanfileMethod: raise except Exception as e: raise ConanException(e)
def get_scm_data(conanfile): try: return SCMData(conanfile) except ConanException: return None
def config_source(export_folder, export_source_folder, local_sources_path, src_folder, conanfile, output, force=False): """ creates src folder and retrieve, calling source() from conanfile the necessary source code """ def remove_source(raise_error=True): output.warn("This can take a while for big packages") try: rmdir(src_folder) except BaseException as e_rm: set_dirty(src_folder) msg = str(e_rm) if six.PY2: msg = str(e_rm).decode("latin1") # Windows prints some chars in latin1 output.error("Unable to remove source folder %s\n%s" % (src_folder, msg)) output.warn("**** Please delete it manually ****") if raise_error or isinstance(e_rm, KeyboardInterrupt): raise ConanException("Unable to remove source folder") if force: output.warn("Forced removal of source folder") remove_source() elif is_dirty(src_folder): output.warn("Trying to remove corrupted source folder") remove_source() elif conanfile.build_policy_always: output.warn("Detected build_policy 'always', trying to remove source folder") remove_source() if not os.path.exists(src_folder): output.info('Configuring sources in %s' % src_folder) set_dirty(src_folder) mkdir(src_folder) os.chdir(src_folder) conanfile.source_folder = src_folder try: with conanfile_exception_formatter(str(conanfile), "source"): with get_env_context_manager(conanfile): conanfile.build_folder = None conanfile.package_folder = None try: scm_data = SCMData(conanfile) except ConanException: pass else: dest_dir = os.path.normpath(os.path.join(src_folder, scm_data.subfolder)) captured = local_sources_path and os.path.exists(local_sources_path) local_sources_path = local_sources_path if captured else None _fetch_scm(scm_data, dest_dir, local_sources_path, output) merge_directories(export_folder, src_folder) # Now move the export-sources to the right location merge_directories(export_source_folder, src_folder) _clean_source_folder(src_folder) try: shutil.rmtree(os.path.join(src_folder, "__pycache__")) except OSError: pass conanfile.source() clean_dirty(src_folder) # Everything went well, remove DIRTY flag except Exception as e: os.chdir(export_folder) # in case source() fails (user error, typically), remove the src_folder # and raise to interrupt any other processes (build, package) output.warn("Trying to remove corrupted source folder") remove_source(raise_error=False) if isinstance(e, ConanExceptionInUserConanfileMethod): raise e raise ConanException(e)