{"componentChunkName":"component---src-templates-blog-post-js","path":"/python-pre-commit","result":{"data":{"contentfulBlogPost":{"heroImage":{"fluid":{"src":"//images.ctfassets.net/afd61iijyym5/77n2UN5GtI0nmaVciPklAk/01471896c52cf8731e957cc8da1d26bf/aron-visuals-BXOXnQ26B7o-unsplash.jpg?w=800&h=420&q=50&fit=fill&f=center","srcSet":"//images.ctfassets.net/afd61iijyym5/77n2UN5GtI0nmaVciPklAk/01471896c52cf8731e957cc8da1d26bf/aron-visuals-BXOXnQ26B7o-unsplash.jpg?w=200&h=105&q=50&fit=fill&f=center 200w,\n//images.ctfassets.net/afd61iijyym5/77n2UN5GtI0nmaVciPklAk/01471896c52cf8731e957cc8da1d26bf/aron-visuals-BXOXnQ26B7o-unsplash.jpg?w=400&h=210&q=50&fit=fill&f=center 400w,\n//images.ctfassets.net/afd61iijyym5/77n2UN5GtI0nmaVciPklAk/01471896c52cf8731e957cc8da1d26bf/aron-visuals-BXOXnQ26B7o-unsplash.jpg?w=800&h=420&q=50&fit=fill&f=center 800w,\n//images.ctfassets.net/afd61iijyym5/77n2UN5GtI0nmaVciPklAk/01471896c52cf8731e957cc8da1d26bf/aron-visuals-BXOXnQ26B7o-unsplash.jpg?w=1200&h=630&q=50&fit=fill&f=center 1200w,\n//images.ctfassets.net/afd61iijyym5/77n2UN5GtI0nmaVciPklAk/01471896c52cf8731e957cc8da1d26bf/aron-visuals-BXOXnQ26B7o-unsplash.jpg?w=1600&h=840&q=50&fit=fill&f=center 1600w,\n//images.ctfassets.net/afd61iijyym5/77n2UN5GtI0nmaVciPklAk/01471896c52cf8731e957cc8da1d26bf/aron-visuals-BXOXnQ26B7o-unsplash.jpg?w=2400&h=1260&q=50&fit=fill&f=center 2400w","sizes":"(max-width: 800px) 100vw, 800px","aspectRatio":1.9047619047619047}},"body":{"childMarkdownRemark":{"html":"<p>Collaborating on a Python project? Keep the code base unified between contributers using pre-commit to streamline the workflow.</p>\n<h2>What is pre-commit?</h2>\n<p>Pre-commit is a Git hook that triggers when <code>git commit</code> is attempted.</p>\n<p>For Python projects, I use it to spend less time formatting my code and more time working on features and higher priority tasks.</p>\n<h2>Get started</h2>\n<ul>\n<li><code>pip install pre-commit</code></li>\n<li>add config file (<code>.pre-commit-config.yaml</code>), here's an example:</li>\n</ul>\n<pre><code>    repos:\n    - repo: https://github.com/PyCQA/pylint\n      rev: pylint-2.7.2  # Use the sha / tag you want to point at\n      hooks:\n      - id: pylint\n        exclude: ^server/\n    - repo: https://github.com/pre-commit/mirrors-autopep8\n      rev: v1.5.4  # Use the sha / tag you want to point at\n      hooks:\n      - id: autopep8\n        exclude: ^server/\n</code></pre>\n<ul>\n<li>Run <code>pre-commit install</code></li>\n<li>Run <code>pre-commit run --all-files</code> the first time pre-commit is added to the project so all files are checked</li>\n</ul>\n<p>Moving forward, pre-commit is triggered when <code>git commit</code> is attempted.</p>\n<h2>Usage</h2>\n<p>Commits are not saved until they pass the pre-commit.</p>\n<p>Based on the example configuration, all files must pass <code>pylint</code> then the same files are formatted to PEP 8 standard using <code>autopep8</code>.</p>\n<p>Errors will provide details about the files and why the process failed. Fix the issues and commit again until they pass.</p>\n<p>Pre-commit prevents pushing to the code base until they pass. Can you see the value in this? :)</p>"}},"title":"Automate Python Workflow With Pre-Commits: Autopep8 and Pylint","description":{"description":"Keep your Python project code base unified between contributers using pre-commit to streamline the workflow."},"updatedAt":"2021-05-05T20:43:02.461Z","author":{"name":"Edgar Ong"},"slug":"python-pre-commit","tags":["python","development"]},"allContentfulBlogPost":{"nodes":[{"tags":["python","development"],"title":"Automate Python Workflow With Pre-Commits: Autopep8 and Pylint","description":{"description":"Keep your Python project code base unified between contributers using pre-commit to streamline the workflow."},"slug":"python-pre-commit"},{"tags":["development"],"title":"What To Do After You Build A Feature","description":{"description":"You're not done yet, there's still more to do after coding a feature."},"slug":"building-feature"},{"tags":["development"],"title":"Build Small Apps to Git Gud","description":{"description":"Learn how to be a better developer by building small apps."},"slug":"build-small-apps"},{"tags":["general"],"title":"Hello world","description":{"description":"Hello from the perspective of a software engineer, post coding bootcamp!"},"slug":"hello-world"}]}},"pageContext":{"slug":"python-pre-commit","id":"f42ef783-7083-559f-baee-0db21362c81f"}},"staticQueryHashes":["63159454"]}