def test_package_with_version_specs(self, monkeypatch, specs, link): indexurl = "http://my/simple/" current = Current() current.reconfigure(dict(simpleindex=indexurl)) ri = RemoteIndex(current) def mockget(url): assert url.startswith(indexurl) assert url.endswith("pkg/") return url, """ <a href="http://my/pkg-0.3.tar.gz"/> <a href="http://my/pkg-0.2.8.tar.gz"/> <a href="http://my/pkg-0.2.7.tar.gz"/> <a href="http://my/pkg-0.2.6.tar.gz"/> <a href="http://my/pkg-0.2.5.tar.gz"/> <a href="http://my/pkg-0.2.5a1.tar.gz"/> <a href="http://my/pkg-0.2.4.1.tar.gz"/> <a href="http://my/pkg-0.2.4.tar.gz"/> <a href="http://my/pkg-0.2.3.tar.gz"/> <a href="http://my/pkg-0.2.2.tar.gz"/> <a href="http://my/pkg-0.2.1.tar.gz"/> <a href="http://my/pkg-0.2.0.tar.gz"/> """ monkeypatch.setattr(ri, "getcontent", mockget) lnk = ri.getbestlink(specs) assert URL(lnk.url).url_nofrag == link
def test_receive_error(self, monkeypatch, tmpdir): indexurl = "http://my/simple/" config = Config(tmpdir.join("client")) config.reconfigure(dict(simpleindex=indexurl)) ri = RemoteIndex(config) def mockget(url): raise ri.ReceiveError(404) monkeypatch.setattr(ri, "getcontent", mockget) link = ri.getbestlink("pkg") assert link is None
def test_receive_error(self, monkeypatch, tmpdir): indexurl = "http://my/simple/" current = Current(tmpdir.join("client")) current.reconfigure(dict(simpleindex=indexurl)) ri = RemoteIndex(current) def mockget(url): raise ri.ReceiveError(404) monkeypatch.setattr(ri, "getcontent", mockget) link = ri.getbestlink("pkg") assert link is None
def remoteindex(self): try: return self._remoteindex except AttributeError: from devpi.remoteindex import RemoteIndex self._remoteindex = RemoteIndex(self.current) return self._remoteindex
def test_basic(self, monkeypatch, gen, tmpdir): md5 = gen.md5() indexurl = "http://my/simple/" config = Config(tmpdir.join("client")) config.reconfigure(dict(simpleindex=indexurl)) ri = RemoteIndex(config) def mockget(url): assert url.startswith(indexurl) return """ <a href="../../pkg-1.2.tar.gz#md5=%s"/> <a href="http://something/pkg-1.2dev1.zip"/> <a href="http://something/pkg-1.2dev2.zip"/> """ % md5 monkeypatch.setattr(ri, "getcontent", mockget) link = ri.getbestlink("pkg") assert link.href == "http://my/pkg-1.2.tar.gz"
def test_basic(self, monkeypatch, gen, tmpdir): md5 = gen.md5() indexurl = "http://my/simple/" current = Current(tmpdir.join("client")) current.reconfigure(dict(simpleindex=indexurl)) ri = RemoteIndex(current) def mockget(url): assert url.startswith(indexurl) return url, """ <a href="../../pkg-1.2.tar.gz#md5=%s"/> <a href="http://something/pkg-1.2dev1.zip"/> <a href="http://something/pkg-1.2dev2.zip"/> """ % md5 monkeypatch.setattr(ri, "getcontent", mockget) link = ri.getbestlink("pkg") assert URL(link.url).url_nofrag == "http://my/pkg-1.2.tar.gz"
def __init__(self, hub, rootdir, current): self.rootdir = rootdir self.current = current self.hub = hub self.remoteindex = RemoteIndex(current) self.dir_download = self.rootdir.mkdir("downloads")
class DevIndex: def __init__(self, hub, rootdir, current): self.rootdir = rootdir self.current = current self.hub = hub self.remoteindex = RemoteIndex(current) self.dir_download = self.rootdir.mkdir("downloads") def download_and_unpack(self, link): url = link.url try: (url, content) = self.remoteindex.getcontent(url, bytes=True) except self.remoteindex.ReceiveError: self.hub.fatal("could not receive", url) self.hub.info("received", url) if hasattr(link, "md5"): md5 = hashlib.md5() md5.update(content) digest = md5.hexdigest() assert digest == link.md5, (digest, link.md5) #self.hub.info("verified md5 ok", link.md5) basename = URL(url).basename path_archive = self.dir_download.join(basename) with path_archive.open("wb") as f: f.write(content) pkg = UnpackedPackage(self.hub, self.rootdir, path_archive, link) pkg.unpack() link.pkg = pkg def getbestlink(self, pkgname): #req = pkg_resources.parse_requirements(pkgspec)[0] return self.remoteindex.getbestlink(pkgname) def runtox(self, link): # publishing some infos to the commands started by tox #setenv_devpi(self.hub, env, posturl=self.current.resultlog, # packageurl=link.url, # packagemd5=link.md5) jsonreport = link.pkg.rootdir.join("toxreport.json") path_archive = link.pkg.path_archive toxargs = ["--installpkg", str(path_archive), "-i ALL=%s" % str(self.current.simpleindex), "--result-json", str(jsonreport), ] unpack_path = link.pkg.path_unpacked toxargs.extend(self.get_tox_args(unpack_path=unpack_path)) with link.pkg.path_unpacked.as_cwd(): self.hub.info("%s$ tox %s" %(os.getcwd(), " ".join(toxargs))) try: ret = tox.cmdline(toxargs) except SystemExit as e: ret = e.args[0] if ret != 2: jsondata = json.load(jsonreport.open("r")) url = URL(link.url) post_tox_json_report(self.hub, url.url_nofrag, jsondata) if ret != 0: self.hub.error("tox command failed", ret) return 1 return 0 def get_tox_args(self, unpack_path): hub = self.hub args = self.hub.args toxargs = [] if args.venv is not None: toxargs.append("-e" + args.venv) if args.toxini: ini = hub.get_existing_file(args.toxini) elif unpack_path.join("tox.ini").exists(): ini = hub.get_existing_file(unpack_path.join("tox.ini")) elif args.fallback_ini: ini = hub.get_existing_file(args.fallback_ini) else: hub.fatal("no tox.ini file found in %s" % unpack_path) toxargs.extend(["-c", str(ini)]) if args.toxargs: toxargs.extend(shlex.split(args.toxargs)) return toxargs
def __init__(self, rootdir, config): self.rootdir = rootdir self.config = config self.remoteindex = RemoteIndex(config) self.dir_download = self.rootdir.mkdir("downloads")
class DevIndex: def __init__(self, rootdir, config): self.rootdir = rootdir self.config = config self.remoteindex = RemoteIndex(config) self.dir_download = self.rootdir.mkdir("downloads") def download_and_unpack(self, link): try: content = self.remoteindex.getcontent(link.href) except self.remoteindex.ReceiveError: log.fatal("could not receive", link.href) log.info("received", link.href) if hasattr(link, "md5"): md5 = hashlib.md5() md5.update(content) assert md5.hexdigest() == link.md5 log.info("verified md5 ok", link.md5) path_archive = self.dir_download.join(link.basename) with path_archive.open("wb") as f: f.write(content) pkg = UnpackedPackage(self.rootdir, path_archive, link) pkg.unpack() link.pkg = pkg def getbestlink(self, pkgname): #req = pkg_resources.parse_requirements(pkgspec)[0] return self.remoteindex.getbestlink(pkgname) def runtox(self, link, Popen, venv=None): path_archive = link.pkg.path_archive assert pytestpluginpath.check() # the env var is picked up by pytest-devpi plugin env = os.environ.copy() setenv_devpi(env, posturl=self.config.resultlog, packageurl=link.href, packagemd5=link.md5) # to get pytest to pick up our devpi plugin # XXX in the future we rather want to instruct tox to use # a pytest driver with our plugin enabled and maybe # move reporting and posting of resultlogs to tox env["PYTHONPATH"] = pytestpluginpath.dirname log.debug("setting PYTHONPATH", env["PYTHONPATH"]) env["PYTEST_PLUGINS"] = x = pytestpluginpath.purebasename log.debug("setting PYTEST_PLUGINS", env["PYTEST_PLUGINS"]) for name, val in env.items(): assert isinstance(val, str), (name, val) log.debug("pytestplugin", x) toxargs = ["tox", "--installpkg", str(path_archive), "-i ALL=%s" % self.config.simpleindex, ] if venv is not None: toxargs.append("-e" + venv) log.info("%s$ %s" %(link.pkg.path_unpacked, " ".join(toxargs))) popen = Popen(toxargs, cwd=str(link.pkg.path_unpacked), env=env) popen.communicate() if popen.returncode != 0: log.error("tox command failed", popen.returncode) return 1 return 0
class DevIndex: def __init__(self, hub, rootdir, current): self.rootdir = rootdir self.current = current self.hub = hub self.remoteindex = RemoteIndex(current) self.dir_download = self.rootdir.mkdir("downloads") def download_and_unpack(self, link): try: content = self.remoteindex.getcontent(link.url, bytes=True) except self.remoteindex.ReceiveError: self.hub.fatal("could not receive", link.url) self.hub.info("received", link.url) if hasattr(link, "md5"): md5 = hashlib.md5() md5.update(content) digest = md5.hexdigest() assert digest == link.md5, (digest, link.md5) #self.hub.info("verified md5 ok", link.md5) basename = URL(link.url).basename path_archive = self.dir_download.join(basename) with path_archive.open("wb") as f: f.write(content) pkg = UnpackedPackage(self.hub, self.rootdir, path_archive, link) pkg.unpack() link.pkg = pkg def getbestlink(self, pkgname): #req = pkg_resources.parse_requirements(pkgspec)[0] return self.remoteindex.getbestlink(pkgname) def runtox(self, link): # publishing some infos to the commands started by tox #setenv_devpi(self.hub, env, posturl=self.current.resultlog, # packageurl=link.url, # packagemd5=link.md5) jsonreport = link.pkg.rootdir.join("toxreport.json") path_archive = link.pkg.path_archive toxargs = [ "--installpkg", str(path_archive), "-i ALL=%s" % str(self.current.simpleindex), "--result-json", str(jsonreport), ] unpack_path = link.pkg.path_unpacked toxargs.extend(self.get_tox_args(unpack_path=unpack_path)) with link.pkg.path_unpacked.as_cwd(): self.hub.info("%s$ tox %s" % (os.getcwd(), " ".join(toxargs))) try: ret = tox.cmdline(toxargs) except SystemExit as e: ret = e.args[0] if ret != 2: jsondata = json.load(jsonreport.open("r")) post_tox_json_report(self.hub, self.hub.current.resultlog, jsondata) if ret != 0: self.hub.error("tox command failed", ret) return 1 return 0 def get_tox_args(self, unpack_path): hub = self.hub args = self.hub.args toxargs = [] if args.venv is not None: toxargs.append("-e" + args.venv) if args.toxini: ini = hub.get_existing_file(args.toxini) elif unpack_path.join("tox.ini").exists(): ini = hub.get_existing_file(unpack_path.join("tox.ini")) elif args.fallback_ini: ini = hub.get_existing_file(args.fallback_ini) else: hub.fatal("no tox.ini file found in %s" % unpack_path) toxargs.extend(["-c", str(ini)]) if args.toxargs: toxargs.extend(shlex.split(args.toxargs)) return toxargs