{"id":15441169,"url":"https://github.com/15r10nk/pysource-codegen","last_synced_at":"2025-04-07T13:04:59.632Z","repository":{"id":161171114,"uuid":"627623719","full_name":"15r10nk/pysource-codegen","owner":"15r10nk","description":"generate random python code to test linter/formatter/and other tools","archived":false,"fork":false,"pushed_at":"2024-10-28T23:32:09.000Z","size":233,"stargazers_count":38,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-29T20:55:38.468Z","etag":null,"topics":["fuzzing","python","testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/15r10nk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"15r10nk"}},"created_at":"2023-04-13T21:19:18.000Z","updated_at":"2024-10-28T14:47:13.000Z","dependencies_parsed_at":"2023-12-25T21:38:10.986Z","dependency_job_id":"121a7da8-fed1-429e-befe-54f907ed3e7a","html_url":"https://github.com/15r10nk/pysource-codegen","commit_stats":{"total_commits":165,"total_committers":5,"mean_commits":33.0,"dds":0.06060606060606055,"last_synced_commit":"7dd66763310450a41d0dc5e652932b4e2a0c17e4"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/15r10nk%2Fpysource-codegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/15r10nk%2Fpysource-codegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/15r10nk%2Fpysource-codegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/15r10nk%2Fpysource-codegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/15r10nk","download_url":"https://codeload.github.com/15r10nk/pysource-codegen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657276,"owners_count":20974344,"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":["fuzzing","python","testing"],"created_at":"2024-10-01T19:16:59.332Z","updated_at":"2025-04-07T13:04:59.607Z","avatar_url":"https://github.com/15r10nk.png","language":"Python","funding_links":["https://github.com/sponsors/15r10nk"],"categories":[],"sub_categories":[],"readme":"[![pypi version](https://img.shields.io/pypi/v/pysource-codegen.svg)](https://pypi.org/project/pysource-codegen/)\n![Python Versions](https://img.shields.io/pypi/pyversions/pysource-codegen)\n![PyPI - Downloads](https://img.shields.io/pypi/dw/pysource-codegen)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/15r10nk)](https://github.com/sponsors/15r10nk)\n\n# Introduction\n\n\n`pysource_codegen` is able to generate random python code which can be compiled.\nThe compiled code should not be executed.\n\nThis is still a very early version, but it does its job.\nIt is general useful to test tools like formatters, linters or anything which operates on python code.\n\n## Install:\n``` bash\npip install pysource-codegen\n```\n\n## Usage:\n\nThe tool can be used over the CLI:\n\n``` bash\npysource-codegen --seed 42\n```\n\nor as a library:\n\n``` python\nfrom pysource_codegen import generate\n\nseed = 42\nprint(generate(seed))\n```\n\nYou might find [pysource-minimize](https://github.com/15r10nk/pysource-minimize) also useful\nto reduce the generated code which triggers your bug down to a minimal code snipped,\nwhich can be used to fix the issue.\n\n``` python\nfrom pysource_codegen import generate\nfrom pysource_minimize import minimize\n\n\ndef contains_bug(code):\n    \"\"\"\n    returns True if the code triggers a bug and False otherwise\n    \"\"\"\n    try:\n        test_something_with(code)  # might throw\n\n        if \"bug\" in code:  # maybe other checks\n            return True\n    except:\n        return True\n    return False\n\n\ndef find_issue():\n    for seed in range(0, 10000):\n        code = generate(seed)\n\n        if contains_bug(code):\n            new_code = minimize(code, contains_bug)\n\n            print(\"the following code triggers a bug\")\n            print(new_code)\n\n            return\n\n\nfind_issue()\n```\n\n\n## Bugs found in other projects:\n\n### black\n\n* https://github.com/psf/black/issues/3676\n* https://github.com/psf/black/issues/3678\n* https://github.com/psf/black/issues/3677\n\n### cpython\n\n#### 3.12\n* https://github.com/python/cpython/issues/109219\n* https://github.com/python/cpython/issues/109823\n* https://github.com/python/cpython/issues/109719\n* https://github.com/python/cpython/issues/109627\n* https://github.com/python/cpython/issues/109219\n* https://github.com/python/cpython/issues/109118\n* https://github.com/python/cpython/issues/109114\n* https://github.com/python/cpython/issues/109889\n\n#### 3.13\n* https://github.com/python/cpython/issues/120367\n* https://github.com/python/cpython/issues/120225\n* https://github.com/python/cpython/issues/124746\n* https://github.com/python/cpython/issues/124871\n\n## Todo:\n\n* [ ] refactor the existing code\n  * add better context information to `probability()`\n  * remove `fix()` function and move code into `probability()`\n* [ ] use probabilities for the ast-nodes from existing python code (use markov chains)\n* [x] support older python versions\n* [ ] allow to customize the probabilities to generate code to test specific language features\n* [ ] [hypothesis](https://hypothesis.readthedocs.io/en/latest/) support\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F15r10nk%2Fpysource-codegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F15r10nk%2Fpysource-codegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F15r10nk%2Fpysource-codegen/lists"}