Re: Using loguru in a library

2023-05-02 Thread Roy Hann
Dieter Maurer wrote:

> Roy Hann wrote at 2023-4-30 15:40 -:
>>Is there anyone using loguru (loguru 0.5.3 in my case) successfully in a
>>library?
>> ...
>>  import mylib
>>  logger.enable('mylib')
>>
>>expecting that it would report any log messages above level DEBUG, just
>>as it does when I don't disable logging.
>
> Have you configured the logging system?
>
> Note that `logging.config.fileConfig` may do strange things
> regarding disabling (due to its default parameter
> `disable_existing_loggers=True`).
> I had several cases of missing log entries because `fileConfig`
> had disabled already existing loggers.

Thank you for the response Dieter. 

I am using the loguru package, not the logging package. 

I think my next step is going to have be creating a minimal test
case to post on stackoverflow.  :-P

Roy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Editing PEP-8, in particular "expected 2 blanks, found 1

2023-05-02 Thread Thomas Passin

On 5/2/2023 4:39 PM, Kevin M. Wilson via Python-list wrote:

Folks, help please! What the @#$! are these doing popping up. Code styles are 
personal, and not subject to debate.Where can I edit these out of my IDE?
Kevin
"When you pass through the waters, I will be with you: and when you pass through the 
rivers, they will not sweep over you. When you walk through the fire, you will not be 
burned: the flames will not set you ablaze."
Isaiah 43:2

|  | Virus-free.www.avg.com |



It might help if you gave a hint about what IDE is involved...

--
https://mail.python.org/mailman/listinfo/python-list


Re: Editing PEP-8, in particular "expected 2 blanks, found 1

2023-05-02 Thread 2QdxY4RzWzUUiLuE
On 2023-05-02 at 20:39:35 +,
"Kevin M. Wilson via Python-list"  wrote:

> [...] Where can I edit these out of my IDE?

I doubt anyone will know unless you at least tell us which IDE you're
using.
-- 
https://mail.python.org/mailman/listinfo/python-list


Editing PEP-8, in particular "expected 2 blanks, found 1

2023-05-02 Thread Kevin M. Wilson via Python-list
Folks, help please! What the @#$! are these doing popping up. Code styles are 
personal, and not subject to debate.Where can I edit these out of my IDE?
Kevin
"When you pass through the waters, I will be with you: and when you pass 
through the rivers, they will not sweep over you. When you walk through the 
fire, you will not be burned: the flames will not set you ablaze."      
Isaiah 43:2

|  | Virus-free.www.avg.com |

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using loguru in a library

2023-05-02 Thread Dieter Maurer
Roy Hann wrote at 2023-4-30 15:40 -:
>Is there anyone using loguru (loguru 0.5.3 in my case) successfully in a
>library?
> ...
>  import mylib
>  logger.enable('mylib')
>
>expecting that it would report any log messages above level DEBUG, just
>as it does when I don't disable logging.

Have you configured the logging system?

Note that `logging.config.fileConfig` may do strange things
regarding disabling (due to its default parameter
`disable_existing_loggers=True`).
I had several cases of missing log entries because `fileConfig`
had disabled already existing loggers.
-- 
https://mail.python.org/mailman/listinfo/python-list


Note when migrating '#' formats for PyArgs_ParseTuple

2023-05-02 Thread aapost

Just in case anyone else runs in to it.

If you have code such as:

char* a;
char* b;
char* d;
int size;

if (!PyArg_ParseTuple(args, "sss#:f", , , , ))
return NULL;

and it tells you to:

#define PY_SSIZE_T_CLEAN
#include "Python.h"

Be sure to change int size; to:

Py_ssize_t size;

If you forget, your code will compile fine and still work perfectly fine 
on all py2 and py3 i386 variants, but will break 64bit variants in very 
non-obvious ways.


In the above example the mismatched pointer type of size messes up the 
seemingly unrelated pointer a


padr a 0x7f1f
padr b 0x7f1fa656b960
padr d 0x7f1fa65579a0

So while accessing the s# argument works fine, you get a segfault when 
you access a


I spent quite a while chasing my tail researching variadics, picking 
apart the code trying to understand how and where 'a' gets stomped on 
before I realized the size type mismatch.


--
On that note, I will say that the removal of distutils/setup.py-ability 
from 3.12 without a similarly simple out of the box replacement is 
unfortunate. (if setup.py usage had design flaws that lead to 
deprecation fine, but python should have some form of stand alone 
equivalency included out of the box by default)


For researching issues like the above, and for people who want to use 
python for off-internet projects, it is nice to be able to spin up a 
virtual machine from any said era, and do a

./configure
make
./python setup.py install --user

As things diverge in the future, things start to break, and you don't 
always have all the pieces to put it back together, and pip kind of 
sucks and is not simple when it doesn't work. It's pushy, it wants to 
force everyone to connect to the hive, it demands ssl, etc, when I just 
want it to shut up and make

./python -m pip install .
do what
./python setup.py install --user
does

I will figure out what works best situationally moving forward as far as 
work arounds (probably modifying pip), but just saying, the modern way 
of jenkinizing everything sucks, and takes the fun out of tinkering in a 
cave.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Using loguru in a library

2023-05-02 Thread Roy Hann
MRAB wrote:

> On 2023-04-30 16:40, Roy Hann wrote:
>> Is there anyone using loguru (loguru 0.5.3 in my case) successfully in a
>> library?
>> 
>> 
>> In my __init__.py in mylib I do
>> 
>>logger.disable('mylib')
>> 
>> which definitely works. I don't get any more logging.
>> 
>> I "pip install ." the library, then in mytest.py I do
>> 
>>import mylib
>>logger.enable('mylib')
>> 
>> expecting that it would report any log messages above level DEBUG, just
>> as it does when I don't disable logging. Unfortunately it doesn't
>> have any effect; it doesn't report any logging from mylib.
>> 
>> I have verified that __name__ is visible in the library and is 'mylib'.
>> 
>> I would also have expected that logger.enable(None) would turn all the
>> logging on everywhere but it seems not.
>> 
>> I have probably misunderstood how logger.enable() is supposed to be
>> used. Can anyone share a brief example?
>> 
> According to the docs, the argument is the name of the module.
>
> In your example, the name of the module (i.e. file) is "__init__"; 
> "mylib" is the name of the package.

Thanks for taking a look at this. I will continue to play around with
it using your suggestion, but according to the snippets and recipes
for loguru at
https://loguru.readthedocs.io/en/stable/resources/recipes.html#configuring-loguru-to-be-used-by-a-library-or-an-application
I need to refer to the package name in disable() in __init__.py, not the
module/file name, and so I expect to use it in enable() in my main.
Also, as mentioned, I have already verified that __name__ in my
package is referring to the package name not the module.

Since every package will have a __init__.py even if it's empty, using
the module name to control logging by package would be difficult.

Or so I say. My code isn't working so I am wrong about some or all
of this. I'll keep tinkering and looking out for advice/suggestions
here.

Roy

-- 
https://mail.python.org/mailman/listinfo/python-list