{"id":18960325,"url":"https://github.com/eugeneyan/python-collab-template","last_synced_at":"2025-08-20T03:31:53.462Z","repository":{"id":42995680,"uuid":"273815424","full_name":"eugeneyan/python-collab-template","owner":"eugeneyan","description":"🛠 Python project template with unit tests, code coverage, linting, type checking, Makefile wrapper, and GitHub Actions.","archived":false,"fork":false,"pushed_at":"2024-04-14T19:35:49.000Z","size":45,"stargazers_count":144,"open_issues_count":1,"forks_count":41,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-11T17:11:39.597Z","etag":null,"topics":["coverage","github-actions","hacktoberfest","linting","makefile","python","type-checking","unit-testing"],"latest_commit_sha":null,"homepage":"https://eugeneyan.com/writing/setting-up-python-project-for-automation-and-collaboration/","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/eugeneyan.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":"2020-06-21T01:48:38.000Z","updated_at":"2024-12-09T21:34:19.000Z","dependencies_parsed_at":"2024-11-16T11:14:41.685Z","dependency_job_id":null,"html_url":"https://github.com/eugeneyan/python-collab-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eugeneyan%2Fpython-collab-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eugeneyan%2Fpython-collab-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eugeneyan%2Fpython-collab-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eugeneyan%2Fpython-collab-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eugeneyan","download_url":"https://codeload.github.com/eugeneyan/python-collab-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230388131,"owners_count":18217755,"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":["coverage","github-actions","hacktoberfest","linting","makefile","python","type-checking","unit-testing"],"created_at":"2024-11-08T14:05:29.815Z","updated_at":"2024-12-19T06:10:08.483Z","avatar_url":"https://github.com/eugeneyan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Tests](https://github.com/eugeneyan/python-collab-template/workflows/Tests/badge.svg) [![codecov](https://codecov.io/gh/eugeneyan/python-collab-template/branch/master/graph/badge.svg)](https://codecov.io/gh/eugeneyan/python-collab-template)\n\n# python-collab-template\n\nRepository for [How to set up a Python Repo for Automation and Collaboration](https://eugeneyan.com/writing/setting-up-python-project-for-automation-and-collaboration/).\n\n## Quickstart\n```\n# Clone this repo and change directory\ngit clone git@github.com:eugeneyan/python-collab-template.git\ncd python-collab-template\n\n# Built docker image\nmake setup\n\n# Alternatively, you can create a python virtualenv on your local machine (-B might be needed to execute)\nmake setup-venv -B\n\n# Run the suite of tests and checks on docker\nmake run-checks\n\n# Alternatively, run the suite of tests and checks on your local machine\nmake checks\n```\n\nMake a pull request to this repo to see the checks in action 😎 \n\nHere's a [sample pull request](https://github.com/eugeneyan/python-collab-template/pull/1) which initially failed ❌ the checks, and then passed ✅.\n\n## Running our checks\n\nIn it, we cover the following aspects of setting up a python project, including:\n\n### Unit Tests\n\n```python\n@pytest.fixture\ndef lowercased_df():\n    string_col = ['futrelle, mme. jacques heath (lily may peel)',\n                  'backstrom, major. karl alfred (maria mathilda gustafsson)']\n    df_dict = {'string': string_col}\n    df = pd.DataFrame(df_dict)\n    return df\n\ndef test_extract_title(lowercased_df):\n    result = extract_title(lowercased_df, col='string')\n    assert result['title'].tolist() == ['mme', 'ms', 'mr', 'lady', 'major']\n\n\ndef test_extract_title_with_replacement(lowercased_df):\n    title_replacement = {'mme': 'mrs', 'ms': 'miss', 'lady': 'rare', 'major': 'rare'}\n    result = extract_title(lowercased_df, col='string', replace_dict=title_replacement)\n    assert result['title'].tolist() == ['mrs', 'miss', 'mr', 'rare', 'rare']\n```\n\n```shell\n$ pytest\n============================= test session starts ==============================\nplatform darwin -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1\nrootdir: /Users/eugene/projects/python-collaboration-template/tests/data_prep\ncollected 2 items\n\ntest_categorical.py::test_extract_title PASSED                           [ 50%]\ntest_categorical.py::test_extract_title_with_replacement PASSED          [100%]\n\n============================== 2 passed in 0.30s ===============================\n```\n\n### Code Coverage\n```\n$ pytest --cov=src\n============================= test session starts ==============================\nplatform darwin -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1\nrootdir: /Users/eugene/projects/python-collaboration-template\nplugins: cov-2.10.0\ncollected 9 items\n\ntests/data_prep/test_categorical.py ....                                 [ 44%]\ntests/data_prep/test_continuous.py .....                                 [100%]\n\n---------- coverage: platform darwin, python 3.8.2-final-0 -----------\nName                           Stmts   Miss  Cover\n--------------------------------------------------\nsrc/__init__.py                    0      0   100%\nsrc/data_prep/__init__.py          0      0   100%\nsrc/data_prep/categorical.py      12      0   100%\nsrc/data_prep/continuous.py       11      0   100%\n--------------------------------------------------\nTOTAL                             23      0   100%\n\n============================== 9 passed in 0.49s ===============================\n```\n\n### Linting\n```\n$ pylint src.data_prep.categorical --reports=y\n************* Module src.data_prep.categorical\nsrc/data_prep/categorical.py:20:0: C0330: Wrong continued indentation (add 9 spaces).\n                        df[title_col].map(replace_dict),\n                        ^        | (bad-continuation)\nsrc/data_prep/categorical.py:21:0: C0330: Wrong continued indentation (add 9 spaces).\n                        df[title_col])\n                        ^        | (bad-continuation)\nsrc/data_prep/categorical.py:16:12: W1401: Anomalous backslash in string: '\\.'. String constant might be missing an r prefix. (anomalous-backslash-in-string)\nsrc/data_prep/categorical.py:1:0: C0114: Missing module docstring (missing-module-docstring)\nsrc/data_prep/categorical.py:5:0: C0116: Missing function or method docstring (missing-function-docstring)\nsrc/data_prep/categorical.py:9:0: C0116: Missing function or method docstring (missing-function-docstring)\nsrc/data_prep/categorical.py:14:0: C0116: Missing function or method docstring (missing-function-docstring)\n\nReport\n======\n12 statements analysed.\n\n...\n\nMessages\n--------\n+------------------------------+------------+\n|message id                    |occurrences |\n+==============================+============+\n|missing-function-docstring    |3           |\n+------------------------------+------------+\n|bad-continuation              |2           |\n+------------------------------+------------+\n|missing-module-docstring      |1           |\n+------------------------------+------------+\n|anomalous-backslash-in-string |1           |\n+------------------------------+------------+\n\n-----------------------------------\nYour code has been rated at 4.17/10\n```\n\n### Type Checking\n```\n$ mypy src\nsrc/data_prep/continuous.py:23: error: Incompatible types in assignment (expression has type \"str\", variable has type \"float\")\nFound 1 error in 1 file (checked 4 source files)\n```\n\n```\n$ mypy src\nSuccess: no issues found in 4 source files\n```\n\n### Wrapping it in a Makefile\n```\nclean-pyc:\n\tfind . -name '*.pyc' -exec rm -f {} +\n\tfind . -name '*.pyo' -exec rm -f {} +\n\tfind . -name '*~' -exec rm -f {} +\n\tfind . -name '__pycache__' -exec rm -fr {} +\n\nclean-test:\n\trm -f .coverage\n\trm -f .coverage.*\n\nclean: clean-pyc clean-test\n\ntest: clean\n\t. .venv/bin/activate \u0026\u0026 py.test tests --cov=src --cov-report=term-missing --cov-fail-under 95\n```\n\n### GitHub Actions with each `git push`\n```\n# .github/workflows/tests.yml\nname: Tests\non: push\njobs:\n  tests:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v2\n    - uses: actions/setup-python@v1\n      with:\n        python-version: 3.8\n        architecture: x64\n    - run: make setup\n    - run: make check\n    - run: bash \u003c(curl -s https://codecov.io/bash)\n```\n\n### 👉 View the [article](https://eugeneyan.com/writing/setting-up-python-project-for-automation-and-collaboration/) for the walkthrough.\n\n### Todo\n- [ ] Update requirements.txt to use `poetry`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feugeneyan%2Fpython-collab-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feugeneyan%2Fpython-collab-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feugeneyan%2Fpython-collab-template/lists"}