Skip to content

Create consent mechanism that disables reporting when Python module is imported as library #92

@zomglings

Description

@zomglings

Some options. We should implement at least one of the following options, but we do not have to implement them all.

Using inspect

Here is an example of how to detect this automatically:

def is_in_library():
    stack = inspect.stack()[:-1]
    if all("site-packages" not in finfo.filename for finfo in stack):
        print("(debug) Not in library!")
        return False
    return True  # don’t send statistics!

Taken from Ray telemetry proposal: https://docs.google.com/document/d/1gZut2v52xDd3bNBaw2PxilUBWQRixIQcOJPx16FIoAw/edit#

Now, I don't like using inspect.stack (see this Stack Overflow post and this Python mailing list thread for some reasons why).

However, we can implement this and leave it up to the creator of the consent mechanism whether or not they should use it.

Stateful consent switch - off when used as library, on when used as standalone tool

Create a stateful consent mechanism with a boolean switch. By default, the switch will be False and the mechanism will not grant consent. This way, if a tool which integrates with Humbug can be used as a library, any dependents of that library will not send reporting.

However, if the tool can also be used from the command line, the CLI can switch the state of the mechanism to True to enable reporting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions