Creates rst files in the _include directory using the python scripts
    there.

    This will ignore any files in the _include directory that start with ``_``.
512318
def build_includes():
    
    print("Running scripts in _include:")
    cwd = os.getcwd()
    os.chdir('_include')
    pyfiles = glob.glob('*.py')
    for fn in pyfiles:
        if not fn.startswith('_'):
            print(' {}'.format(fn))
            subprocess.check_output(['python', fn])
    os.chdir(cwd)
517197
def setup_sanitize_files(self):
        
        for fname in self.get_sanitize_files():
            with open(fname, 'r') as f:
                self.sanitize_patterns.update(get_sanitize_patterns(f.read()))
300745
def expand_include(filename):
        
        open_files = set()

        def _expand_include_rec(filename):
            if filename in open_files:
                raise RuntimeError('Recursive include statement detected for '
                                   'file: ' + filename)
            else:
                open_files.add(filename)

            with open(filename) as open_file:
                for line in open_file:
                    line_stripped = line.strip().replace("//", "#")
                    if line_stripped.startswith('@include '):
                        inc_to_clean = line_stripped.split(None, 1)[1]
                        inc_filename = inc_to_clean.replace('"'," ").strip()
                        for included_line in _expand_include_rec(inc_filename):
                            yield included_line
                    else:
                        yield line

            open_files.remove(filename)

        try:
            lines = []
            for line in _expand_include_rec(filename):
                lines.append(line)
            return ''.join(lines)
        except RuntimeError:
            return None
543227
def include_template(*files)
      include_base = options[:include_base] || File.dirname(caller.first.split(/:\d/,2).first)
      files.each do |file|
        path = File.join(include_base, file)
        include_file(path)
      end
    end
118595
def create_tar_archive(self):
        
        #file filter
        EXCLUDE_FILES = glob.glob(os.path.join(self.savefolder, 'cells'))
        EXCLUDE_FILES += glob.glob(os.path.join(self.savefolder,
                                                'populations', 'subsamples'))
        EXCLUDE_FILES += glob.glob(os.path.join(self.savefolder,
                                                'raw_nest_output'))

        def filter_function(tarinfo):
            print(tarinfo.name)
            if len([f for f in EXCLUDE_FILES if os.path.split(tarinfo.name)[-1]
                    in os.path.split(f)[-1]]) > 0 or \
               len([f for f in EXCLUDE_FILES if os.path.split(tarinfo.path)[-1]
                    in os.path.split(f)[-1]]) > 0:
                print('excluding %s' % tarinfo.name)

                return None
            else:
                return tarinfo

        if RANK == 0:
            print('creating archive %s' % (self.savefolder + '.tar'))
            #open file
            f = tarfile.open(self.savefolder + '.tar', 'w')
            #avoid adding files to repo as /scratch/$USER/hybrid_model/...
            arcname = os.path.split(self.savefolder)[-1]

            f.add(name=self.savefolder,
                  arcname=arcname,
                  filter=filter_function)
            f.close()

        #resync
        COMM.Barrier()
1012964
def create(self, ignore=None):
        """"""
        ignore = ignore or []

        def _create(tree_or_filename, alias=None):
            """Create indices and aliases by walking DFS."""
            # Iterate over aliases:
            for name, value in tree_or_filename.items():
                if isinstance(value, dict):
                    for result in _create(value, alias=name):
                        yield result
                else:
                    with open(value, 'r') as body:
                        yield name, self.client.indices.create(
                            index=name,
                            body=json.load(body),
                            ignore=ignore,
                        )

            if alias:
                yield alias, self.client.indices.put_alias(
                    index=list(_get_indices(tree_or_filename)),
                    name=alias,
                    ignore=ignore,
                )

        for result in _create(self.active_aliases):
            yield result
1164071
def _check_and_handle_includes(self, from_file):
        
        logger.debug("Check/handle includes from %s", from_file)
        try:
            paths = self._parser.get("INCLUDE", "paths")
        except (config_parser.NoSectionError,
                config_parser.NoOptionError) as exc:
            logger.debug("_check_and_handle_includes: EXCEPTION: %s", exc)
            return
        paths_lines = [p.strip() for p in paths.split("\n")]
        logger.debug("paths = %s (wanted just once; CLEARING)", paths_lines)
        self._parser.remove_option("INCLUDE", "paths")
        for f in paths_lines:
            abspath = (f if os.path.isabs(f) else
                       os.path.abspath(
                           os.path.join(os.path.dirname(from_file), f)))
            use_path = os.path.normpath(abspath)
            if use_path in self._parsed_files:
                raise RecursionInConfigFile("In %s: %s already read",
                                            from_file, use_path)
            self._parsed_files.append(use_path)
            self._handle_rc_file(use_path)
1055423
def rst(filename):
    '''
    
    '''
    content = codecs.open(filename, encoding='utf-8').read()
    for regex, replacement in PYPI_RST_FILTERS:
        content = re.sub(regex, replacement, content)
    return content
677996
def each
      dirs = ["pairtree_root"]
      excludes = []
      for dir in dirs
        Find.find(dir) do |path|
          if FileTest.directory?(path)
            if excludes.include?(File.basename(path))
              Find.prune       # Don't look any further into this directory.
            else
              next
            end
          else
            p path
          end
        end
      end   
    end
160175
def _clean_files_only(self, files):
        '''  '''
        try:
            if not (os.path.exists(self.origin_path)):
                self.logger.info("Creating Origin Path - %s" % self.origin_path)
                os.makedirs(self.origin_path) # create the origin_path directory
            if not (os.path.exists(self.dir_path)):
                self.logger.info("Creating Directory Path - %s" % self.dir_path)
                os.makedirs(self.dir_path)    # create the dir_path directory
            self._add_extra_files(files)

        except OSError as e: # pragma: no cover
            if e.errno == errno.EEXIST:
                pass
            else:   # pragma: no cover
                self.logger.exception(e)
                raise e

        except Exception as e:    # pragma: no cover
            self.logger.exception(e)
            raise Exception("CleanFilesOnlyError: unable to process")
112069
def recurse_tree(rootpath, excludes, opts):
    # type: (unicode, List[unicode], Any) -> List[unicode]
    
    if INITPY in os.listdir(rootpath):
        path_prefix = path.sep.join(rootpath.split(path.sep)[:-1])
    else:
        path_prefix = rootpath

    toplevels = []
    followlinks = getattr(opts, 'followlinks', False)
    includeprivate = getattr(opts, 'includeprivate', False)
    implicit_namespaces = getattr(opts, 'implicit_namespaces', False)
    for root, subs, files in walk(rootpath, followlinks=followlinks):
        # document only Python module files (that aren't excluded)
        py_files = sorted(f for f in files
                          if path.splitext(f)[1] in PY_SUFFIXES and
                          not is_excluded(path.join(root, f), excludes))
        is_pkg = INITPY in py_files
        if is_pkg:
            py_files.remove(INITPY)
            py_files.insert(0, INITPY)
        elif root != rootpath:
            # only accept non-package at toplevel unless using implicit
            # namespaces
            if not implicit_namespaces:
                del subs[:]
                continue
        # remove hidden ('.') and private ('_') directories, as well as
        # excluded dirs
        if includeprivate:
            exclude_prefixes = ('.',)  # type: Tuple[unicode, ...]
        else:
            exclude_prefixes = ('.', '_')
        subs[:] = sorted(sub for sub in subs
                         if not sub.startswith(exclude_prefixes) and
                         not is_excluded(path.join(root, sub), excludes))

        pkg = root[len(path_prefix):].lstrip(path.sep).replace(path.sep, '.')
        for py_file in py_files:
            if not shall_skip(path.join(root, py_file), opts):
                if py_file == INITPY:
                    module = ''
                else:
                    module = path.splitext(py_file)[0]
                toplevels.append(makename(pkg, module))

    return toplevels
735856
def create_py3_docs():
    
    # we want the correct .rst 'type' for our data
    trans = {"methods": "function", "exceptions": "exception", "constants": "attribute"}
    data = get_py3_info()
    for k, v in data.items():
        output = []
        for name, desc in v:
            output.append("")
            output.append(".. _%s:" % name)  # reference for linking
            output.append("")
            output.append(".. py:%s:: %s" % (trans[k], name))
            output.append("")
            output.extend(auto_undent(desc))
        with open("../doc/py3-%s-info.inc" % k, "w") as f:
            f.write("\n".join(output))
894969
def include(self, filename, *args, **kwargs):
        
        p = self.__class__(filename, skip_defaults=True, skip_fallbacks=True)
        self.update(p._sections, *args, **kwargs)
463150
def create_rc_file(self, packages):
        

        print("Creating rcfile '%s'\n" % self.rc_filename)

        # TODO bug with == in config file

        if not self.config.sections():
            self._write_default_sections()

        sections = {}
        section_text = []
        for i, section in enumerate(self.config.sections()):
            if section == 'metadata':
                continue
            sections[i] = section
            section_text.append('%s. %s' % (i, section))
        section_text = ' / '.join(section_text)

        self._remap_stdin()
        package_names = set()
        lines = packages.readlines()
        requirements = self._parse_requirements(lines)
        for (package, version) in requirements:
            package_names.add(package)
            section, configured_version = self._get_option(package)
            # Package already exists in configuration
            if section:
                # If there is a configured version, update it. If not, leave it unversioned.
                if configured_version:
                    if configured_version != version:
                        print("Updating '%s' version from '%s' to '%s'"
                              % (package, configured_version, version))
                        self.config.set(section, package, version)
                continue

            section = self._get_section(package, sections, section_text)
            self._set_option(section, package, version)

        for section in self.config.sections():
            if section == 'metadata':
                continue
            for option in self.config.options(section):
                if option not in package_names:
                    print("Removing package '%s'" % option)
                    self.config.remove_option(section, option)

        rc_file = open(self.rc_filename, 'w+')
        self.config.write(rc_file)
        rc_file.close()
351764
protected function set_include_files() {
        // We normally include files.
        $includefiles = true;

        // In an import, we don't need to include files.
        if ($this->get_mode() === backup::MODE_IMPORT) {
            $includefiles = false;
        }

        // When a backup is intended for the same site, we don't need to include the files.
        // Note, this setting is only used for duplication of an entire course.
        if ($this->get_mode() === backup::MODE_SAMESITE) {
            $includefiles = false;
        }

        $this->includefiles = (int) $includefiles;
        $this->log("setting file inclusion to {$this->includefiles}", backup::LOG_DEBUG);
        return $this->includefiles;
    }
1315660
private boolean handleResourceAsInclude(RebelResource rebelResource, Resource resource) {
    File dir = new File(resource.getDirectory());
    if (!dir.isAbsolute()) {
      dir = new File(getProject().getBasedir(), resource.getDirectory());
    }
    //if directory does not exist then exclude all
    if (!dir.exists() || !dir.isDirectory()) {
      return false;
    }

    resource.setDirectory(dir.getAbsolutePath());

    String[] files = getFilesToCopy(resource);
    if (files.length > 0) {
      //only include files that come from this directory
      List<String> includedFiles = new ArrayList<String>();
      for (String file : files) {
        includedFiles.add(StringUtils.replace(file, '\\', '/'));
      }
      rebelResource.setIncludes(includedFiles);
    }
    else {
      //there weren't any matching files
      return false;
    }

    return true;
  }
320453
def notebook_object_to_rst(ntbk, rpth, cr=None):
    

    # Parent directory of file rpth
    rdir = os.path.dirname(rpth)
    # File basename
    rb = os.path.basename(os.path.splitext(rpth)[0])

    # Pre-process notebook prior to conversion to rst
    if cr is not None:
        preprocess_notebook(ntbk, cr)
    # Convert notebook to rst
    rex = RSTExporter()
    rsttxt, rstres = rex.from_notebook_node(ntbk)
    # Replace `` with ` in sphinx cross-references
    rsttxt = re.sub(r':([^:]+):``(.*?)``', r':\1:`\2`', rsttxt)
    # Insert a cross-reference target at top of file
    reflbl = '.. _examples_' + os.path.basename(rdir) + '_' + \
             rb.replace('-', '_') + ':\n'
    rsttxt = reflbl + rsttxt
    # Write the converted rst to disk
    write_notebook_rst(rsttxt, rstres, rb, rdir)