Create new :py:class:`Writer` from path

        :param path: the path to load from (converted to ``str`` for
            compatibility with ``path.py``)
        :param header: VCF header to use, lines and samples are deep-copied
176536
def from_path(klass, path, header):
        
        path = str(path)
        use_bgzf = False  # we already interpret path
        if path.endswith(".gz"):
            f = bgzf.BgzfWriter(filename=path)
        else:
            f = open(path, "wt")
        return klass.from_stream(f, header, path, use_bgzf=use_bgzf)
1078273
def from_path(cls, path: pathlib.Path) -> 'Entity':
        
        if path.is_file():
            return File.from_path(path)
        return Directory.from_path(path)
1004957
def _append_path(new_path):  # type: (str) -> None
    
    for path in sys.path:
        path = os.path.abspath(path)
        if new_path == path:
            return
    sys.path.append(new_path)
355167
def path(path_name=None, override=None, *, root=None, name=None, ext=None,
         inject=None, relpath=None, reduce=False):
    
    path_name, identity, root = _initialize(path_name, override, root, inject)
    new_name = _process_name(path_name, identity, name, ext)
    new_directory = _process_directory(path_name, identity, root, inject)
    full_path = os.path.normpath(os.path.join(new_directory, new_name))
    if APPEND_SEP_TO_DIRS and not new_name and full_path[-1] != os.sep:
        full_path += os.sep
    final_path = _format_path(full_path, root, relpath, reduce)
    return final_path
597751
def create_init(self, path):  # type: (str) -> None
        
        source = """# coding=utf-8
\"\"\"
Version
\"\"\"
__version__ = \"0.0.0\"
"""
        with io.open(path, "w", encoding="utf-8") as outfile:
            outfile.write(source)
1120379
def from_file(cls, path, **kwargs):
		
		LOG.debug('creating %s from "%s"', cls, path)

		# the filename will be the default slug - can be overridden later
		kwargs['slug'] = os.path.splitext(os.path.basename(path))[0]

		# TODO: ideally this should be part of the Post class.
		# if a pubdate isn't explicitly passed, get it from the file metadata
		# instead. note that it might still be overriden later on while reading
		# the file contents.
		if issubclass(cls, Post) and not kwargs.get('pubdate'):
			# you would think creation always comes before modification, but you
			# can manually modify a file's modification date to one earlier than
			# the creation date. this lets you set a post's pubdate by running
			# the command `touch`. we support this behaviour by simply finding
			# the chronologically earliest date of creation and modification.
			timestamp = min(os.path.getctime(path), os.path.getmtime(path))
			kwargs['pubdate'] = datetime.fromtimestamp(timestamp)

		with open(path, 'r') as file:
			entry = cls.from_string(file.read(), **kwargs)

		return entry
1036104
def write(self, path):
        '''

        '''
        with open(path, 'wb') as oligo_file:
            oligo_writer = csv.writer(oligo_file, delimiter=',',
                                      quoting=csv.QUOTE_MINIMAL)
            oligo_writer.writerow(['name', 'oligo', 'notes'])
            for i, oligo in enumerate(self.oligos):
                name = 'oligo {}'.format(i + 1)
                oligo_len = len(oligo)
                if i != len(self.oligos) - 1:
                    oligo_tm = self.overlap_tms[i]
                    notes = 'oligo length: {}, '.format(oligo_len) + \
                            'overlap Tm: {:.2f}'.format(oligo_tm)
                else:
                    notes = 'oligo length: {}'.format(oligo_len)
                oligo_writer.writerow([name, oligo, notes])
            if self.primers:
                for i, (primer, melt) in enumerate(self.primers):
                    oligo_writer.writerow(['primer {}'.format(i + 1),
                                           primer,
                                           'Tm: {:.2f}'.format(melt)])
933356
def from_path(cls, path):
        
        name = path.name[:-3]
        with logs.debug_time(u'Importing rule: {};'.format(name)):
            rule_module = load_source(name, str(path))
            priority = getattr(rule_module, 'priority', DEFAULT_PRIORITY)
        return cls(name, rule_module.match,
                   rule_module.get_new_command,
                   getattr(rule_module, 'enabled_by_default', True),
                   getattr(rule_module, 'side_effect', None),
                   settings.priority.get(name, priority),
                   getattr(rule_module, 'requires_output', True))
1027483
def import_from_path(path):
    
    module_name, class_name = path.rsplit('.', 1)
    try:
        return getattr(__import__(module_name, fromlist=[class_name]), class_name)
    except AttributeError:
        raise ImportError('Unable to import %s' % path)
146519
def create(self, path: str, k: int = 20):
        
        self.lex = np.zeros((len(self.vocab_source), k), dtype=np.int)
        src_unk_id = self.vocab_source[C.UNK_SYMBOL]
        trg_unk_id = self.vocab_target[C.UNK_SYMBOL]
        num_insufficient = 0  # number of source tokens with insufficient number of translations given k
        for src_id, group in groupby(lexicon_iterator(path, self.vocab_source, self.vocab_target), key=itemgetter(0)):
            # Unk token will always be part of target vocab, so no need to track it here
            if src_id == src_unk_id:
                continue

            # filter trg_unk_id
            filtered_group = ((trg_id, prob) for src_id, trg_id, prob in group if trg_id != trg_unk_id)
            # sort by prob and take top k
            top_k = [trg_id for trg_id, prob in sorted(filtered_group, key=itemgetter(1), reverse=True)[:k]]
            if len(top_k) < k:
                num_insufficient += 1

            self.lex[src_id, :len(top_k)] = top_k

        logger.info("Created top-k lexicon from \"%s\", k=%d. %d source tokens with fewer than %d translations",
                    path, k, num_insufficient, k)
1349756
def write_http_request(self, path: str, headers: Headers) -> None:
        
        self.path = path
        self.request_headers = headers

        logger.debug("%s > GET %s HTTP/1.1", self.side, path)
        logger.debug("%s > %r", self.side, headers)

        # Since the path and headers only contain ASCII characters,
        # we can keep this simple.
        request = f"GET {path} HTTP/1.1\r\n"
        request += str(headers)

        self.writer.write(request.encode())
1247143
def copy_path(self, path):
        
        src = os.path.expandvars(os.path.expanduser(path))
        basename = os.path.basename(src)
        dest_path = os.path.expandvars(os.path.expanduser(
            os.path.join(self.curr_work_path, basename)))
        if os.path.isdir(dest_path):
            shutil.rmtree(dest_path)
        if os.path.isdir(src):
            try:
                shutil.copytree(src, dest_path)
            except shutil.Error:
                pass  # There are permissions errors to copy
        elif os.path.isfile(src):
            shutil.copy(src, dest_path)
        else:
            raise UserWarning(
                "Just directory or file is supported to copy [%s]" % src)
        return os.path.relpath(dest_path, self.curr_work_path)
730443
def create(self, path, mode):  # pragma: no cover
        
        # print("create {}".format(path))
        now_time = time()
        with self.attr_lock:
            base = NoStat()
            base.staged = True
            base.st_mode = stat.S_IFREG | OBJ_PERMISSION
            base.st_nlink = 1
            base.st_size = -1
            self.attr[path] = {TIMESTAMP_KEY: now_time,
                               BASE_KEY: base,
                               STAGED_KEY: BytesIO()}
        return mode
1170447
def load_config(self, path):
        
        self.config_path = path
        self.config.read(self.config_path)
1373448
def load_py(stream, filepath=None):
    
    with add_sys_paths(config.package_definition_build_python_paths):
        return _load_py(stream, filepath=filepath)
977345
def load_path(self, path):
        '''
        
        '''
        containing_module, _, last_item = path.rpartition('.')
        if last_item[0].isupper():
            # Is a class definition, should do an "import from"
            path = containing_module
        imported_obj = importlib.import_module(path)
        if last_item[0].isupper():
            try:
                imported_obj = getattr(imported_obj, last_item)
            except AttributeError:
                msg = 'Cannot import "%s". ' \
                    '(Hint: CamelCase is only for classes)' % last_item
                raise ConfigurationError(msg)
        return imported_obj
793866
def with_path(self, path):
        
        new_command = copy.deepcopy(self)
        new_command._paths.append(str(path))
        return new_command