model

Module, Package data model.

class picage.model.BaseModuleOrPackage(name, path=None, parent=None, is_single_file=None)[source]

Base Class to represent a module or package.

property fullname

Example: for package pip.commands.install, it’s pip.commands.install.

property shortname

Example: for package pip.commands.install, it’s install.

class picage.model.Module(name, path=None, parent=None, is_single_file=None)[source]

Represent a module object in Python. Typically it’s a *.py file.

Parameters
  • name – module name, e.g.: “pip.commands.install”.

  • path – module file absolute path.

  • parent – default None, parent package name, list of package

  • is_single_file – if it is a single file package/module.

class picage.model.Package(name, path=None, parent=None, is_single_file=None)[source]

Represent a package object in Python. It is a directory having a __init__.py file.

Parameters
  • name – dot seperated full name, e.g.: “pip.commands.install”.

  • path – package directory/file absolute path.

  • parent (parent) – parent package, instance of Package.

中文文档

是Python中Package概念的抽象类。指包含有 __init__.py 文件的文件夹。 Package必须可以被import命令所导入, 换言之, 就是已经被成功安装了。

Package的属性的解释:

  • name: 包名称

  • path: 包目录所在的路径

  • fullname: 包的全名, 带母包

  • shortname: 包的短名称, 也就是最后一个点之后的部分。

  • parent: 母包的实例。

  • is_single_file: 是否是单文件的包。

  • sub_packages: 有序字典, {子包的名称: Package对象}

  • sub_modules: 有序字典, {子模块的名称: Module对象}

walk(pkg_only=True)[source]

A generator that walking through all sub packages and sub modules.

Parameters

pkg_only (bool) – if True, it only yields package (folder with __init__.py) if False, it also yields module, but they don’t have sub_packages and sub_modules

中文文档

遍历一个包的所有子包以及子模块.

  1. current package object (包对象)

  2. current package’s parent (当前包对象的母包)

  3. list of sub packages (所有子包)

  4. list of sub modules (所有模块)

pprint()[source]

Pretty print the package structure.