Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zomglings opened this issue Oct 11, 2021 · 0 comments
Labels
enhancement New feature or request python

Comments

@zomglings
Copy link
Member

zomglings commented Oct 11, 2021

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.

@zomglings zomglings added enhancement New feature or request python labels Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python
Projects
None yet
Development

No branches or pull requests

1 participant