{"id":18756529,"url":"https://github.com/octoprint/codemods","last_synced_at":"2025-07-15T20:46:54.598Z","repository":{"id":38840692,"uuid":"301699102","full_name":"OctoPrint/codemods","owner":"OctoPrint","description":"Codemods based on LibCST","archived":false,"fork":false,"pushed_at":"2023-09-11T02:30:10.000Z","size":64,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-26T19:44:31.837Z","etag":null,"topics":["python"],"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/OctoPrint.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-10-06T11:07:53.000Z","updated_at":"2023-11-16T00:28:29.000Z","dependencies_parsed_at":"2024-11-07T17:53:02.213Z","dependency_job_id":null,"html_url":"https://github.com/OctoPrint/codemods","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctoPrint%2Fcodemods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctoPrint%2Fcodemods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctoPrint%2Fcodemods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctoPrint%2Fcodemods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OctoPrint","download_url":"https://codeload.github.com/OctoPrint/codemods/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654045,"owners_count":21140235,"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":["python"],"created_at":"2024-11-07T17:37:00.384Z","updated_at":"2025-04-13T02:02:55.232Z","avatar_url":"https://github.com/OctoPrint.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 👷‍♀️ OctoPrint codemods\n\nHelpful codemods based on [LibCST](https://github.com/Instagram/LibCST/) created for use in OctoPrint development.\n\nProvided as-is for documentational purposes.\n\n## Setup\n\n    pip3 install .\n\n## Usage\n\nSee\n\n    codemod_* --help\n\nE.g.\n\n```\n$ codemod_not_in --help\nusage: codemod_not_in [-h] [--before] [--after] [--dryrun] [--ignore IGNORE]\n                      [--verbose] [--test]\n                      bases [bases ...]\n\nConverts 'not foo in bar' to 'foo not in bar' constructs.\n\npositional arguments:\n  bases            Files and directories (recursive) including python files to\n                   be modified.\n\noptional arguments:\n  -h, --help       show this help message and exit\n  --before         Write the CST of the original file to file.cst.before\n  --after          Write the CST of the transformed file to file.cst.after\n  --dryrun         Only perform a dry run without writing back the transformed\n                   file\n  --ignore IGNORE  Paths to ignore, add multiple as required\n  --verbose        Generate output for all processed files, not juse for those\n                   with replacements\n  --test           Run in test mode: first path is input file, second path is\n                   file with expected output.\n```\n\nTo run in test mode, use `--test` and supply two files, input and expected output, e.g.:\n\n```\n$ codemod_not_in --test tests/input/not_in.py tests/expected/not_in.py\ntests/input/not_in.py:4:0:\n  not foo in bar\n✨ Test successful, contents identical\n```\n\nFor running multiple codemods on the same inputs, it is recommended to use `codemod_batch`:\n\n```\n$ codemod_batch --check not_in --check remove_float_conversion tests/input/file.py\ntests/input/not_in.py:4:0:\n  not foo in bar\ntests/input/not_in.py: 1 replacements done\n```\n\n## pre-commit\n\nThis repository can be used with [pre-commit](https://pre-commit.com/).\n\n```yaml\n- repo: https://github.com/OctoPrint/codemods\n  rev: \"0.6.3\"\n  hooks:\n      - id: codemod_not_in\n```\n\nAdditional arguments can also be specified:\n\n```yaml\n- repo: https://github.com/OctoPrint/codemods\n  rev: \"0.6.3\"\n  hooks:\n      - id: codemod_not_in\n        args: [\"--ignore\", \"lib/vendor\"]\n```\n\nIf more than one command should be run, use the `batch` command for better performance:\n\n```yaml\n- repo: https://github.com/OctoPrint/codemods\n  rev: \"0.6.3\"\n  hooks:\n      - id: codemod_batch\n        args:\n            [\n                \"--ignore\",\n                \"lib/vendor\",\n                \"--check\",\n                \"not_in\",\n                \"--check\",\n                \"remove_float_conversion\"\n            ]\n```\n\n## What codemods are available?\n\n\u003e 🛑 **Heads-up**\n\u003e\n\u003e Mods overlapping with [pyupgrade](https://github.com/asottile/pyupgrade) have been\n\u003e removed in version 0.6.0.\n\n### `not_in`\n\nConverts `not foo in bar` to `foo not in bar` constructs.\n\n### `remove_builtins_imports`\n\nRemoves `from builtins import ...` and `import builtins`.\n\nUse with Python 3 source only.\n\n### `remove_float_conversion`\n\nRemoves unnecessary float conversions and `.0`s in division and multiplication.\n\nUse with Python 3 source only, unless `from __future__ import division` is used.\n\n## What code checks are available?\n\n### `detect_past_builtins_imports`\n\nDetects `from past... import ...` \u0026 `import past...`.\n\nUse with Python 3 source only.\n\n## Development\n\nCheckout out the source. Install source and requirements, in editable mode:\n\n```\npip install -e . -r requirements.txt\n```\n\nAll existing tests can be run with `pytest`.\n\nIndividual tests can be run with `codemod_{codemod} --test tests/input/{codemod}.py tests/expected/{codemod}.py` (replacing `{codemod}` with the codemod to test).\n\nWhen adding new codemods or checks, add implementation to `octoprint_codemods` (be sure to inherit from `octoprint_codemods.Codemod` or `octoprint_codemods.Codecheck` and implement `main` using `octoprint_codemods.runner`, see existing code).\n\n`--before` and `--after` can be used to generated dumps of the CST before and after transformation. `--dryrun` helps to keep input unmodified during development.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctoprint%2Fcodemods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctoprint%2Fcodemods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctoprint%2Fcodemods/lists"}