Re: Embedding version in command-line program

2020-10-20 Thread Loris Bennett
"Loris Bennett"  writes:

> Tony Flury  writes:
>
>> On 07/10/2020 12:06, Loris Bennett wrote:
>>> Hi,
>>>
>>> I have written a program, which I can run on the command-line thus
>>>
>>>mypyprog --version
>>>
>>> and the get the version, which is currently derived from a variable in
>>> the main module file.
>>>
>>> However, I also have the version in an __init__.py file and in a
>>> pyproject.toml (as I'm using poetry, otherwise this would be in
>>> setup.py).
>>>
>>> What's the best way of reducing these three places where the version is
>>> defined to a single one?
>>>
>>> Cheers,
>>>
>>> Loris
>
>> My top level package always has a version.py file which defines __version__,
>> __author__ etc. I am not sure if that helps in your .toml file though - is it
>> executed or does it have the ability to read files when it creates the
>> distributable ?
>
> The problem is that the .toml file is not by default part of the
> distribution, but AFAIU is intended to store the project metadata used
> to create the METADATA file in dist-info when the package is built.
> Thus, the version defined in the .toml file is not directly available to
> the module itself.
>
> It seems to me, as a python novice, that poetry's function 'version'
> needs to be extended.  One possibility is that it should not only bump
> the version in the .toml file, but also bump the version in a version
> file like 'version.py' as well.  Alternatively, the value of the key
> 'version' in the .toml file, if it is not the version itself,  could be
> path to a file, such as a 'version.py', which holds the version.
>
> If that sounds reasonable, I could suggest it to the developers of
> poetry.

This is a known issue with a solution using 'importlib.metadata' or
'importlib_metadata' described here:

  https://github.com/python-poetry/poetry/pull/2366#issuecomment-652418094

Cheers,

Loris
-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


web conference on python

2020-10-20 Thread Agnese Camellini
Hello, i am not a staff member, but some connection on likeding asked me to
share this link and i would be happy if it helps someone.
https://python.geekle.us/?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pickle in C does not work

2020-10-20 Thread Serhiy Storchaka
20.10.20 01:28, Marco Sulla пише:
> PyObject *d = PyObject_Call((PyObject *)&PyDict_Type, args, NULL);

You can use PyDict_New() + PyDict_Merge() to create a dict from your
mapping.

> but I get:
> _pickle.PicklingError: Can't pickle : attribute lookup
> frozendict on builtins failed

tp_name of your class should include the module name.

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


Re: Pickle in C does not work

2020-10-20 Thread Marco Sulla
On Tue, 20 Oct 2020 at 16:07, Serhiy Storchaka  wrote:

> You can use PyDict_New() + PyDict_Merge() to create a dict from your
> mapping.
>

Well, yes, I know. I just wrote it for simplicity now. Do you think this is
the problem?
I forgot to say that copy and deepcopy works. For what I know, they use
__reduce__ if it's present.


> tp_name of your class should include the module name.
>

It will be done :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pickle in C does not work

2020-10-20 Thread Marco Sulla
On Tue, 20 Oct 2020 at 16:12, Marco Sulla 
wrote:

> tp_name of your class should include the module name.
>>
>
> It will be done :-)
>

It was the name... Thank you a lot!
-- 
https://mail.python.org/mailman/listinfo/python-list


Py_BuildValue vs PyTuple_Pack vs PyTuple_New

2020-10-20 Thread Marco Sulla
I read these three C api functions, They are similar, because they all
construct a tuple[1].

IMHO, Py_BuildValue is more simple to use than PyTuple_Pack that is more
simple to use than PyTuple_New.

Where to use one or the other? What's the relative performance of the three
functions?

[1] actually, Py_BuildValue can also return non-tuple objects.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Py_BuildValue vs PyTuple_Pack vs PyTuple_New

2020-10-20 Thread Serhiy Storchaka
20.10.20 18:05, Marco Sulla пише:
> I read these three C api functions, They are similar, because they all
> construct a tuple[1].
> 
> IMHO, Py_BuildValue is more simple to use than PyTuple_Pack that is more
> simple to use than PyTuple_New.
> 
> Where to use one or the other? What's the relative performance of the three
> functions?

Py_BuildValue is the most powerful (it can creates not only tuple, it
can create items from V integers, strings, etc, it can decrement
refcount), but it is slower. It is used when the performance less
important than saving few lines of code. PyTuple_Pack() is convenient
when you create a tuple from constant number of Python objects. It is a
good compromise with readability and performance. PyTuple_New is used
for creating a variable-size tuple. In combination with macros
PyTuple_SET_ITEM it can be use3d as more verbose but slightly more
efficient version of PyTuple_Pack. But PyTuple_SET_ITEM is not in the
limited API.

For your case I suggest to use PyTuple_Pack (unless you find that
PyTuple_New+PyTuple_SET_ITEM is critically more performant).

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


Re: Pickle in C does not work

2020-10-20 Thread Serhiy Storchaka
20.10.20 17:12, Marco Sulla пише:
> On Tue, 20 Oct 2020 at 16:07, Serhiy Storchaka  wrote:
>> You can use PyDict_New() + PyDict_Merge() to create a dict from your
>> mapping.
> Well, yes, I know. I just wrote it for simplicity now. Do you think this is
> the problem?

I think that it can be more performant and maybe even simpler.

> I forgot to say that copy and deepcopy works. For what I know, they use
> __reduce__ if it's present.

They do not resolve class by name. They just use the result of
__reduce__ to reconstruct an instance.

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


Re: Py_BuildValue vs PyTuple_Pack vs PyTuple_New

2020-10-20 Thread Marco Sulla
Good, thank you a lot again.
-- 
https://mail.python.org/mailman/listinfo/python-list