{"id":21044973,"url":"https://github.com/quansight/pyflyby-old","last_synced_at":"2025-03-13T22:11:45.854Z","repository":{"id":98607538,"uuid":"203232112","full_name":"Quansight/pyflyby-old","owner":"Quansight","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-11T19:18:44.000Z","size":1356,"stargazers_count":1,"open_issues_count":4,"forks_count":1,"subscribers_count":47,"default_branch":"master","last_synced_at":"2025-03-10T15:17:10.324Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Quansight.png","metadata":{"files":{"readme":"README.txt","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2019-08-19T18:59:09.000Z","updated_at":"2019-09-11T19:52:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"b132624a-d549-40cf-925a-63b0c34b4a25","html_url":"https://github.com/Quansight/pyflyby-old","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quansight%2Fpyflyby-old","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quansight%2Fpyflyby-old/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quansight%2Fpyflyby-old/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quansight%2Fpyflyby-old/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Quansight","download_url":"https://codeload.github.com/Quansight/pyflyby-old/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243489835,"owners_count":20299001,"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":[],"created_at":"2024-11-19T14:19:24.032Z","updated_at":"2025-03-13T22:11:45.830Z","avatar_url":"https://github.com/Quansight.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pyflyby is a set of Python programming productivity tools.\n\nFor command-line interaction:\n  * py: command-line multitool\n\nFor IPython interaction:\n  * autoimporter: automatically imports symbols when needed.\n\nFor editing python source code:\n  * tidy-imports:      adds missing 'import's, removes unused 'import's, and\n                       also reformats 'import' blocks.\n  * find-imports:      prints to stdout how to import a particular symbol.\n  * reformat-imports:  reformats 'import' blocks\n  * collect-imports:   prints out all the imports in a given set of files.\n  * collect-exports:   prints out definitions in a given set of modules, in the\n                       form of import statements.\n  * transform-imports: renames imported modules/functions.\n\nQuick start: Autoimporter + IPython\n===================================\n\n  $ py\n      In [1]: re.search(\"[a-z]+\", \"....hello...\").group(0)\n      [PYFLYBY] import re\n      Out[1]: 'hello'\n\n      In [2]: chisqprob(arange(5), 2)\n      [PYFLYBY] from numpy import arange\n      [PYFLYBY] from scipy.stats import chisqprob\n      Out[2]: [ 1.      0.6065  0.3679  0.2231  0.1353]\n\nTo load pyflyby into an existing IPython session as a 1-off:\n\n  $ ipython\n      In [1]: %load_ext pyflyby\n\nTo configure IPython/Jupyter Notebook to load pyflyby automatically:\n\n  $ py pyflyby.install_in_ipython_config_file\n     or\n  $ echo 'c.InteractiveShellApp.extensions.append(\"pyflyby\")' \\\n      \u003e\u003e ~/.ipython/profile_default/ipython_config.py\n\n  $ ipython\n      In [1]: b64decode('aGVsbG8=')\n      [PYFLYBY] from base64 import b64decode\n      Out[1]: 'hello'\n\n\nQuick start: command-line multi-tool\n====================================\n\n  $ py b64decode aGVsbG8=\n  [PYFLYBY] from base64 import b64decode\n  [PYFLYBY] b64decode('aGVsbG8=', altchars=None)\n  'hello'\n\n  $ py log2 sys.maxint\n  [PYFLYBY] from numpy import log2\n  [PYFLYBY] import sys\n  [PYFLYBY] log2(9223372036854775807)\n  63.0\n\n  $ py 'plot(cos(arange(30)))'\n  [PYFLYBY] from numpy import arange\n  [PYFLYBY] from numpy import cos\n  [PYFLYBY] from matplotlib.pyplot import plot\n  [PYFLYBY] plot(cos(arange(30)))\n  \u003cplot\u003e\n\n  $ py 38497631 / 13951446\n  2.7594007818257693\n\n  $ py foo.py\n\nQuick start: tidy-imports\n=========================\n\nTo use tidy-imports, just specify the filename(s) to tidy.\n\nFor example:\n\n$ echo 're.search(\"[a-z]+\", \"....hello...\"), chisqprob(arange(5), 2)' \u003e foo.py\n\n$ tidy-imports foo.py\n    --- /tmp/foo.py\n    +++ /tmp/foo.py\n    @@ -1 +1,9 @@\n    +from __future__ import absolute_import, division, with_statement\n    +\n    +from   numpy                    import arange\n    +from   scipy.stats              import chisqprob\n    +import re\n    +\n     re.search(\"[a-z]+\", \"....hello...\"), chisqprob(arange(5), 2)\n\n    Replace /tmp/foo.py? [y/N]\n\n\nQuick start: import libraries\n=============================\n\nCreate a file named .pyflyby with lines such as::\n    from mypackage.mymodule import MyClass, my_function\n    import anotherpackage.anothermodule\n\nYou can put this file in your home directory or in the same directory as your\n*.py files.\n\n\nDetails: automatic imports\n==========================\n\nAUTOMATIC IMPORTS - never type \"import\" again!\n\nThis module allows your \"known imports\" to work automatically in your IPython\ninteractive session without having to type the 'import' statements (and also\nwithout having to slow down your Python startup with imports you only use\noccasionally).\n\nExample:\n\n  In [1]: re.search(\"[a-z]+\", \"....hello...\").group(0)\n  [PYFLYBY] import re\n  Out[1]: 'hello'\n\n  In [2]: chisqprob(arange(5), 2)\n  [PYFLYBY] from numpy import arange\n  [PYFLYBY] from scipy.stats import chisqprob\n  Out[2]: [ 1.      0.6065  0.3679  0.2231  0.1353]\n\n  In [3]: np.sin(arandom(5))\n  [PYFLYBY] from numpy.random import random as arandom\n  [PYFLYBY] import numpy as np\n  Out[3]: [ 0.0282  0.0603  0.4653  0.8371  0.3347]\n\n  In [4]: isinstance(42, Number)\n  [PYFLYBY] from numbers import Number\n  Out[4]: True\n\n\nIt just works\n-------------\n\nTab completion works, even on modules that are not yet imported.  In the\nfollowing example, notice that numpy is imported when we need to know its\nmembers, and only then:\n\n  $ ipython\n  In [1]: nump\u003cTAB\u003e\n  In [1]: numpy\n  In [1]: numpy.arang\u003cTAB\u003e\n  [PYFLYBY] import numpy\n  In [1]: numpy.arange\n\n\nThe IPython \"?\" magic help (pinfo/pinfo2) automatically imports symbols first\nif necessary:\n\n  $ ipython\n  In [1]: arange?\n  [PYFLYBY] from numpy import arange\n  ... Docstring: arange([start,] stop[, step,], dtype=None) ...\n\nOther IPython magic commands work as well:\n\n  $ ipython\n  In [1]: %timeit np.cos(pi)\n  [PYFLYBY] import numpy as np\n  [PYFLYBY] from numpy import pi\n  100000 loops, best of 3: 2.51 us per loop\n\n  $ echo 'print arange(4)' \u003e foo.py\n  $ ipython\n  In [1]: %run foo.py\n  [PYFLYBY] from numpy import arange\n  [0 1 2 3]\n\n\nImplementation details\n----------------------\n\nThe automatic importing happens at parse time, before code is executed.  The\nnamespace never contains entries for names that are not yet imported.\n\nThis method of importing at parse time contrasts with previous implementations\nof automatic importing that use proxy objects.  Those implementations using\nproxy objects don't work as well, because it is impossible to make proxy\nobjects behave perfectly.  For example, instance(x, T) will return the wrong\nanswer if either x or T is a proxy object.\n\n\nCompatibility\n-------------\n\nTested with:\n  - Python 2.6, 2.7\n  - IPython 0.10, 0.11, 0.12, 0.13, 1.0, 1.2, 2.0, 2.1, 2.2, 2.3, 2.4, 3.0,\n    3.1, 3.2, 4.0.\n  - IPython (text console), IPython Notebook, Spyder\n\n\n\nDetails: import libraries\n=========================\n\nPyflyby uses \"import libraries\" that tell how to import a given symbol.\n\nAn import library file is simply a python source file containing 'import' (or\n'from ... import ...') lines.  These can be generated automatically with\ncollect-imports and collect-exports.\n\nKnown imports\n-------------\n\nFind-imports, tidy-imports, and autoimport consult the database of known\nimports to figure out where to get an import.  For example, if the\nimports database contains::\n    from numpy import arange, NaN\nthen when you type the following in IPython::\n    print arange(10)\nthe autoimporter would automatically execute \"from numpy import arange\".\n\nThe database can be one file or multiple files.  This makes it easy to have\nproject-specific known_imports along with global and per-user defaults.\n\nThe PYFLYBY_PATH environment variable specifies which files to read.\nThis is a colon-separated list of filenames or directory names.  The default\nis:\n  PYFLYBY_PATH=/etc/pyflyby:~/.pyflyby:.../.pyflyby\n\nIf you set\n  PYFLYBY_PATH=/foo1/bar1:/foo2/bar2\nthen this replaces the default.\n\nYou can use a hyphen to include the default in the path.  If you set\n  PYFLYBY_PATH=/foo1/bar1:-:/foo2/bar2\nthen this reads /foo1/bar1, then the default locations, then /foo2/bar2.\n\nIn $PYFLYBY_PATH, \".../.pyflyby\" (with _three_ dots) means that all ancestor\ndirectories are searched for a member named \".pyflyby\".\n\nFor example, suppose the following files exist:\n  /etc/pyflyby/stuff.py\n  /u/quarl/.pyflyby/blah1.py\n  /u/quarl/.pyflyby/more/blah2.py\n  /proj/share/mypythonstuff/.pyflyby\n  /proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py\n  /.pyflyby\n\nFurther, suppose:\n  * /proj is on a separate file system from /.\n  * $HOME=/u/quarl\n\nThen \"tidy-imports /proj/share/mypythonstuff/foo/bar/quux/zot.py\" will by\ndefault use the following:\n  /etc/pyflyby/stuff.py\n  /u/quarl/.pyflyby/blah1.py\n  /u/quarl/.pyflyby/more/blah2.py\n  /proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py\n  /proj/share/mypythonstuff/.pyflyby (a file)\n\nNotes:\n  * /.pyflyby is not included, because traversal stops at file system\n    boundaries, and in this example, /proj is on a different file system than\n    /.\n  * .pyflyby (in $HOME or near the target file) can be a file or a directory.\n    If it is a directory, then it is recursively searched for *.py files.\n  * The order usually doesn't matter, but if there are \"forget\" instructions\n    (see below), then the order matters.  In the default $PYFLYBY_PATH,\n    .../.pyflyby is placed last so that per-directory configuration can\n    override per-user configuration, which can override systemwide\n    configuration.\n\n\nForgetting imports\n------------------\n\nOccasionally you may have reason to tell pyflyby to \"forget\" entries from the\ndatabase of known imports.\n\nYou can put the following in any file reachable from $PYFLYBY_PATH:\n\n  __forget_imports__ = [\"from numpy import NaN\"]\n\nThis is useful if you want to use a set of imports maintained by someone else\nexcept for a few particular imports.\n\nEntries in $PYFLYBY_PATH are processed left-to-right in the order specified,\nso put the files containing these at the end of your $PYFLYBY_PATH.  By\ndefault, tidy-imports and friends process /etc/pyflyby, then ~/.pyflyby,\nthen the per-directory .pyflyby.\n\n\nMandatory imports\n-----------------\n\nWithin a certain project you may have a policy to always include certain\nimports.  For example, maybe you always want to do \"from __future__ import\ndivision\" in all files.\n\nYou can put the following in any file reachable from $PYFLYBY_PATH:\n\n  __mandatory_imports__ = [\"from __future__ import division\"]\n\nTo undo mandatory imports inherited from other .pyflyby files, use\n__forget_imports__.\n\n\nCanonicalize imports\n--------------------\n\nSometimes you want every run of tidy-imports to automatically rename an import\nto a new name.\n\nYou can put the following in any file reachable from $PYFLYBY_PATH:\n\n  __canonical_imports__ = {\"oldmodule.oldfunction\": \"newmodule.newfunction\"}\n\nThis is equivalent to running:\n  tidy-imports --transform=oldmodule.oldfunction=newmodule.newfunction\n\n\nSoapbox: avoid \"star\" imports\n=============================\n\nWhen programming in Python, a good software engineering practice is to avoid\nusing \"from foopackage import *\" in production code.\n\nThis style is a maintenance nightmare:\n\n  * It becomes difficult to figure out where various symbols\n    (functions/classes/etc) come from.\n\n  * It's hard to tell what gets shadowed by what.\n\n  * When the package changes in trivial ways, your code will be affected.\n    Consider the following example: Suppose foopackage.py contains \"import\n    sys\", and myprogram.py contains \"from foopackage import *; if\n    some_condition: sys.exit(0)\".  If foopackage.py changes so that \"import\n    sys\" is removed, myprogram.py is now broken because it's missing \"import\n    sys\".\n\nTo fix such code, you can run `tidy-imports --replace-star-imports' to\nautomatically replace star imports with the specific needed imports.\n\n\nEmacs support\n=============\n\n* To get a `M-x tidy-imports' command in GNU Emacs, add to your ~/.emacs:\n\n    (load \"/path/to/pyflyby/lib/emacs/pyflyby.el\")\n\n\n- Pyflyby.el doesn't yet work with XEmacs; patches welcome.\n\n\nAuthorship\n==========\n\nPyflyby is written by Karl Chen \u003cquarl@8166.clguba.z.quarl.org\u003e\n\n\nLicense\n=======\n\nPyflyby is released under a very permissive license, the MIT/X11 license; see\nLICENSE.txt.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquansight%2Fpyflyby-old","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquansight%2Fpyflyby-old","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquansight%2Fpyflyby-old/lists"}