unbox


Nameunbox JSON
Version 0.1.10 PyPI version JSON
download
home_pagehttps://github.com/i2mint/unbox
SummaryFinding imports in code
upload_time2023-09-20 07:33:03
maintainer
docs_urlNone
authorOtoSense
requires_python
licenseapache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # unbox
Finding imports in code

To install:	```pip install unbox```

# What's here

Lots of little goodies to help you analyze the imports of your, or others' code. 

## Getting a list of missing dependencies

```python
>>> from unbox import print_missing_names
>>> import some_module  # doctest: +SKIP
>>> print_missing_names(some_module)  # doctest: +SKIP
SoundFile
i2
librosa
pyttsx3
slink
```

## Seeing what the dependencies of a package are, before installing it

Simply get a list of dependencies for a package from PyPI.

```python
>>> import unbox
>>> unbox.dependencies_from_pypi('pandas')
['numpy', 'numpy', 'python-dateutil', 'pytz', 'tzdata']
```

But you have control over the requirements that are returned, 
and how they are returned:

```python
>>> it = unbox.dependencies_from_pypi(
...     'pandas',
...     requirement_filter=lambda x: True,  # don't filter any requirements
...     requirement_trans=lambda x: x,  # as is
...     egress = lambda x: x  # just get the iterator as is
... )
>>> next(it)
'numpy>=1.22.4; python_version < "3.11"'
>>> list(it)[-1]
'zstandard>=0.17.0; extra == "all"'
```


## A dict-like interface

The base of `unbox` is just the `dol` interface to `findimports`, which then allows us to offer a bunch of functionalities easily. 

Say you wanted to know what dol was made of. 
The dol way of doing this is to make a `Mapping` (i.e. a key-value dict-like interface), 
and then do what you do with dicts...

```python
>>> import dol
>>> import unbox
>>> s = unbox.ModuleNamesImportedByModule(dol)  # make a store containing the modules of the `dol` package
>>> # Now wee how you can do things you do with dicts
>>> len(s)
15
>>> list(s)
['dol.__init__',
 'dol.appendable',
 'dol.base',
 'dol.caching',
 'dol.core',
 'dol.dig',
 'dol.errors',
 'dol.filesys',
 'dol.mixins',
 'dol.naming',
 'dol.paths',
 'dol.signatures',
 'dol.sources',
 'dol.trans',
 'dol.util']
>>> 'dol.appendable' in s
>>> # The values of `s` are sets of modules imported by a module.
>>> s['dol.appendable']  # what does dol.appendable import?
{'collections.abc', 'dol.trans', 'time', 'types', 'typing'}
```

Check out `ModulesImportedByModule` also, which gives you a `Mapping` with module objects 
as keys, and `findimports.ImportInfo` instances as values.

## imports_for

As an example of what you can do with this set up, have a look at `imports_for`. 
Or don't have a look; just use it, since it's quite useful.

```python
from unbox import imports_for 
import wave
assert imports_for(wave) == {'warnings', 'builtins', 'sys', 'audioop', 'chunk', 'struct', 'collections'}
```

At it's base, imports_for gives you a generator of import names. 
With the `post` argument (defaulted to `set`) you can specify a callable that can produce the output 
you want; whether you want to filter the items, count them, order them, etc.

We curried a few common ones for you, for your convenience:

```python
from unbox import imports_for
imports_for.counter  # imported names and their counts
imports_for.most_common  # imported names and their counts, ordered by most common
imports_for.first_level  # set for imported first level names (e.g. 'os' instead of 'os.path.etc.)
imports_for.first_level_count  # count of imported first level names (e.g. 'os' instead of 'os.path.etc.)
imports_for.third_party  # imported (first level) names that are not builtin names (most probably third party packages)"
```

## Collections of python names

Check out the contents of these collections:

```python
from unbox import (
    builtin_module_names,
    scanned_standard_lib_names,
    all_accessible_modules,
    all_accessible_pkg_names,
    all_accessible_non_pkg_module_names,
    builtin_obj_names,
    python_names
)
```

For example, `builtin_module_names` will be a set of names that are 
[documented](`https://docs.python.org/3.8/library/`) **and** importable on your system.

The `scanned_standard_lib_names` set is similar, but the names are obtained by scanning 
the local standard library file names -- so include things like easter eggs (`this`, `antigravity`).

`all_accessible_modules` will be the list of all modules accessible in your python path.

And so on...
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/i2mint/unbox",
    "name": "unbox",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "OtoSense",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/fc/08/9ab76d61d5c0dab6712070f423a21866a4658bdd928553908fcd81b5d405/unbox-0.1.10.tar.gz",
    "platform": "any",
    "description": "# unbox\nFinding imports in code\n\nTo install:\t```pip install unbox```\n\n# What's here\n\nLots of little goodies to help you analyze the imports of your, or others' code. \n\n## Getting a list of missing dependencies\n\n```python\n>>> from unbox import print_missing_names\n>>> import some_module  # doctest: +SKIP\n>>> print_missing_names(some_module)  # doctest: +SKIP\nSoundFile\ni2\nlibrosa\npyttsx3\nslink\n```\n\n## Seeing what the dependencies of a package are, before installing it\n\nSimply get a list of dependencies for a package from PyPI.\n\n```python\n>>> import unbox\n>>> unbox.dependencies_from_pypi('pandas')\n['numpy', 'numpy', 'python-dateutil', 'pytz', 'tzdata']\n```\n\nBut you have control over the requirements that are returned, \nand how they are returned:\n\n```python\n>>> it = unbox.dependencies_from_pypi(\n...     'pandas',\n...     requirement_filter=lambda x: True,  # don't filter any requirements\n...     requirement_trans=lambda x: x,  # as is\n...     egress = lambda x: x  # just get the iterator as is\n... )\n>>> next(it)\n'numpy>=1.22.4; python_version < \"3.11\"'\n>>> list(it)[-1]\n'zstandard>=0.17.0; extra == \"all\"'\n```\n\n\n## A dict-like interface\n\nThe base of `unbox` is just the `dol` interface to `findimports`, which then allows us to offer a bunch of functionalities easily. \n\nSay you wanted to know what dol was made of. \nThe dol way of doing this is to make a `Mapping` (i.e. a key-value dict-like interface), \nand then do what you do with dicts...\n\n```python\n>>> import dol\n>>> import unbox\n>>> s = unbox.ModuleNamesImportedByModule(dol)  # make a store containing the modules of the `dol` package\n>>> # Now wee how you can do things you do with dicts\n>>> len(s)\n15\n>>> list(s)\n['dol.__init__',\n 'dol.appendable',\n 'dol.base',\n 'dol.caching',\n 'dol.core',\n 'dol.dig',\n 'dol.errors',\n 'dol.filesys',\n 'dol.mixins',\n 'dol.naming',\n 'dol.paths',\n 'dol.signatures',\n 'dol.sources',\n 'dol.trans',\n 'dol.util']\n>>> 'dol.appendable' in s\n>>> # The values of `s` are sets of modules imported by a module.\n>>> s['dol.appendable']  # what does dol.appendable import?\n{'collections.abc', 'dol.trans', 'time', 'types', 'typing'}\n```\n\nCheck out `ModulesImportedByModule` also, which gives you a `Mapping` with module objects \nas keys, and `findimports.ImportInfo` instances as values.\n\n## imports_for\n\nAs an example of what you can do with this set up, have a look at `imports_for`. \nOr don't have a look; just use it, since it's quite useful.\n\n```python\nfrom unbox import imports_for \nimport wave\nassert imports_for(wave) == {'warnings', 'builtins', 'sys', 'audioop', 'chunk', 'struct', 'collections'}\n```\n\nAt it's base, imports_for gives you a generator of import names. \nWith the `post` argument (defaulted to `set`) you can specify a callable that can produce the output \nyou want; whether you want to filter the items, count them, order them, etc.\n\nWe curried a few common ones for you, for your convenience:\n\n```python\nfrom unbox import imports_for\nimports_for.counter  # imported names and their counts\nimports_for.most_common  # imported names and their counts, ordered by most common\nimports_for.first_level  # set for imported first level names (e.g. 'os' instead of 'os.path.etc.)\nimports_for.first_level_count  # count of imported first level names (e.g. 'os' instead of 'os.path.etc.)\nimports_for.third_party  # imported (first level) names that are not builtin names (most probably third party packages)\"\n```\n\n## Collections of python names\n\nCheck out the contents of these collections:\n\n```python\nfrom unbox import (\n    builtin_module_names,\n    scanned_standard_lib_names,\n    all_accessible_modules,\n    all_accessible_pkg_names,\n    all_accessible_non_pkg_module_names,\n    builtin_obj_names,\n    python_names\n)\n```\n\nFor example, `builtin_module_names` will be a set of names that are \n[documented](`https://docs.python.org/3.8/library/`) **and** importable on your system.\n\nThe `scanned_standard_lib_names` set is similar, but the names are obtained by scanning \nthe local standard library file names -- so include things like easter eggs (`this`, `antigravity`).\n\n`all_accessible_modules` will be the list of all modules accessible in your python path.\n\nAnd so on...",
    "bugtrack_url": null,
    "license": "apache-2.0",
    "summary": "Finding imports in code",
    "version": "0.1.10",
    "project_urls": {
        "Homepage": "https://github.com/i2mint/unbox"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fc089ab76d61d5c0dab6712070f423a21866a4658bdd928553908fcd81b5d405",
                "md5": "13bc3352b16ad6819cf23aed824a4b4d",
                "sha256": "9427b03b89c0e6193079a39b2254c267675a5c2eb7634cbbabe3e06b82499033"
            },
            "downloads": -1,
            "filename": "unbox-0.1.10.tar.gz",
            "has_sig": false,
            "md5_digest": "13bc3352b16ad6819cf23aed824a4b4d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21395,
            "upload_time": "2023-09-20T07:33:03",
            "upload_time_iso_8601": "2023-09-20T07:33:03.689604Z",
            "url": "https://files.pythonhosted.org/packages/fc/08/9ab76d61d5c0dab6712070f423a21866a4658bdd928553908fcd81b5d405/unbox-0.1.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-20 07:33:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "i2mint",
    "github_project": "unbox",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "unbox"
}
        
Elapsed time: 0.30020s