Skip to main content

python-aspectlib

Travis-CI Build Status
AppVeyor Build Status

Coverage Status
PYPI Package
PYPI Package

aspectlib is an aspect-oriented programming, monkey-patch and decorators library. It is useful when changing behavior in existing code is desired.

Documentation

Docs are hosted at readthedocs.org: python-aspectlib docs.

Implementation status

Weaving functions, methods, instances and classes is completed.

Pending:

  • “Concerns” (see docs/todo.rst)

If aspectlib.weave doesn’t work for your scenario please report a bug !

Requirements

OS:

Any

Runtime:

Python 2.6, 2.7, 3.3, 3.4 or PyPy

Python 3.2, 3.1 and 3.0 are NOT supported (some objects are too crippled).

Similar projects

Changelog

Version 1.2.1

  • Don’t raise exceptions from Replay.__exit__ if there would be an error (makes original cause hard to debug).

Version 1.2.0

  • Fix weaving methods that were defined in some baseclass (and not on the target class).

  • Fix wrong qualname beeing used in the Story/Replay recording. Now used the alias given to the weaver instead of whatever is the realname on the current platform.

Version 1.1.1

  • Use ASPECTLIB_DEBUG for every logger in aspectlib.

Version 1.1.0

  • Add a bind option to aspectlib.Aspect so you can access the cutpoint from the advisor.

  • Replaced automatic importing in aspectlib.test.Replay with extraction of context variables (locals and globals from the calling aspectlib.test.Story). Works better than the previous inference of module from AST of the result.

  • All the methods on the replay are now properties: aspectlib.test.Story.diff, aspectlib.test.Story.unexpected and aspectlib.test.Story.missing.

  • Added aspectlib.test.Story.actual and aspectlib.test.Story.expected.

  • Added an ASPECTLIB_DEBUG environment variable option to switch on debug logging in aspectlib’s internals.

Version 1.0.0

  • Reworked the internals aspectlib.test.Story to keep call ordering, to allow dependencies and improved the serialization (used in the diffs and the missing/unexpected lists).

Version 0.9.0

  • Changed aspectlib.test.record:

    • Renamed history option to calls.

    • Renamed call option to iscalled.

    • Added callback option.

    • Added extended option.

  • Changed aspectlib.weave:

    • Allow weaving everything in a module.

    • Allow weaving instances of new-style classes.

  • Added aspectlib.test.Story class for capture-replay and stub/mock testing.

Version 0.8.1

  • Use simpler import for the py3support.

Version 0.8.0

  • Change aspectlib.debug.log to use aspectlib.Aspect and work as expected with coroutines or generators.

  • Fixed aspectlib.debug.log to work on Python 3.4.

  • Remove the undocumented aspectlib.Yield advice. It was only usable when decorating generators.

Version 0.7.0

  • Add support for decorating generators and coroutines in aspectlib.Aspect.

  • Made aspectlib raise better exceptions.

Version 0.6.1

  • Fix checks inside aspectlib.debug.log that would inadvertently call __bool__/__nonzero.

Version 0.6.0

  • Don’t include __getattribute__ in ALL_METHODS - it’s too dangerous dangerous dangerous dangerous dangerous dangerous … ;)

  • Do a more reliable check for old-style classes in debug.log

  • When weaving a class don’t weave attributes that are callable but are not actually routines (functions, methods etc)

Version 0.5.0

  • Changed aspectlib.debug.log:

    • Renamed arguments to call_args.

    • Renamed arguments_repr to call_args_repr.

    • Added call option.

    • Fixed issue with logging from old-style methods (object name was a generic “instance”).

  • Fixed issues with weaving some types of builtin methods.

  • Allow to apply multiple aspects at the same time.

  • Validate string targets before weaving. aspectlib.weave('mod.invalid name', aspect) now gives a clear error (invalid name is not a valid identifier)

  • Various documentation improvements and examples.

Version 0.4.1

  • Remove junk from 0.4.0’s source distribution.

Version 0.4.0

  • Changed aspectlib.weave:

    • Replaced only_methods, skip_methods, skip_magicmethods options with methods.

    • Renamed on_init option to lazy.

    • Added aliases option.

    • Replaced skip_subclasses option with subclasses.

  • Fixed weaving methods from a string target.

Metadata

Release files for aspectlib 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aspectlib 1.2.1
File Size Uploaded
aspectlib-1.2.1.tar.gz 149.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aspectlib 1.2.1
File Interpreter ABI Platform
aspectlib-1.2.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 178.5 kB

Release files / aspectlib-1.2.1.tar.gz

Download URL aspectlib-1.2.1.tar.gz
Size 149.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e8e07e9429a84e3aa917c38e73e8ca5550f4f90a0506f96850195da8c8551525
BLAKE2b-256 checksum
How to use checksums
fa64a756f6d72b91ecd02a7795afe7ab85fbcbaf6572934ad44b0e504e10b608
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aspectlib-1.2.1-py2.py3-none-any.whl

Download URL aspectlib-1.2.1-py2.py3-none-any.whl
Size 28.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
85be856df4f0572eb0d4e1d8cacdc3b010a4a7ff9e3be34c534ea813bd813fae
BLAKE2b-256 checksum
How to use checksums
a7b2f05e53c2ba0500a772e88be9c58f552960e0e8a82d5c5297fc8437a2cd4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.0.0

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.2

2 release files

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0

1 release file

0.9.0

2 release files

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page