Internal API

pypicontents

pypicontents is just black magic.

PyPIContents is a package that studies the codebase of your project in search for internal and external imports. It then discards the imports that are satisfied with internal code or with the standard library and finally searches the PyPIContents index to list which packages satisfy your imports.

pypicontents.cli module

pypicontents.cli is a module for handling the command line interface.

This module handles the commands for using PyPIContents. It also parses parameters, show help, version and controls the logging level.

pypicontents.cli.commandline(argv=None)[source]

Configure ArgumentParser to accept custom arguments and commands.

Parameters:argv

a list of commandline arguments like sys.argv. For example:

['-v', '--loglevel', 'INFO']
Returns:a Namespace object.

New in version 0.1.0.

pypicontents.cli.main(argv=None)[source]

Handle arguments and commands.

Parameters:argv

a list of commandline arguments like sys.argv. For example:

['-v', '--loglevel', 'INFO']
Returns:an exit status.

New in version 0.1.0.

pypicontents.wrapper module

pypicontents.api package

pypicontents.api is a package containing all the cli commands.

This package contains each command of PyPIContents organized in modules.

pypicontents.api.pypi module

pypicontents.api.report is a module implementing the report command.

This module contains the logic to examine your source code, extract internal and external imports, and finally determine which external PyPI packages you need to install in order to satisfy dependencies.

pypicontents.api.stdlib module

pypicontents.api.stdlib.fetch_inventory(uri, inv)[source]

Fetch, parse and return an intersphinx inventory file.

pypicontents.api.errors module

pypicontents.api.stats module

pypicontents.api.merge module

pypicontents.core package

pypicontents.core contains the core functions of the application.

This package contains functions for managing the download of files, exploring and obtaining imported modules, logging and other minor file operations.

pypicontents.core.logger module

pipsalabim.core.logger is the global application logging module.

All modules use the same global logging object. No messages will be emitted until the logger is started.

class pypicontents.core.logger.ControlableLogger(name=None)[source]

This class represents a logger object that can be started and stopped.

It has a start method which allows you to specify a logging level. The stop method halts output.

__init__(name=None)[source]

Initialize this ControlableLogger.

The name defaults to the application name. Loggers with the same name refer to the same underlying object. Names are hierarchical, e.g. ‘parent.child’ defines a logger that is a descendant of ‘parent’.

Parameters:name – a string containing the logger name.
Returns:a ControlableLogger instance.

New in version 0.1.0.

disabled = None

Attribute disabled (boolean): Stores the current status of the logger.

formatstring = None

Attribute formatstring (string): Stores the string that will be used to format the logger output.

loglevel(level='INFO')[source]

Set the log level for this logger.

Messages less than the given priority level will be ignored. The default level is ‘INFO’, which conforms to the *nix convention that a successful run should produce no diagnostic output. Available levels and their suggested meanings:

  • NOTSET: all messages are processed.
  • DEBUG: output useful for developers.
  • INFO: trace normal program flow, especially external
    interactions.
  • WARNING: an abnormal condition was detected that might need
    attention.
  • ERROR: an error was detected but execution continued.
  • CRITICAL: an error was detected and execution was halted.
Parameters:level – a string containing the desired logging level.

New in version 0.1.0.

start(filename=None)[source]

Start logging with this logger.

Until the logger is started, no messages will be emitted. This applies to all loggers with the same name and any child loggers.

New in version 0.1.0.

stop()[source]

Stop logging with this logger.

Remove available handlers and set disabled attribute to True.

New in version 0.1.0.

pypicontents.core.patches module

pypicontents.core.utils module

pypicontents.core.utils is a utility module.

This module contains several utilities to process information coming from the other modules.

pypicontents.core.utils.human2bytes(s)[source]

Attempts to guess the string format based on default symbols set and return the corresponding bytes as an integer. When unable to recognize the format ValueError is raised.

>>> human2bytes('0 B')
0
>>> human2bytes('1 K')
1024
>>> human2bytes('1 M')
1048576
>>> human2bytes('1 Gi')
1073741824
>>> human2bytes('1 tera')
1099511627776
>>> human2bytes('0.5kilo')
512
>>> human2bytes('0.1  byte')
0
>>> human2bytes('1 k')  # k is an alias for K
1024
>>> human2bytes('12 foo')
Traceback (most recent call last):
    ...
ValueError: can't interpret '12 foo'