def key(self): """ Returns the key to use in the ledger. If this object has a 'base_path' attribute, the key is the path relative to this base path. Otherwise it is the absolute pathname to the file. """ if self.key_file is None: if self.base_path: self.key_file = relpath(self.file, self.base_path) else: self.key_file = self.file return self.key_file
def make_release_tree (self, base_dir, files): # Taken from 2.7 version -- but also removes source_dir from dests """Create the directory tree that will become the source distribution archive. All directories implied by the filenames in 'files' are created under 'base_dir', and then we hard link or copy (if hard linking is unavailable) those files into place. Essentially, this duplicates the developer's source tree, but in a directory named after the distribution, containing only the files to be distributed. """ self.run_command('gen_version') source_dir = self.distribution.source_dir # Create all the directories under 'base_dir' necessary to # put 'files' there; the 'mkpath()' is just so we don't die # if the manifest happens to be empty. self.mkpath(base_dir) dir_util.create_tree(base_dir, [relpath(f, source_dir) for f in files], dry_run=self.dry_run) # And walk over the list of files, either making a hard link (if # os.link exists) to each one that doesn't already exist in its # corresponding location under 'base_dir', or copying each file # that's out-of-date in 'base_dir'. (Usually, all files will be # out-of-date, because by default we blow away 'base_dir' when # we're done making the distribution archives.) link = None msg = "copying files to %s..." % base_dir if not files: log.warn("no files to distribute -- empty manifest?") else: log.info(msg) for file in files: if not os.path.isfile(file): log.warn("'%s' not a regular file -- skipping" % file) else: dest = destpath(file, [source_dir]) dest = os.path.join(base_dir, dest) self.copy_file(file, dest, link=link) self.distribution.metadata.write_pkg_info(base_dir)
def destpath(filename, paths): for p in paths: if filename.startswith(p): return relpath(filename, p) return filename
def get_package_dir(self): build_py = self.get_finalized_command("build_py") return relpath(build_py.get_package_dir(""), self.distribution.source_dir)
def test_relpath_7(self): rp = relpath("/foo/bar/", "/foo/baz/") self.assertEqual(rp, "../bar")
def test_relpath_6(self): rp = relpath("/foo/bar/baz", "/foo/bar/baz") self.assertEqual(rp, ".")
def test_relpath_5(self): rp = relpath("/", "/") self.assertEqual(rp, ".")
def test_relpath_4(self): rp = relpath("/etc/foobar", "/") self.assertEqual(rp, "etc/foobar")
def test_relpath_3(self): rp = relpath("foo/bar/baz", "/asd/brf") self.assertEqual(rp, "foo/bar/baz")
def test_relpath_2(self): rp = relpath("/asd/brf/cqe/tol", "/asd/brf") self.assertEqual(rp, "cqe/tol")
def test_relpath_1(self): rp = relpath("/asd/brf/cqe", "/asd/qzc/rvg/tol") self.assertEqual(rp, "../../../brf/cqe")