{"id":21911739,"url":"https://github.com/stepicorg/amorph","last_synced_at":"2025-03-22T08:27:38.666Z","repository":{"id":142905489,"uuid":"92298878","full_name":"StepicOrg/amorph","owner":"StepicOrg","description":"Finds set of patches to transform one code into another","archived":false,"fork":false,"pushed_at":"2017-11-14T10:39:16.000Z","size":1315,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-01-27T08:42:02.112Z","etag":null,"topics":["code","refactor","restructure","transform"],"latest_commit_sha":null,"homepage":"","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/StepicOrg.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":"2017-05-24T14:03:35.000Z","updated_at":"2017-07-12T09:50:39.000Z","dependencies_parsed_at":"2023-06-26T02:05:11.873Z","dependency_job_id":null,"html_url":"https://github.com/StepicOrg/amorph","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StepicOrg%2Famorph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StepicOrg%2Famorph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StepicOrg%2Famorph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StepicOrg%2Famorph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StepicOrg","download_url":"https://codeload.github.com/StepicOrg/amorph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244929459,"owners_count":20533770,"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":["code","refactor","restructure","transform"],"created_at":"2024-11-28T18:07:29.294Z","updated_at":"2025-03-22T08:27:38.660Z","avatar_url":"https://github.com/StepicOrg.png","language":"Python","readme":"# Amorph\nPackage for Python source code transformation.\n\n```python\n\u003e\u003e\u003e from amorph import patch_with_closest\n\u003e\u003e\u003e source = '''\n... def f(a, b):\n...    return a + b\n... '''\n\u003e\u003e\u003e samples = [\n... '''\n... def f(a, b):\n...    return a * b\n... ''',\n... '''\n... def f(a, b):\n...    return sum([a for i in range(b)])\n... '''\n... ]\n\u003e\u003e\u003e for patch in patch_with_closest(source, samples):\n...     print(patch)\nReplace char #26 with '*'\n```\n\n## Use cases\n\n### Patch with given sample\n```python\nfrom amorph import patch_with_sample\n\npatches = patch_with_sample(source, sample)\n```\n\n### Specify patch method\nCurrently `diff`, `tokens` and `ast` methods available.\nTo use `ast` patching you should run the [API server](https://github.com/laplab/amorph-java) first.\n```python\nfrom amorph import patch_with_closest, patch_with_sample, Method\n\npatches = patch_with_sample(source, sample, method=Method.DIFF)\npatches = patch_with_closest(source, samples, method=Method.DIFF)\n```\n\n### Find closest code\n```python\nfrom amorph.utils import find_closest\n\nclosest_sample = find_closest(source, sample)\n```\n\n### Custom metric\n```python\nfrom amorph import patch_with_closest\nfrom amorph.utils import find_closest\n\ndef dummy_metric(source, sample):\n    return source.count('def') - sample.count('def')\n\nclosest_sample = find_closest(source, samples, metric=dummy_metric)\npatches = patch_with_closest(source, samples, metric=dummy_metric)\n```\n\n### Nested objects\n```python\nfrom amorph import patch_with_closest, patch_with_sample\nfrom amorph.utils import find_closest\nfrom operator import itemgetter\n\nsource = {'code': 'print(input())'}\nsamples = [{'code': 'print(\"Hello World!\")'}, {'code': 'print(\"Bye Bye!\")'}]\nget_code = itemgetter('code')\n\nclosest = find_closest(source, samples, key=get_code)\npatches = patch_with_sample(source, closest, key=get_code)\npatches = patch_with_closest(source, samples, key=get_code)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepicorg%2Famorph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstepicorg%2Famorph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepicorg%2Famorph/lists"}