{"id":18683560,"url":"https://github.com/scify/code_quality_workshop","last_synced_at":"2025-11-07T18:30:32.604Z","repository":{"id":206236178,"uuid":"710201057","full_name":"scify/code_quality_workshop","owner":"scify","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-28T06:58:31.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-12-27T23:43:58.319Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-26T08:16:03.000Z","updated_at":"2024-07-28T06:58:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"5e2f03c0-ec6c-464f-b17c-489fc414198a","html_url":"https://github.com/scify/code_quality_workshop","commit_stats":null,"previous_names":["scify/code_quality_workshop"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scify%2Fcode_quality_workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scify%2Fcode_quality_workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scify%2Fcode_quality_workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scify%2Fcode_quality_workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scify","download_url":"https://codeload.github.com/scify/code_quality_workshop/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239535291,"owners_count":19655008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T10:14:56.763Z","updated_at":"2025-02-18T19:29:39.251Z","avatar_url":"https://github.com/scify.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Software Development \u0026 Code Quality Workshop\n\nBefore we start:\n1. clone the repo: git clone git@github.com:scify/code_quality_workshop.git\n2. Install dependencies\n    - with poetry\n        ```\n        cd \u003cpath to dir\u003e\n        poetry init\n        poetry install\n        ```\n    - with pip:\n        Create virtual environment of your choice.\n        ```\n        pip install -r requirements\n        ```\n\n# Overview\n\n## What we need?\n\n1. We need to make sure our code is maintainable and readable at all times.\n2. We need to catch code smells as soon as possible.\n3. We need a common style of writting for better in between team readability.\n\n## How?\n\nBy Using:\n\n1. Linters\n2. Formatters\n\n\n## Linting\n\n\n### What is a Linter\n\nA linter can:\n- Catch code smells\n- Find code that is not compliant to a certain style guideline (such as PEP8)\n\n### PEP8\n\nPEP8 is a very impactful style guide for python.\n\nExample:\n\n```\nx=5 -\u003e no\nx =5 -\u003e no\nx = 5 -?ye\n```\n\n### Proposed Linter\n\nruff (https://github.com/astral-sh/ruff)\n\nFrom the command line:\n\n```\nruff check --select=E,T201 .\nruff check --select=ALL .\n```\n\n### Rule examples\n\n- pep8-naming (N) https://docs.astral.sh/ruff/rules/#pep8-naming-n\n- flake8-print (T20) https://docs.astral.sh/ruff/rules/#flake8-print-t20\n- flake8-bandit (S) https://docs.astral.sh/ruff/rules/#flake8-bandit-s\n\n\n## Formatting\n\n\n### What is a Formatter?\n\nFormats source code automatically.\n\nExamples:\n- Replace tabs with 4 spaces\n- Split a too long line\n\nIt accomplises consistency in the code base and among programmers.\n\n### Proposed Formatters\n\nblack (https://github.com/psf/black)\nisort (https://pycqa.github.io/isort/)\n\n#### Isort\n\nSorts and groups our Imports.\n\nExample (source: https://pycqa.github.io/isort/):\n\nBefore isort:\n```\nfrom my_lib import Object\n\nimport os\n\nfrom my_lib import Object3\n\nfrom my_lib import Object2\n\nimport sys\n\nfrom third_party import lib15, lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14\n\nimport sys\n\nfrom __future__ import absolute_import\n\nfrom third_party import lib3\n\nprint(\"Hey\")\nprint(\"yo\")\n```\n\nAfter isort:\n\n```\nfrom __future__ import absolute_import\n\nimport os\nimport sys\n\nfrom third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8,\n                         lib9, lib10, lib11, lib12, lib13, lib14, lib15)\n\nfrom my_lib import Object, Object2, Object3\n\nprint(\"Hey\")\nprint(\"yo\")\n```\n\n#### Black formatter\n\n- Is opinionated (limited configuration options)\n- Has integration with InteliJ, VSCode\n- industry standard\n\n##### Is Black safe to use?\n\nYes. [..] Black strives to ensure that after formatting the AST is checked with limited special cases where the code is allowed to differ. If issues are found, an error is raised and the file is left untouched.[..]\n(source: https://black.readthedocs.io/en/stable/faq.html#is-black-safe-to-use)\n\n\n##### Running black\n\nShow the changes that will be made:\n```\nblack . --diff\n```\n\nrun black formatter:\n```\nblack .\n```\n\n\n## Where can we enforce those?\n\n- On commit\n- On push/merge\n\n\n### Enforcing on commit\n\npre-commit (https://pre-commit.com/) is a tool to easily manage git hooks. With pre-commit we can install git hooks for all the tools\ndiscussed so far.\n\nThat way, every time we commit all these tools will run and will reject our commit if they don't pass.\n\n#### Usage\n\nFirst we create a configuration file that will hold pre-commit configurations.\n\nExample:\n```\nrepos:\n-   repo: https://github.com/pre-commit/pre-commit-hooks\n    rev: v2.3.0\n    hooks:\n    -   id: check-yaml\n    -   id: end-of-file-fixer\n    -   id: trailing-whitespace\n-   repo: https://github.com/psf/black\n    rev: 22.10.0\n    hooks:\n    -   id: black\n```\n\nThen we need to install the specified hooks:\nRun:\n\n```\npre-commit install\n```\n\nNow every time we commit the hooks will run.\n\n#### pre-commit CLI\n\nWe can run hooks without commiting from the cli. This can easily bundle all our tools together!\n\n```\npre-commit run --all-files\n```\n\nWe can also specify a hook to skip when we want to commit:\n```\nSKIP=flake8 git commit -m \"foo\"\n```\nor skip all hooks:\n```\ngit commit -m \"adding code\" --no-verify\n```\n\nNOTE: Ruff's lint hook should be placed after other formatting tools, such as Ruff's format hook, Black, or isort.\n\n### Enforcing on Push/Merge\n\nGithub Actions\n\nWe can enforce certain actions to run when either a push is made, a pull request is created etc.\nThese actions could involve:\n- Check linting\n- Tests\n- Other\n\nThat is what we would call a very very basic CI!\n\nNOTE: Format should be avoided in CI. Since formatting changes the source code, we would not want that to run in the CI as this would result in inconsistencies between code commited in git and code deployed later!\n\n#### What does this CI currently do?\n\n1. Enforces that code quality is always maintained properly on our main/production branch.\n2. Easily tests linting on multiple python versions\n\n### Other\n\nfor typos:\ntypos (https://github.com/crate-ci/typos)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscify%2Fcode_quality_workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscify%2Fcode_quality_workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscify%2Fcode_quality_workshop/lists"}