def test_make_distribution(self): # check if tar and gzip are installed if find_executable("tar") is None or find_executable("gzip") is None: return # now building a sdist dist, cmd = self.get_cmd() # creating a gztar then a tar cmd.formats = ["gztar", "tar"] cmd.ensure_finalized() cmd.run() # making sure we have two files dist_folder = join(self.tmp_dir, "dist") result = os.listdir(dist_folder) result.sort() self.assertEquals(result, ["fake-1.0.tar", "fake-1.0.tar.gz"]) os.remove(join(dist_folder, "fake-1.0.tar")) os.remove(join(dist_folder, "fake-1.0.tar.gz")) # now trying a tar then a gztar cmd.formats = ["tar", "gztar"] cmd.ensure_finalized() cmd.run() result = os.listdir(dist_folder) result.sort() self.assertEquals(result, ["fake-1.0.tar", "fake-1.0.tar.gz"])
def test_run(self): # can't test on windows if sys.platform == 'win32': return pkg_dir, dist = self.create_dist() cmd = build_clib(dist) foo_c = os.path.join(pkg_dir, 'foo.c') self.write_file(foo_c, 'int main(void) { return 1;}\n') cmd.libraries = [('foo', {'sources': [foo_c]})] build_temp = os.path.join(pkg_dir, 'build') os.mkdir(build_temp) cmd.build_temp = build_temp cmd.build_clib = build_temp # before we run the command, we want to make sure # all commands are present on the system # by creating a compiler and checking its executables from distutils2.compiler.ccompiler import new_compiler, customize_compiler compiler = new_compiler() customize_compiler(compiler) for ccmd in compiler.executables.values(): if ccmd is None: continue if find_executable(ccmd[0]) is None: return # can't test # this should work cmd.run() # let's check the result self.assertTrue('libfoo.a' in os.listdir(build_temp))
def _find_exe_version(cmd, pattern=_RE_VERSION): """Find the version of an executable by running `cmd` in the shell. `pattern` is a compiled regular expression. If not provided, default to _RE_VERSION. If the command is not found, or the output does not match the mattern, returns None. """ from subprocess import Popen, PIPE executable = cmd.split()[0] if find_executable(executable) is None: return None pipe = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) try: stdout, stderr = pipe.stdout.read(), pipe.stderr.read() finally: pipe.stdout.close() pipe.stderr.close() # some commands like ld under MacOS X, will give the # output in the stderr, rather than stdout. if stdout != '': out_string = stdout else: out_string = stderr result = pattern.search(out_string) if result is None: return None return result.group(1)
def test_make_distribution_owner_group(self): # check if tar and gzip are installed if find_executable("tar") is None or find_executable("gzip") is None: return # now building a sdist dist, cmd = self.get_cmd() # creating a gztar and specifying the owner+group cmd.formats = ["gztar"] cmd.owner = pwd.getpwuid(0)[0] cmd.group = grp.getgrgid(0)[0] cmd.ensure_finalized() cmd.run() # making sure we have the good rights archive_name = join(self.tmp_dir, "dist", "fake-1.0.tar.gz") archive = tarfile.open(archive_name) try: for member in archive.getmembers(): self.assertEquals(member.uid, 0) self.assertEquals(member.gid, 0) finally: archive.close() # building a sdist again dist, cmd = self.get_cmd() # creating a gztar cmd.formats = ["gztar"] cmd.ensure_finalized() cmd.run() # making sure we have the good rights archive_name = join(self.tmp_dir, "dist", "fake-1.0.tar.gz") archive = tarfile.open(archive_name) # note that we are not testing the group ownership here # because, depending on the platforms and the container # rights (see #7408) try: for member in archive.getmembers(): self.assertEquals(member.uid, os.getuid()) finally: archive.close()