dsm
dependenpy dsm module.
This is the core module of dependenpy. It contains the following classes:
DSM
: to create a DSM-capable object for a list of packages,Package
: which represents a Python package,Module
: which represents a Python module,Dependency
: which represents a dependency between two modules.
DSM
¤
Bases: RootNode
, NodeMixin
, PrintMixin
DSM-capable class.
Technically speaking, a DSM instance is not a real DSM but more a tree representing the Python packages structure. However, it has the necessary methods to build a real DSM in the form of a square matrix, a dictionary or a tree-map.
Source code in dependenpy/dsm.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
__init__(*packages, build_tree=True, build_dependencies=True, enforce_init=True)
¤
Initialization method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*packages |
str
|
list of packages to search for. |
()
|
build_tree |
bool
|
auto-build the tree or not. |
True
|
build_dependencies |
bool
|
auto-build the dependencies or not. |
True
|
enforce_init |
bool
|
if True, only treat directories if they contain an |
True
|
Source code in dependenpy/dsm.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
build_tree()
¤
Build the Python packages tree.
Source code in dependenpy/dsm.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
isdsm()
property
¤
Inherited from NodeMixin. Always True.
Returns:
Type | Description |
---|---|
bool
|
Whether this object is a DSM. |
Source code in dependenpy/dsm.py
80 81 82 83 84 85 86 87 88 |
|
Dependency
¤
Bases: object
Dependency class.
Represent a dependency from a module to another.
Source code in dependenpy/dsm.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
__init__(source, lineno, target, what=None)
¤
Initialization method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
Module
|
source Module. |
required |
lineno |
int
|
number of line at which import statement occurs. |
required |
target |
str/Module/Package
|
the target node. |
required |
what |
str
|
what is imported (optional). |
None
|
Source code in dependenpy/dsm.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
external()
property
¤
Property to tell if the dependency's target is a valid node.
Returns:
Type | Description |
---|---|
bool
|
Whether the dependency's target is a valid node. |
Source code in dependenpy/dsm.py
446 447 448 449 450 451 452 453 454 |
|
Module
¤
Bases: LeafNode
, NodeMixin
, PrintMixin
Module class.
This class represents a Python module (a Python file).
Source code in dependenpy/dsm.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
__contains__(item)
¤
Whether given item is contained inside this module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
Package/Module
|
a package or module. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if self is item or item is self's package and
self if an |
Source code in dependenpy/dsm.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
__init__(name, path, dsm=None, package=None)
¤
Initialization method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the module. |
required |
path |
str
|
path to the module. |
required |
dsm |
DSM
|
parent DSM. |
None
|
package |
Package
|
parent Package. |
None
|
Source code in dependenpy/dsm.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
as_dict(absolute=False)
¤
Return the dependencies as a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
absolute |
bool
|
Whether to use the absolute name. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
dictionary of dependencies. |
Source code in dependenpy/dsm.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
build_dependencies()
¤
Build the dependencies for this module.
Parse the code with ast, find all the import statements, convert them into Dependency objects.
Source code in dependenpy/dsm.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
cardinal(to)
¤
Return the number of dependencies of this module to the given node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to |
Package/Module
|
the target node. |
required |
Returns:
Type | Description |
---|---|
int
|
Number of dependencies. |
Source code in dependenpy/dsm.py
406 407 408 409 410 411 412 413 414 415 416 |
|
get_imports(ast_body)
¤
Return all the import statements given an AST body (AST nodes).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ast_body |
compiled code's body
|
the body to filter. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
The import statements. |
Source code in dependenpy/dsm.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
ismodule()
property
¤
Inherited from NodeMixin. Always True.
Returns:
Type | Description |
---|---|
bool
|
Whether this object is a module. |
Source code in dependenpy/dsm.py
282 283 284 285 286 287 288 289 290 |
|
parse_code()
¤
Read the source code and return all the import statements.
Returns:
Type | Description |
---|---|
list[dict]
|
list of dict: the import statements. |
Source code in dependenpy/dsm.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
Package
¤
Bases: RootNode
, LeafNode
, NodeMixin
, PrintMixin
Package class.
This class represent Python packages as nodes in a tree.
Source code in dependenpy/dsm.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
__init__(name, path, dsm=None, package=None, limit_to=None, build_tree=True, build_dependencies=True, enforce_init=True)
¤
Initialization method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the package. |
required |
path |
str
|
path to the package. |
required |
dsm |
DSM
|
parent DSM. |
None
|
package |
'Package'
|
parent package. |
None
|
limit_to |
List[str]
|
list of string to limit the recursive tree-building to what is specified. |
None
|
build_tree |
bool
|
auto-build the tree or not. |
True
|
build_dependencies |
bool
|
auto-build the dependencies or not. |
True
|
enforce_init |
bool
|
if True, only treat directories if they contain an |
True
|
Source code in dependenpy/dsm.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
build_tree()
¤
Build the tree for this package.
Source code in dependenpy/dsm.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
cardinal(to)
¤
Return the number of dependencies of this package to the given node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to |
Package/Module
|
target node. |
required |
Returns:
Type | Description |
---|---|
int
|
Number of dependencies. |
Source code in dependenpy/dsm.py
226 227 228 229 230 231 232 233 234 235 236 |
|
ispackage()
property
¤
Inherited from NodeMixin. Always True.
Returns:
Type | Description |
---|---|
bool
|
Whether this object is a package. |
Source code in dependenpy/dsm.py
153 154 155 156 157 158 159 160 161 |
|
isroot()
property
¤
Property to tell if this node is a root node.
Returns:
Type | Description |
---|---|
bool
|
This package has no parent. |
Source code in dependenpy/dsm.py
173 174 175 176 177 178 179 180 181 |
|
issubpackage()
property
¤
Property to tell if this node is a sub-package.
Returns:
Type | Description |
---|---|
bool
|
This package has a parent. |
Source code in dependenpy/dsm.py
163 164 165 166 167 168 169 170 171 |
|
split_limits_heads()
¤
Return first parts of dot-separated strings, and rest of strings.
Returns:
Type | Description |
---|---|
tuple[list[str], list[str]]
|
The heads and rest of the strings. |
Source code in dependenpy/dsm.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|