{"id":16799581,"url":"https://github.com/joeyespo/hack-function","last_synced_at":"2025-05-16T05:08:28.704Z","repository":{"id":62568875,"uuid":"121060314","full_name":"joeyespo/hack-function","owner":"joeyespo","description":"\"Goto Definition\" for the Python Interpreter","archived":false,"fork":false,"pushed_at":"2018-02-12T06:01:41.000Z","size":7,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T17:18:48.191Z","etag":null,"topics":["debugging-tools","productivity","python","python-3","source-code","tools"],"latest_commit_sha":null,"homepage":null,"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/joeyespo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-10T22:34:04.000Z","updated_at":"2022-11-06T16:28:45.000Z","dependencies_parsed_at":"2022-11-03T16:46:56.756Z","dependency_job_id":null,"html_url":"https://github.com/joeyespo/hack-function","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeyespo%2Fhack-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeyespo%2Fhack-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeyespo%2Fhack-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeyespo%2Fhack-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joeyespo","download_url":"https://codeload.github.com/joeyespo/hack-function/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471058,"owners_count":22076585,"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":["debugging-tools","productivity","python","python-3","source-code","tools"],"created_at":"2024-10-13T09:29:10.445Z","updated_at":"2025-05-16T05:08:28.662Z","avatar_url":"https://github.com/joeyespo.png","language":"Python","readme":"Hack - \"Goto Definition\" for the Python Interpreter\n===================================================\n\n[![Current version on PyPI](http://img.shields.io/pypi/v/hack-function.svg)](http://pypi.python.org/pypi/hack-function/)\n[![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-😊-1EAEDB.svg)](https://saythanks.io/to/joeyespo)\n\nExposes a `hack` function to \"hack open\" an object from the Python Interpreter,\nwhich loads the object's source file at the line its defined on using the\ndefault or [configured](#configuring) text editor. It can also print out or\nreturn a string of this metadata instead.\n\n\nWhy?\n----\n\nSometimes you just need to read the source.\n\nThe Python Interpreter, `dir`, and `help` are fantastic tools for tinkering and\nsanity checking. However, at times the only way to gain a better understanding\nis to see what's going on below the surface. Spending the time searching or\ntracking down where an object is defined can be tedious and distracting.\n\nNow all you have to remember is `hack(\u003cobject\u003e)`.\n\n#### Use cases\n\n- Read the source of a function when its documentation is unclear or incomplete\n- Quickly jump to a package you're developing when tinkering in the interpreter\n- Explore a dependency to confirm a bug without having to learn its file layout\n\n\nInstallation\n------------\n\n```bash\n$ pip install hack-function\n```\n\nAfter installing, the `hack` function will be available globally.\n\n\nUsage\n-----\n\nView the source of an object in your code editor:\n\n```py\n\u003e\u003e\u003e import os\n\u003e\u003e\u003e hack(os.path.isabs)\n```\n\nYou can also view it directly in the interpreter:\n\n```py\n\u003e\u003e\u003e hack(os.path.isabs, 'source')\ndef isabs(s):\n    \"\"\"Test whether a path is absolute\"\"\"\n    s = os.fspath(s)\n    s = splitdrive(s)[1]\n    return len(s) \u003e 0 and s[0] in _get_bothseps(s)\n```\n\nOr print just the path and line number:\n\n```py\n\u003e\u003e\u003e hack(os.path.join, 'path')\n/usr/lib/python3.5/posixpath.py:62\n```\n\nEach action can also be aliased by its first character:\n\n```py\n\u003e\u003e\u003e hack(os.path, 'p')\n/usr/lib/python3.5/posixpath.py\n```\n\nAnd some actions can be configured further:\n\n```py\n\u003e\u003e\u003e out = hack(os.path.isabs, 's', capture=True)\n\u003e\u003e\u003e out.split('\\n')[0]\n'def isabs(s):\\n'\n```\n\nTake a look at the `hack` source code for more details:\n\n```py\n\u003e\u003e\u003e hack(hack)\n```\n\n\nConfiguring\n-----------\n\nBy default, `hack` takes a best-guess of which text editor to use. You can\noverride this by setting one of the following to your editor's run command:\n- The contents of `~/.hack-function`\n- The `EDITOR` environment variable\n- The `HACK_FUNCTION_EDITOR` environment variable\n\nIn the above, `$FILE` will be replaced with the filename to open and `$LINE`\nwith the line number. If these aren't preset, the filename will be appended\nto the command.\n\n#### Examples\n\nLinux and Mac:\n\n```bash\n$ EDITOR=\"vi +\\$LINE \\$FILE\" python\n\u003e\u003e\u003e hack(hack)\n```\n\nWindows:\n\n```batch\n\u003eSET EDITOR=\"C:\\Program Files\\Sublime Text 3\\sublime_text.exe\" $FILE:$LINE\n\u003epy\n\u003e\u003e\u003e hack(hack)\n```\n\nOr persist one of the above `EDITOR` values in a `~/.hack-function` file.\n\nAdditional notes\n----------------\n\n- `hack` will not work on builtin objects and modules (since they're likely implemented outside of Python code)\n- `hack` uses the `inspect` module internally (look here if you need programmatic access to this information)\n\n\nContributing\n------------\n\n1. Check the open issues or open a new issue to start a discussion around\n   your feature idea or the bug you found\n2. Fork the repository and make your changes\n3. Open a new pull request\n\nIf your PR has been waiting a while, feel free to [ping me on Twitter](https://twitter.com/joeyespo).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeyespo%2Fhack-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoeyespo%2Fhack-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeyespo%2Fhack-function/lists"}