mirror of
https://github.com/k2-fsa/icefall.git
synced 2025-08-09 01:52:41 +00:00
205 lines
11 KiB
HTML
205 lines
11 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<html class="writer-html5" lang="en">
|
|
<head>
|
|
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Follow the code style — icefall 0.1 documentation</title>
|
|
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=03e43079" />
|
|
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=e59714d7" />
|
|
|
|
|
|
<script src="../_static/jquery.js?v=5d32c60e"></script>
|
|
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
|
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js?v=e031e9a9"></script>
|
|
<script src="../_static/doctools.js?v=888ff710"></script>
|
|
<script src="../_static/sphinx_highlight.js?v=4825356b"></script>
|
|
<script src="../_static/js/theme.js"></script>
|
|
<link rel="index" title="Index" href="../genindex.html" />
|
|
<link rel="search" title="Search" href="../search.html" />
|
|
<link rel="next" title="How to create a recipe" href="how-to-create-a-recipe.html" />
|
|
<link rel="prev" title="Contributing to Documentation" href="doc.html" />
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav">
|
|
<div class="wy-grid-for-nav">
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-scroll">
|
|
<div class="wy-side-nav-search" >
|
|
|
|
|
|
|
|
<a href="../index.html" class="icon icon-home">
|
|
icefall
|
|
</a>
|
|
<div role="search">
|
|
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
|
|
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="../for-dummies/index.html">Icefall for dummies tutorial</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="../docker/index.html">Docker</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="../faqs.html">Frequently Asked Questions (FAQs)</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="../model-export/index.html">Model export</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="../fst-based-forced-alignment/index.html">FST-based forced alignment</a></li>
|
|
</ul>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="../recipes/index.html">Recipes</a></li>
|
|
</ul>
|
|
<ul class="current">
|
|
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Contributing</a><ul class="current">
|
|
<li class="toctree-l2"><a class="reference internal" href="doc.html">Contributing to Documentation</a></li>
|
|
<li class="toctree-l2 current"><a class="current reference internal" href="#">Follow the code style</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="how-to-create-a-recipe.html">How to create a recipe</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="../huggingface/index.html">Huggingface</a></li>
|
|
</ul>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="../decoding-with-langugage-models/index.html">Decoding with language models</a></li>
|
|
</ul>
|
|
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="../index.html">icefall</a>
|
|
</nav>
|
|
|
|
<div class="wy-nav-content">
|
|
<div class="rst-content">
|
|
<div role="navigation" aria-label="Page navigation">
|
|
<ul class="wy-breadcrumbs">
|
|
<li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
|
|
<li class="breadcrumb-item"><a href="index.html">Contributing</a></li>
|
|
<li class="breadcrumb-item active">Follow the code style</li>
|
|
<li class="wy-breadcrumbs-aside">
|
|
<a href="https://github.com/k2-fsa/icefall/blob/master/docs/source/contributing/code-style.rst" class="fa fa-github"> Edit on GitHub</a>
|
|
</li>
|
|
</ul>
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
<div itemprop="articleBody">
|
|
|
|
<section id="follow-the-code-style">
|
|
<span id="id1"></span><h1>Follow the code style<a class="headerlink" href="#follow-the-code-style" title="Permalink to this heading"></a></h1>
|
|
<p>We use the following tools to make the code style to be as consistent as possible:</p>
|
|
<blockquote>
|
|
<div><ul class="simple">
|
|
<li><p><a class="reference external" href="https://github.com/psf/black">black</a>, to format the code</p></li>
|
|
<li><p><a class="reference external" href="https://github.com/PyCQA/flake8">flake8</a>, to check the style and quality of the code</p></li>
|
|
<li><p><a class="reference external" href="https://github.com/PyCQA/isort">isort</a>, to sort <code class="docutils literal notranslate"><span class="pre">imports</span></code></p></li>
|
|
</ul>
|
|
</div></blockquote>
|
|
<p>The following versions of the above tools are used:</p>
|
|
<blockquote>
|
|
<div><ul class="simple">
|
|
<li><p><code class="docutils literal notranslate"><span class="pre">black</span> <span class="pre">==</span> <span class="pre">22.3.0</span></code></p></li>
|
|
<li><p><code class="docutils literal notranslate"><span class="pre">flake8</span> <span class="pre">==</span> <span class="pre">5.0.4</span></code></p></li>
|
|
<li><p><code class="docutils literal notranslate"><span class="pre">isort</span> <span class="pre">==</span> <span class="pre">5.10.1</span></code></p></li>
|
|
</ul>
|
|
</div></blockquote>
|
|
<p>After running the following commands:</p>
|
|
<blockquote>
|
|
<div><div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ git clone https://github.com/k2-fsa/icefall
|
|
$ cd icefall
|
|
$ pip install pre-commit
|
|
$ pre-commit install
|
|
</pre></div>
|
|
</div>
|
|
</div></blockquote>
|
|
<p>it will run the following checks whenever you run <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">commit</span></code>, <strong>automatically</strong>:</p>
|
|
<blockquote>
|
|
<div><figure class="align-center" id="id2">
|
|
<a class="reference internal image-reference" href="../_images/pre-commit-check.png"><img alt="../_images/pre-commit-check.png" src="../_images/pre-commit-check.png" style="width: 600px;" /></a>
|
|
<figcaption>
|
|
<p><span class="caption-number">Fig. 12 </span><span class="caption-text">pre-commit hooks invoked by <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">commit</span></code> (Failed).</span><a class="headerlink" href="#id2" title="Permalink to this image"></a></p>
|
|
</figcaption>
|
|
</figure>
|
|
</div></blockquote>
|
|
<p>If any of the above checks failed, your <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">commit</span></code> was not successful.
|
|
Please fix any issues reported by the check tools.</p>
|
|
<div class="admonition hint">
|
|
<p class="admonition-title">Hint</p>
|
|
<p>Some of the check tools, i.e., <code class="docutils literal notranslate"><span class="pre">black</span></code> and <code class="docutils literal notranslate"><span class="pre">isort</span></code> will modify
|
|
the files to be committed <strong>in-place</strong>. So please run <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">status</span></code>
|
|
after failure to see which file has been modified by the tools
|
|
before you make any further changes.</p>
|
|
</div>
|
|
<p>After fixing all the failures, run <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">commit</span></code> again and
|
|
it should succeed this time:</p>
|
|
<blockquote>
|
|
<div><figure class="align-center" id="id3">
|
|
<a class="reference internal image-reference" href="../_images/pre-commit-check-success.png"><img alt="../_images/pre-commit-check-success.png" src="../_images/pre-commit-check-success.png" style="width: 600px;" /></a>
|
|
<figcaption>
|
|
<p><span class="caption-number">Fig. 13 </span><span class="caption-text">pre-commit hooks invoked by <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">commit</span></code> (Succeeded).</span><a class="headerlink" href="#id3" title="Permalink to this image"></a></p>
|
|
</figcaption>
|
|
</figure>
|
|
</div></blockquote>
|
|
<p>If you want to check the style of your code before <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">commit</span></code>, you
|
|
can do the following:</p>
|
|
<blockquote>
|
|
<div><div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>pre-commit<span class="w"> </span>install
|
|
$<span class="w"> </span>pre-commit<span class="w"> </span>run
|
|
</pre></div>
|
|
</div>
|
|
</div></blockquote>
|
|
<p>Or without installing the pre-commit hooks:</p>
|
|
<blockquote>
|
|
<div><div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span><span class="nb">cd</span><span class="w"> </span>icefall
|
|
$<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span><span class="nv">black</span><span class="o">==</span><span class="m">22</span>.3.0<span class="w"> </span><span class="nv">flake8</span><span class="o">==</span><span class="m">5</span>.0.4<span class="w"> </span><span class="nv">isort</span><span class="o">==</span><span class="m">5</span>.10.1
|
|
$<span class="w"> </span>black<span class="w"> </span>--check<span class="w"> </span>your_changed_file.py
|
|
$<span class="w"> </span>black<span class="w"> </span>your_changed_file.py<span class="w"> </span><span class="c1"># modify it in-place</span>
|
|
$
|
|
$<span class="w"> </span>flake8<span class="w"> </span>your_changed_file.py
|
|
$
|
|
$<span class="w"> </span>isort<span class="w"> </span>--check<span class="w"> </span>your_changed_file.py<span class="w"> </span><span class="c1"># modify it in-place</span>
|
|
$<span class="w"> </span>isort<span class="w"> </span>your_changed_file.py
|
|
</pre></div>
|
|
</div>
|
|
</div></blockquote>
|
|
</section>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
|
|
<a href="doc.html" class="btn btn-neutral float-left" title="Contributing to Documentation" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
|
<a href="how-to-create-a-recipe.html" class="btn btn-neutral float-right" title="How to create a recipe" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
|
|
</div>
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>© Copyright 2021, icefall development team.</p>
|
|
</div>
|
|
|
|
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
|
|
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
|
|
provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
|
|
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
<script>
|
|
jQuery(function () {
|
|
SphinxRtdTheme.Navigation.enable(true);
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |