disabling pkg_resources warning on console scripts

10 views
Skip to first unread message

Jonathan Vanasco

unread,
Jul 11, 2025, 1:10:11 PMJul 11
to pylons-discuss
This is an annoying issue related to pkg_resources being deprecated (https://github.com/Pylons/pyramid/issues/3731); I am wondering if anyone has figured out a solution for it.

The /scripts with registered entrypoints have executables created that look like this:

    # -*- coding: utf-8 -*-
    import re
    import sys
    from {{MYAPP}}.scripts.{{SCRIPTNAME}} import main
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
        sys.exit(main())

When these scripts are executed, the Python interpreter will first import {{MYAPP}}which will import Pyramid, which then imports pkg_resources, which then emits the warning.

I can't figure out a way to suppress this warning during console script execution, aside from disabling it in every context.  I am fine with this on the webapp, but this creates noise - and problems - for console scripts that are registered into cron.  

Disabling warnings in the script does not work, because the /scripts/{{script}} is imported *after* the topline namespace is imported.  

I don't think there is anything I can do here, but wondered if anyone else has figured this out.  

The only approach I can think of, is disabling this warning in all contexts by default, then letting me re-enable it via an environment variable and having a unit test do coverage for it.  I'd rather not do that, but it may be the only way.





Michael Merickel

unread,
Jul 11, 2025, 2:01:11 PMJul 11
to pylons-...@googlegroups.com, pylons-discuss
Some options:
1. Don’t have pyramid imported when you import your package. Wait until main() is called. 
2. Set the PYTHONWARNINGS env var in your env prior to the script running. 
3. In your package define an __init__.py that configures warnings prior to importing anything else. 

Not saying they’re great options but trying to help. 

- Michael

On Jul 11, 2025, at 11:10, Jonathan Vanasco <jvan...@gmail.com> wrote:

This is an annoying issue related to pkg_resources being deprecated (https://github.com/Pylons/pyramid/issues/3731); I am wondering if anyone has figured out a solution for it.
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pylons-discuss/1ad7075b-94dd-4eaf-8def-91779bc156den%40googlegroups.com.

Jonathan Vanasco

unread,
Jul 11, 2025, 2:23:23 PMJul 11
to pylons-discuss
Thanks!

#1 is a great idea.  I hadn't thought of that.
#2 was previously rejected.
#3 was basically what I was trying to avoid, because (in this usage) i'd have to turn everything off by default and then turn things on for CI/testing contexts

Jonathan Vanasco

unread,
Aug 21, 2025, 3:43:24 PMAug 21
to pylons-discuss
I just wanted to circle back on this for the benefit of others:

I ultimately went with Option #3.  The first line of `__init__.py` imports a file that disables the pkg_resources warning (and potentially others) by default.  This is the most manageable, and has the most minimal impact on `flake8-import-order` linting of all the methods I tried. 

Importing Pyramid within main() ended up having too many issues due to how certain pyramid hooks are used throughout the application and how the various scripts import Pyramid.

Setting PYTHONWARNINGS in the environment, or invoking it as part of the commandline, was too onerous as the packages I am concerned with expose many scripts for commandline use. 

Reply all
Reply to author
Forward
0 new messages