Python: asyncio and Tkinter

2017-12-20 Thread c.buhtz
I am looking for an "elegant" and "official" way to use asyncio in
Tkinter applications. The goal is that the GUI is not freezing while
doing some download-tasks (over 100 files from different locations).

I am looking around on the web for solutions but couldn't find one.
Only some workarounds with unknown and possible sideffects.

I asked the same question on StackOverflow with a MWE


On my current state I wouuld say there is not an official solution for
this. asyncio and Tkinter are not build to work together without dirty
hacks.

Do you have other informations?

I think about combining asyncio with multithreading so the asyncio
event loop has it's own thread and is not blocking the GUI event loop.
Or using only multithreading.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python: asyncio and Tkinter

2017-12-20 Thread c.buhtz
X-Post:
 

Dear Chris.

On 2017-12-21 00:42 Chris Angelico  wrote:
> I would recommend threading. You can run your GUI event loop on one
> thread, and your network I/O loop on another thread.

Thank you very much for your answer. It also came to my mind to
separate each loop in it's own thread. But I am for a way from being a
professional in that topics.

I created a minimal working example to ask that question on
StackOVerflow, too. There is no multithreading in that example.


Now I modified that example "based" on your solution. But the GUI is
still freezing why my tasks are working. Your solution is a bit to
complex for me and use some technics (the server think) I don't know.

Could you please throw an eye on the current state of my code?

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


Re: PEP about recommended project folder layout

2022-07-30 Thread c.buhtz
Isn't there a PEP?

On 2022-07-26 07:14 c.bu...@posteo.jp wrote:
> Hello,
> 
> I am not sure if I looked into the correct sources. I was looking in 
> "PEP 609 – Python Packaging Authority (PyPA) Governance" [1] and the 
> "PyPA specifications" [2].
> 
> My question in short: Is there an official document (e.g. a PEP)
> about a recommended layout for project folders.
> 
> Looking into the wild and past there are a lot of variations of such 
> layouts. I am far away from being a pro but depending on experience
> in my own projects and what I have learned from others (e.g. in 
> blog-posts/tutorials) I recommend to have the "test" folder and the 
> package folder side by side on the same level in the project folder
> (the root).
> 
> my_project
> |- tests
> |  └ test_*.py
> |- my_package
> |  └ __init__.py
> └-- README.md
> 
> I sometimes add to it the so called "src"-Layout where the package 
> folder is one level deeper in an extra "src" folder.
> 
> my_project
> |- tests
> |  └ test_*.py
> |- src
> |  └- my_package
> | └ __init__.py
> └-- README.md
> 
> I don't want to discuss the pros and cons of all variations. What I
> need is an official document I can use in discussions with other
> maintainers. If there is a PEP/document against my current
> recommendation I am also fine with this. ;)
> 
> Kind
> Christian
> 
> [1] -- 
> [2] -- 

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


[py-usr] flake8 gives me a W605 but Python don't

2022-09-10 Thread c.buhtz
Hello,

My `flake8` gives me a "W605 invalid escape sequence" [1] warning for
this piece of example code.

import re

def foobar():
rex = re.compile('Version: \d+.\d+.\d+.*', re.MULTILINE)

for match in rex.findall(' Version: 1.2.3 '):
print(match)


if __name__ == '__main__':
foobar()

But running this with Python 3.9.2 makes no problem. Python doesn't
give me a `SyntaxWarning` or anything else. Python doesn't give me an
error or warning. Only `flymake8` gives me this error.

I do understand what is wrong with the pattern string in `compile()`.
There should be a `r''` or the regex-escape characters should be
escaped them selfs (e.g. `'Version: \\d'`).

But my question is about why Python doesn't give me an error about it
and why does it work. The pattern matches. Shouldn't there be an error
or something? Does Python identify this string as an r-String by itself?

[1] -- 
-- 
https://mail.python.org/mailman/listinfo/python-list


Which architectures to support in a CI like Travis?

2022-09-18 Thread c.buhtz
Hello,

I am using TravisCI for my project on GitHub. The project is packaged
for Debian, Ubuntu, Arch and several other distros.

All this distros support multiple architectures and they have their own
test machines to take care that all packages working on all archs.

On my side (upstream) I wonder which arch I should "support" in my
TravisCI configuration. I wan't to speed up travis and I want to save
energy and carbon.

I suspect that my Python code should run on much every platform that
offers a Python interpreter. Of course there are edge cases. But they
would be captured by the distros own test environments.

So is there a good and objective reason to support multiple (and maybe)
exotic platforms in a CI pipeline on upstream?

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


Debugging automatic quotation in subprocess.Popen()

2022-10-07 Thread c.buhtz
Hello,

I need to improve my understanding about how subprocess.Popen() does
quote arguments. I have special case here.

Simple example:
Popen(['ls', '-l']) results on a shell in "ls -l" without quotation.

Quotes are added if they are needed:
Popen(['ls', 'folder with blank']) results on a shell in
"ls 'folder with blank'".

Am I right so far with the basics?

Is there a way to be sure and to debug how Popen() give it to the shell?
-- 
https://mail.python.org/mailman/listinfo/python-list


pip/setuptools: Entry points not visible from pkexec-root-environment

2022-12-18 Thread c.buhtz
Hello,

when I install a package on a GNU/Linux system via "sudo python3 -m pip
install -e ." that defines entry points in its pyproject.toml the entry
point starter scripts are located in /usr/locale/bin.

That folder is in PATH for "regular" root users and by "sudo su" roots
users.

But I need to start that entry points via "pkexec".
But in the environment started by "pkexec" the PATH does not contain
/usr/local/bin.

So what can I do?

I don't need a hack or workaround but an "elegant" solution.
-- 
https://mail.python.org/mailman/listinfo/python-list


What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread c.buhtz
Hello,

this posting isn't about asking for a technical solution. My intention
is to understand the design decision Python's core developers made in
context of that topic.

The logging module write everything to stderr no matter which logging
level is used.

The argparse module does it more differentiated. If arguments are
mandatory but none are given then argparse produce a short version of
the usage info; on stderr. If the user request the usage info via "-h"
it goes to stdout. This is the behavior I would expect.

Why does logging behave different? DEBUG and INFO imho should go to
stdout not stderr.

Of course I could modify the handlers etc. to workaround this. But I
assume that there was something in mind of the Python developers when
they decided that.

My goal is not to divide between the use of print() or logging.info()
in my own code. This would mess up a lot.
-- 
https://mail.python.org/mailman/listinfo/python-list


No solution for "--verbose" (on stdout) output in Pythonds standard library?

2023-01-04 Thread c.buhtz
Hello,

first I have to say that in my current and fresh humble opinion the
often seen "--verbose" switch in command line applications should
affect only the messages given to the users. This means messages on
"stdout". That is what this question is about.

The logging module is not an option because it works on stderr and is
not intended to offer messages for the user but just for the system and
its admins via logs (log-files, syslog, stderr redirection, ...).

Using logging handlers redirecting to stdout are considered as
workarounds by me and also not an option.

This is not only my opinion but also part of the Python documentation:
https://docs.python.org/3/howto/logging.html#when-to-use-logging

I'm so detailed here about that difference between stdout and stderr
because in the wild (e.g. on StackOverflow) you often find "use logging
log levels" as a solution for that problem, which IMHO isn't one.

Now the question:
>From my research on the docs it seems there is no feature in the
standard library which could help me to implement "--verbose" or
multiple verbosity levels like "-vvv"?
I found some workarounds/hacks.
https://stackoverflow.com/q/5980042/4865723
But my experience with Python as a Swiss knife is that there is always
a standard solution for such basic and often reinvented things. I won't
believe that each Python developer writes its own verbose feature. ;)
-- 
https://mail.python.org/mailman/listinfo/python-list


subprocess equivalent for "os.execvp()"?

2023-01-08 Thread c.buhtz
Hello,

is there an equivalent in the subprocess module for "os.execvp()" to
replace the current process with the new called one?

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


import logging raise NotImplementedError

2015-11-24 Thread c.buhtz
I using 'logging' for some month.
But today I have strange problem. When importing it it fails.

Python 3.4.3 (default, Oct 14 2015, 20:33:09)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging  
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2237, in _find_and_load
  File "", line , in
_find_and_load_unlocked File "", line
2164, in _find_spec File "", line 1940, in
find_spec File "", line 1916, in _get_spec
  File "", line 1897, in _legacy_get_spec
  File "", line 863, in spec_from_loader
  File "", line 904, in
spec_from_file_location File
"/usr/local/lib/python3.4/dist-packages/logging-0.4.9.6-py3.4.egg/logging/__init__.py",
line 618 raise NotImplementedError, 'emit must be implemented '\ ^
SyntaxError: invalid syntax

Any idea about it?

I am not sure if there where an update in the background or something
changed.

The current situation make each "logging" using Python application
unable to run.

The problem happens with Python3 because "logging" is in the default
installation. In Python2 it is not installed. I installed it with
   sudo python2 -m pip install logging -U

This works without problems. Importing in Python2 works, too.
-- 
GnuPGP-Key ID 0751A8EC
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: import logging raise NotImplementedError

2015-11-25 Thread c.buhtz
On 2015-11-25 09:00 Chris Angelico  wrote:
> You appear to have installed it into your Python 3.4's package

No really me. I found out who.

I installed "ebscopy" from its GitHub repository with
"sudo pip3 ./setup.py install"
And this (tried to) install(ed) "logging" from PyPi. Don't know why.

I just removed the egg-file in the dist-utils directory. After that
everything works fine.
-- 
GnuPGP-Key ID 0751A8EC
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: import logging raise NotImplementedError

2015-11-25 Thread c.buhtz
On 2015-11-25 19:51 Chris Angelico  wrote:
> Ah! That would do it, yes. (Incidentally, 'pip install ebscopy' would
> be how I'd do it.)

Yes, I did first. But I had some problems with 'ebscopy' so I wanted to
be sure to get the freshes version of it available. ;)
-- 
GnuPGP-Key ID 0751A8EC
-- 
https://mail.python.org/mailman/listinfo/python-list


filter a list of strings

2015-12-02 Thread c.buhtz
I would like to know how this could be done more elegant/pythonic.

I have a big list (over 10.000 items) with strings (each 100 to 300
chars long) and want to filter them.

list = .

for item in list[:]:
  if 'Banana' in item:
 list.remove(item)
  if 'Car' in item:
 list.remove(item)

There are a lot of more conditions of course. This is just example code.
It doesn't look nice to me. To much redundance.

btw: Is it correct to iterate over a copy (list[:]) of that string list
and not the original one?
-- 
GnuPGP-Key ID 0751A8EC
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: filter a list of strings

2015-12-03 Thread c.buhtz
Thank you for your suggestion. This will help a lot.

On 2015-12-03 08:32 Jussi Piitulainen  wrote:
> list = [ item for item in list
>  if ( 'Banana' not in item and
>   'Car' not in item ) ]

I often saw constructions like this
  x for x in y if ...
But I don't understand that combination of the Python keywords (for,
in, if) I allready know. It is to complex to imagine what there really
happen.

I understand this
  for x in y:
if ...

But what is about the 'x' in front of all that?
-- 
GnuPGP-Key ID 0751A8EC
-- 
https://mail.python.org/mailman/listinfo/python-list


carry **arguments through different scopes/functions

2016-01-31 Thread c.buhtz
I am not sure what the problem is here, so I don't really know how I
should call the subject for that question. Please offer a better
subject.

The code below is a extrem simplified example of the original one. But
it reproduce the problem very nice. Please focus on the variable
`return_code`.

There is a `list()` of numbers without the number `7` in. The code
check if the number `7` is in and should tell that it is not in. But it
does tell me that `7 is in`. ;)

I think I didn't know some special things about scopes of variables in
Python. This might be a very good problem to learn more about that. But
I don't know on which Python topic I should focus here to find a
solution for my own.

#!/usr/bin/env python3
import sys

def walkOn_ids(ids, handlerFunction, **handlerArgs):
for one_id in ids:
handlerFunction(one_id=one_id, **handlerArgs)
print('after handler-call for id {}\t{}'
  .format(one_id, handlerArgs))


def _on_id(one_id, return_code):
if return_code is False:
return

if one_id == 7:
return_code = True
else:
return_code = False

print('one_id: {}\treturn_code: {}'.format(one_id, return_code))


def _isSevenInIt(ids):
return_code = True

walkOn_ids(ids=ids,
   handlerFunction=_on_id,
   return_code=return_code)

return return_code


ids = [1,2,3,4,5,6,8,9]  # NO 7
print(ids)

if _isSevenInIt(ids) is True:
print('7 is in')
else:
print('no 7 in it')

sys.exit()

Of course I could make `return_code` a `global` variable. But that is
not the goal. The goal is to carry this variable inside the
walker-function and bring the result back. In the original code I will
use some more complexe data structures with `**handlerArgs`.
-- 
https://mail.python.org/mailman/listinfo/python-list


build a deb-package

2015-06-04 Thread c.buhtz
I am not sure where I am or where to go. ;)
So before asking about technical details I first want to know if it is
generally possible.

On Ubuntu when I install python-based applications (from a repository)
as deb-packages I can start them by just typing its name because the
py-file or a link to it are installed in bin-directory that is in the
$PATH.

I read a lot of wikis/howtows and couldn't get this done with my own
(simple hello world) application working with Python3.

E.g. I used setup.py bdist_rpm and alien to create a deb. But the
py-file is in dist-package and not in a bin-directory.

So is it possible to create a deb-file with a Python3-based application
in it that can be started over the $PATH variable?
-- 
https://mail.python.org/mailman/listinfo/python-list


understanding why there is no setup.py uninstall

2015-07-06 Thread c.buhtz
This question is not technical.
I know that there is no 'uninstall' Option in a setup.py.
I know this discussions and workarounds for that problem, too.


I want to understand the design concept behind it.

Why isn't there no uninstall routine implemented?

For me as a user and admin it feels quite dirty when installing
something with the setup.py but then not being able to remove it clean
like I would do it with packages of my system-package-manager (e.g. with
apt-get on a debianized system).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: understanding why there is no setup.py uninstall

2015-07-07 Thread c.buhtz
On 2015-07-06 18:34 Ben Finney  wrote:
> Part of the better system is that we have the Python Packaging
> Authority http://pypa.io/> which didn't exist when Distutils was
> designed. Read the documents there and I hope you'll be glad at the
> improvement!
> ...

Thank you very much for that explanation. I haven't read something like
this before about that topic. Now it is much easier for me evaluate the
different systems/possibilities for that task.
-- 
https://mail.python.org/mailman/listinfo/python-list


[setuptools] install data-file in users home-dir

2015-07-10 Thread c.buhtz
I am using setuptools to create a wheel file.

There is a conf-file I want to install into the users config-diretory.
e.g. /home/user/.config/appname/app.conf

setup(...,
  data_files = [ ('~/.config/appname/', ['app.conf']) ]
 )

I see two problems here:

1.
I don't know the users "name". So I have to use a placeholder here.
Does '~' work here in that case?

2.
To install the wheel-file with pip I need sudo-privilegs on Ubuntu
14.04.2. That means while the install script runs I can not ask for the
users name because it is "root" in that case.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [setuptools] install data-file in users home-dir

2015-07-10 Thread c.buhtz
Hi Chris,

thank you for your answer.

On 2015-07-10 09:39 Chris Warrick  wrote:
> You should NEVER use sudo with pip.  Instead, use virtualenvs as a
> regular user, or create your own .deb packages.  

I am not sure, but maybe this is an Ubuntu-specific "problem"?
When I don't use sudo I got errors like this
"PermissionError: [Errno 13] Permission denied:
'/usr/local/lib/python3.4/dist-packages/SQLAlchemy-1.0.6.dist-info"

And it make sense for me.

Don't tell me about deb-Packages! :D I am stuck with that currently. I
would be glad to have a correct working whl-file for my local needs.
After that - maybe! - I will start again with thinking about a deb.

How can virtualenv help here? I need to install
python-software/packages to the system and not to a different
environment or sandbox.
I never used virtualenv but as I understand it it is for testing
purpose not for productive system.

> And you should not create the files in your install script.  Instead,
> install them to a different data dir (somewhere in 'share/appname'  

What do you mean with "data dir"? For a default config-file it could
be /etc/appname/default.conf. But I have no rights for that.

> should copy this file to user’s config directory (use pkg_resources to
> help you get it) if it does not exist yet.  

I will look at this package.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [setuptools] install data-file in users home-dir

2015-07-10 Thread c.buhtz
On 2015-07-10 09:39 Chris Warrick  wrote:
> And you should not create the files in your install script.  Instead,
> install them to a different data dir (somewhere in 'share/appname', or
> alongside your package). When someone runs your app, only then you
> should copy this file to user’s config directory

I have to check if there still is a user config file.
When doing this with the app itself, the check would be done while each
start - what is quite unnecessary.
-- 
https://mail.python.org/mailman/listinfo/python-list


Optimal solution for coloring logging output

2015-08-03 Thread c.buhtz
I don't want to ask how to do this because there are so many
"solutions" about it.


There are so much different and part of unpythontic solutions I can not
decide myself. What do you (as real pythontics) think about that.
Which of the solutions fit to concepts of Python and its logging
package?

Coloring means here not only the message itself. The (levelname) should
be included in the coloring.
For myself coloring the (levelname) would be enough to avoid to much
color in the output.

1.
The solution itself shouldn't care about plattform differences because
there are still some packages which are able to offer
plattform-independent console-coloring. Which would you prefere? ;)

2.
Some solutions derive from StreamHandler or much more bad hacking the
emit() function. I think both of them are not responsible for how the
output should look or be presented.

3.
How to present the output is IMO the responsibility of a Formater, isn't
it? So I should derive from the Formater.

What do you as Pythonics think of that? ;)
-- 
-BEGIN PGP PUBLIC KEY BLOCK-
Version: GnuPG v1

mQENBFQIluABCACfPwAhRAwFD3NXgv5CtVUGSiqdfJGVViVBqaKd+14E0pASA0MU
G0Ewj7O7cGy/ZIoiZ0+lIEZmzJKHfuGwYhXjR/PhnUDrQIHLBvh9WuD6JQuULXfH
kXtVm/i9wm76QAcvr2pwYgNzhcJntUHl2GcgnInYbZDeVmg+p9yIPJjuq73/lRS3
0/McgNoFOBhKK/S6STQuFyjr9OyJyYd1shoM3hmy+kg0HYm6OgQBJNg92WV9jwGe
GzlipvEp2jpLwVsTxYir2oOPhfd9D1fC9F/l/3gXbfjd5GIIVrZFq2haZmoVeJ33
LJxo3RA5Tf9LoUeels1b4s9kFz6h7+AHERUpABEBAAG0IUNocmlzdGlhbiBCdWh0
eiA8YnVodHpAcG9zdGVvLmRlPokBPgQTAQIAKAUCVAiW4AIbAwUJAeEzgAYLCQgH
AwIGFQgCCQoLBBYCAwECHgECF4AACgkQZLsXsAdRqOxNUAf/V/hDA5zGDpySuCEj
DhjiVRK74J9Wd8gfH0WAf1Co5HZ24wZH8rgOIVIgXw8rWkOw/VA6xfdfT+64xjTY
Fhkpbrk199nDzp72F7Jc4NC+x8xac2e3rK5ifSWhZx7L5A32pGYE+d16m3EEqImK
D4gcZl38x9zdUnD4hHyXkIPz1uCfuMuGgWEnaUk4Wbj41CBZr3O0ABue6regV15U
jaes8r+B8iCcY+0yP2kse+3iaCaMqNv5FgQZ9+b2Cql8pFkZJVtBVUw4GW3DWZJi
du0O/YrC9TgS+xY9ht/MD2qSHwjcK1sdImjqBO7xP8TIOwKeYyDvGKnSO3EJ/sSA
UPGEPrkBDQRUCJbgAQgA0k/Qg67CCUJE2/zuxBEoK4wLJpDRJzh8CQPZpjWx8VP0
KL892jwfxymXn8KNhuy1SgCBFSeV9jg4VZNWDlUGJc2lo82ajr9PzIsrQwu4lf0B
zrUWV5hWepKu/kb8uSjx58YYfx0SFz4+9akX3Wwu9TUHntzL5Gk3Q26nnsr1xEJ+
VEumvCH9AE0Tk0K7dQpJ2/JcLuO+uhrpd/lHFDYVN5NsG3P015uFOkDI6N/xNFCj
v95XNR93QlfKpK3qWlFGescfG+o/7Ub6s67/i/JoNbw0XgPEHmQfXpD7IHO4cu+p
+ETb11cz+1mmi96cy98ID+uTiToJ8G//yD9rmtyxoQARAQABiQElBBgBAgAPBQJU
CJbgAhsMBQkB4TOAAAoJEGS7F7AHUajs6sQH/iKs6sPc0vkRJLfbwrijZeecwCWF
blo/jzIQ8jPykAj9SLjV20Xwqg3XcJyko8ZU6/zuRJq9xjlv9pZr/oVudQAt6v+h
2Cf4rKEjmau483wjMV2xjTXQhZi9+ttDbia4fgdmGtKsOicn5ae2fFXcXNPu3RiW
sZKifWdokA6xqMW6iIG9YjjI5ShxngHWp2xfPscBFMDRtFOMags/Yx+YvwoyEZ4A
dURYMFHFqpwILEc8hIzhRg1gq40AHbOaEdczS1Rr3T7/gS6eBs4u6HuY5g2Bierm
lLjpspFPjMXwJAa/XLOBjMF2vsHPrZNcouNKkumQ36yq/Pm6DFXAseQDxOk=
=PGP9
-END PGP PUBLIC KEY BLOCK-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread c.buhtz
Dear Cecil,

I subscribed to late to answer to your top-post in that thread.
I had the same topic for myself in the last months and tried a lot of
things.

In your situation I would prefere the INI-file format, too.

But doen't user 'configparser' for that. As other fellows described
it's a bad solution because option order and comments are not preserved
when writing back. It is a quite incomplete implementation of
human-readable-config files.

Use 'configobj'[1][2] which can be handled very easy, too. You can have
comments and everything you want in there.

 [1] https://pypi.python.org/pypi/configobj
 [2] https://github.com/DiffSK/configobj
-- 
-BEGIN PGP PUBLIC KEY BLOCK-
Version: GnuPG v1

mQENBFQIluABCACfPwAhRAwFD3NXgv5CtVUGSiqdfJGVViVBqaKd+14E0pASA0MU
G0Ewj7O7cGy/ZIoiZ0+lIEZmzJKHfuGwYhXjR/PhnUDrQIHLBvh9WuD6JQuULXfH
kXtVm/i9wm76QAcvr2pwYgNzhcJntUHl2GcgnInYbZDeVmg+p9yIPJjuq73/lRS3
0/McgNoFOBhKK/S6STQuFyjr9OyJyYd1shoM3hmy+kg0HYm6OgQBJNg92WV9jwGe
GzlipvEp2jpLwVsTxYir2oOPhfd9D1fC9F/l/3gXbfjd5GIIVrZFq2haZmoVeJ33
LJxo3RA5Tf9LoUeels1b4s9kFz6h7+AHERUpABEBAAG0IUNocmlzdGlhbiBCdWh0
eiA8YnVodHpAcG9zdGVvLmRlPokBPgQTAQIAKAUCVAiW4AIbAwUJAeEzgAYLCQgH
AwIGFQgCCQoLBBYCAwECHgECF4AACgkQZLsXsAdRqOxNUAf/V/hDA5zGDpySuCEj
DhjiVRK74J9Wd8gfH0WAf1Co5HZ24wZH8rgOIVIgXw8rWkOw/VA6xfdfT+64xjTY
Fhkpbrk199nDzp72F7Jc4NC+x8xac2e3rK5ifSWhZx7L5A32pGYE+d16m3EEqImK
D4gcZl38x9zdUnD4hHyXkIPz1uCfuMuGgWEnaUk4Wbj41CBZr3O0ABue6regV15U
jaes8r+B8iCcY+0yP2kse+3iaCaMqNv5FgQZ9+b2Cql8pFkZJVtBVUw4GW3DWZJi
du0O/YrC9TgS+xY9ht/MD2qSHwjcK1sdImjqBO7xP8TIOwKeYyDvGKnSO3EJ/sSA
UPGEPrkBDQRUCJbgAQgA0k/Qg67CCUJE2/zuxBEoK4wLJpDRJzh8CQPZpjWx8VP0
KL892jwfxymXn8KNhuy1SgCBFSeV9jg4VZNWDlUGJc2lo82ajr9PzIsrQwu4lf0B
zrUWV5hWepKu/kb8uSjx58YYfx0SFz4+9akX3Wwu9TUHntzL5Gk3Q26nnsr1xEJ+
VEumvCH9AE0Tk0K7dQpJ2/JcLuO+uhrpd/lHFDYVN5NsG3P015uFOkDI6N/xNFCj
v95XNR93QlfKpK3qWlFGescfG+o/7Ub6s67/i/JoNbw0XgPEHmQfXpD7IHO4cu+p
+ETb11cz+1mmi96cy98ID+uTiToJ8G//yD9rmtyxoQARAQABiQElBBgBAgAPBQJU
CJbgAhsMBQkB4TOAAAoJEGS7F7AHUajs6sQH/iKs6sPc0vkRJLfbwrijZeecwCWF
blo/jzIQ8jPykAj9SLjV20Xwqg3XcJyko8ZU6/zuRJq9xjlv9pZr/oVudQAt6v+h
2Cf4rKEjmau483wjMV2xjTXQhZi9+ttDbia4fgdmGtKsOicn5ae2fFXcXNPu3RiW
sZKifWdokA6xqMW6iIG9YjjI5ShxngHWp2xfPscBFMDRtFOMags/Yx+YvwoyEZ4A
dURYMFHFqpwILEc8hIzhRg1gq40AHbOaEdczS1Rr3T7/gS6eBs4u6HuY5g2Bierm
lLjpspFPjMXwJAa/XLOBjMF2vsHPrZNcouNKkumQ36yq/Pm6DFXAseQDxOk=
=PGP9
-END PGP PUBLIC KEY BLOCK-
-- 
https://mail.python.org/mailman/listinfo/python-list


doc-generation tool

2015-10-06 Thread c.buhtz
I am confused about to much possible tools and conventions for
doc-strings and the doc-generating tools using it.

My code isn't about a package interface. It is just a simple
application I want I readable documentation for.

I have the following needs
 - in-code doc-string should be readable for humans (e.g.
   reStructuredText, markup)
 - type of a methode-argument or class-attribute can be specified
 - no seperation between class-doc-string and
   class-attribute-doc-strings. the attribute should be described in
   the class-doc-string itself

I read a lot about Doxygen and Sphinx but not sure which one of it I
should concentrate on. And maybe there are other/better/easier
solutions for Python code?
-- 
-BEGIN PGP PUBLIC KEY BLOCK-
Version: GnuPG v1

mQENBFQIluABCACfPwAhRAwFD3NXgv5CtVUGSiqdfJGVViVBqaKd+14E0pASA0MU
G0Ewj7O7cGy/ZIoiZ0+lIEZmzJKHfuGwYhXjR/PhnUDrQIHLBvh9WuD6JQuULXfH
kXtVm/i9wm76QAcvr2pwYgNzhcJntUHl2GcgnInYbZDeVmg+p9yIPJjuq73/lRS3
0/McgNoFOBhKK/S6STQuFyjr9OyJyYd1shoM3hmy+kg0HYm6OgQBJNg92WV9jwGe
GzlipvEp2jpLwVsTxYir2oOPhfd9D1fC9F/l/3gXbfjd5GIIVrZFq2haZmoVeJ33
LJxo3RA5Tf9LoUeels1b4s9kFz6h7+AHERUpABEBAAG0IUNocmlzdGlhbiBCdWh0
eiA8YnVodHpAcG9zdGVvLmRlPokBPgQTAQIAKAUCVAiW4AIbAwUJAeEzgAYLCQgH
AwIGFQgCCQoLBBYCAwECHgECF4AACgkQZLsXsAdRqOxNUAf/V/hDA5zGDpySuCEj
DhjiVRK74J9Wd8gfH0WAf1Co5HZ24wZH8rgOIVIgXw8rWkOw/VA6xfdfT+64xjTY
Fhkpbrk199nDzp72F7Jc4NC+x8xac2e3rK5ifSWhZx7L5A32pGYE+d16m3EEqImK
D4gcZl38x9zdUnD4hHyXkIPz1uCfuMuGgWEnaUk4Wbj41CBZr3O0ABue6regV15U
jaes8r+B8iCcY+0yP2kse+3iaCaMqNv5FgQZ9+b2Cql8pFkZJVtBVUw4GW3DWZJi
du0O/YrC9TgS+xY9ht/MD2qSHwjcK1sdImjqBO7xP8TIOwKeYyDvGKnSO3EJ/sSA
UPGEPrkBDQRUCJbgAQgA0k/Qg67CCUJE2/zuxBEoK4wLJpDRJzh8CQPZpjWx8VP0
KL892jwfxymXn8KNhuy1SgCBFSeV9jg4VZNWDlUGJc2lo82ajr9PzIsrQwu4lf0B
zrUWV5hWepKu/kb8uSjx58YYfx0SFz4+9akX3Wwu9TUHntzL5Gk3Q26nnsr1xEJ+
VEumvCH9AE0Tk0K7dQpJ2/JcLuO+uhrpd/lHFDYVN5NsG3P015uFOkDI6N/xNFCj
v95XNR93QlfKpK3qWlFGescfG+o/7Ub6s67/i/JoNbw0XgPEHmQfXpD7IHO4cu+p
+ETb11cz+1mmi96cy98ID+uTiToJ8G//yD9rmtyxoQARAQABiQElBBgBAgAPBQJU
CJbgAhsMBQkB4TOAAAoJEGS7F7AHUajs6sQH/iKs6sPc0vkRJLfbwrijZeecwCWF
blo/jzIQ8jPykAj9SLjV20Xwqg3XcJyko8ZU6/zuRJq9xjlv9pZr/oVudQAt6v+h
2Cf4rKEjmau483wjMV2xjTXQhZi9+ttDbia4fgdmGtKsOicn5ae2fFXcXNPu3RiW
sZKifWdokA6xqMW6iIG9YjjI5ShxngHWp2xfPscBFMDRtFOMags/Yx+YvwoyEZ4A
dURYMFHFqpwILEc8hIzhRg1gq40AHbOaEdczS1Rr3T7/gS6eBs4u6HuY5g2Bierm
lLjpspFPjMXwJAa/XLOBjMF2vsHPrZNcouNKkumQ36yq/Pm6DFXAseQDxOk=
=PGP9
-END PGP PUBLIC KEY BLOCK-
-- 
https://mail.python.org/mailman/listinfo/python-list


PubMed / Entrez

2015-11-19 Thread c.buhtz
I am looking for a way to use the PubMed (medical research search
engine) API (aka Entrez) with Python3.

Does anyone know packages for that?
-- 
GnuPGP-Key ID 0751A8EC
-- 
https://mail.python.org/mailman/listinfo/python-list


[argparse] optional parameter without --switch

2015-11-23 Thread c.buhtz
I want to call (on bash) a Python script in this two ways without any
error.

./arg.py
./arg.py TEST

It means that the parameter (here with the value `TEST`) should be
optional. With argparse I only know a way to create optional paramters
when they have a switch (like `--name`).

Is there a way to fix that?

#!/usr/bin/env python3
import sys
import argparse

parser = argparse.ArgumentParser(description=__file__)

# must have
#parser.add_argument('name', metavar='NAME', type=str)

# optional BUT with a switch I don't want
#parser.add_argument('--name', metavar='NAME', type=str)

# store all arguments in objects/variables of the local namespace
locals().update(vars(parser.parse_args()))

print(name)

sys.exit()
-- 
GnuPGP-Key ID 0751A8EC
-- 
https://mail.python.org/mailman/listinfo/python-list


GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread c.buhtz--- via Python-list

X-Post: https://stackoverflow.com/q/76913082/4865723

I want to display one string in its original source (untranslated) 
version and in its translated version site by site without duplicating 
the string in the python source code?

It wouldn't be a big deal if it is only one word.

print('The translated string "{}" is originally 
"{}".'.format(_('Hello'), 'Hello'))


But in my situation it is a multi line string containing multiple 
paragraphs. It is a full text. I don't want to duplicate that string.


# Imagine 'Hello' as a 50x70 characters multi line string.
original = 'Hello'
translated = _('Hello')
print('The translated string "{}" is originally 
"{}".'.format(translated, original))


I do use the "class based API" of GNU gettext. My current approach, 
which is not working, is to somehow (how!?) disable (or mask) the 
translation function "_()" temporarily.
But as described in the stackoverflow question (see first line of this 
mail) this do not work.


def foobar(translate):
if not translate:
# I try to mask the global _() builtins-function
def _(txt):
return txt

return _('Hello')

if __name__ == '__main__':

# To ilustrate that _() is part of "builtins" namespace
print(_('No problem.'))

print('The translated string "{}" is originally "{}".'
  .format(foobar(True), foobar(False)))

This is the output:

Traceback (most recent call last):
  File "/home/user/ownCloud/_transfer/./z.py", line 27, in 
.format(foobar(True), foobar(False)))
  File "/home/user/ownCloud/_transfer/./z.py", line 19, in foobar
return _('Hello')
UnboundLocalError: local variable '_' referenced before assignment

The full MWE can be found at stackoverflow 
(https://stackoverflow.com/q/76913082/4865723).


The question is if this can be solved somehow or if there is an 
alternative approach.
The "_()" function is installed in the builtins namespace because of 
gettext class based API. This is nice.
Maybe I can somehow manipulate that builtins namespace? I tried to 
import builtins and played around with it but couldn't find a way to do 
it.


Thanks
Christian Buhtz

PS: This is IMHO not relevant for my question but if someone is 
interested the connection to productive code can be found in this issue: 
https://github.com/bit-team/backintime/issues/1473 There I describe what 
I want to achive and also provide a GUI mockup.

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


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread c.buhtz--- via Python-list

Hello Mirko,

thanks for reply.

Am 17.08.2023 18:19 schrieb Mirko via Python-list:

You could solve it by defining _() locally like so:

def foobar(translate):
_ = gettext.gettext


I see no way to do that. It is not the "class based API" of gettext 
installing _() into the builtins namespace.
My users are able to configure the language of their UI explicit. It is 
a full application.



def orig_and_trans(msg):
return (_(msg), msg)


This will be ignored by GNU gettext utils (xgettext in my case) will 
ignore this line because they do not know what "msg" is. The string 
"hello" won't appear in the pot-file.

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


Using "textwrap" package for unwrappable languages (Japanese)

2023-08-30 Thread c.buhtz--- via Python-list

Hi,

I do use "textwrap" package to wrap longer texts passages. Works well 
with English.
But the source string used is translated via gettext before it is 
wrapped.


Using languages like Japanese or Chinese would IMHO result in unwrapped 
text. Japanese rules do allow to break a line nearly where ever you 
want.


How can I handle it with "textwrap"?

At runtime I don't know which language is really used. So I'm not able 
to decide using "textwrap" or just inserting "\n" every 65 characters.


Another approach would be to let the translators handle the line breaks. 
But I would like to avoid it because some of them don't know what "\n" 
means and they don't know the length rule (in my case 65 characters).


Any ideas about it?

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


Re: Using "textwrap" package for unwrappable languages (Japanese)

2023-08-30 Thread c.buhtz--- via Python-list

Dear Peter,

thanks for your reply. That is a very interesting topic.

I was a bit wrong. I realized that textwrap.wrap() do insert linebreaks 
when "words" are to long. So even a string without any blank space well 
get wrapped.


Am 30.08.2023 14:07 schrieb Peter J. Holzer via Python-list:

another caveat: Japanese
characters are usually double-width. So (unless your line length is 130
characters for English) you would want to add that line break every 32
characters.


I don't get your calculation here. Original line length is 130 but for 
"double-with" characters you would break at 32 instead of 65 ?



(


Then I will do something like this

unicodedata.east_asian_width(mystring[0])

W is "wide". But there is also "F" (full-width).
What is the difference between "wide" and "full-width"?

My application do support (currently 46) languages including Simplified 
and Traditional Chinese, Vietnamese, Korean, Japanese, Cyrylic.

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


PEP668 / pipx and "--editable" installs

2023-09-15 Thread c.buhtz--- via Python-list

Hello,
I wonder that today was the first day I stumbled over PEP668 / pipx and 
the "externally-managed-environment" problem. I migrated from Debian 11 
to 12.


I'm developing some Python packages; applications and libraries. I never 
used virtual environments and wouldn't like to start with it.
But I do use "--editable" for my packages. I wonder how I should go on 
with using "pipx" and "--editable" mode because I had some problems with 
it I couldn't fix following PEP668 but only with using 
"--break-system-packages". And PEP668 do not mention editable-mode.


The two example packages I use here are public available and clonable 
(is this a word?) via git.


Let's start with a command line application named "hyperorg" 
(https://codeberg.org/buhtz/hyperorg).
I tried to install it via "pipx install -e .[develop]". It's 
pyproject.toml has a bug: A missing dependency "dateutil". But 
"dateutil" is not available from PyPi for Python 3.11 (the default in 
Debian 12). But thanks to great Debian they have a "python3-dateutil" 
package. I installed it.
But "hyperorg" do ignore it and can't import it. Of course I 
re-installed hyperorg via pipx.
Installing it via "pip" and "--break-system-packages" it works well and 
do see the "python3-dateutil" package.


The second example is a "library" named "buhtzology" 
(https://codeberg.org/buhtz/buhtzology).
Here it seems that "pipx" do refuse to install it in the first place 
("pipx install -e .[develop]") and gave me this message.


"No apps associated with package buhtzology. Try again with 
'--include-deps' to include apps of dependent packages, which are listed 
above. If you are attempting to install a library, pipx should not be 
used. Consider using pip or a similar tool instead."


What is the difference between an "app" (it is a google/apple marketing 
term used for software with user interaction. Just name it application.) 
and a "library" in context of pip(x)? Why does it count?
I tried again with "pipx install --include-deps -e .[develop]" and got 
an output I'm not sure if this is an error or a success message. I 
assume it is an error because I'm not able to "import buhtzology". It 
seems like that the package was not installed.


⚠️  Note: normalizer was already on your PATH at /usr/bin/normalizer
⚠️  Note: f2py was already on your PATH at /usr/bin/f2py
⚠️  Note: f2py3 was already on your PATH at /usr/bin/f2py3
⚠️  Note: f2py3.11 was already on your PATH at /usr/bin/f2py3.11
⚠️  Note: py.test was already on your PATH at /usr/bin/py.test
⚠️  Note: pytest was already on your PATH at /usr/bin/pytest
⚠️  File exists at /home/user/.local/bin/pycodestyle and points to 
/home/user/.local/bin/pycodestyle, not 
/home/user/.local/pipx/venvs/buhtzology/bin/pycodestyle. Not modifying.
⚠️  File exists at /home/user/.local/bin/ruff and points to 
/home/user/.local/bin/ruff, not 
/home/user/.local/pipx/venvs/buhtzology/bin/ruff. Not modifying.

  installed package buhtzology 0.2.0.dev0, installed using Python 3.11.2
  These apps are now globally available
- f2py
- f2py3
- f2py3.11
- fonttools
- normalizer
- py.test
- pyftmerge
- pyftsubset
- pytest
- tabulate
- ttx
- pycodestyle (symlink missing or pointing to unexpected location)
- ruff (symlink missing or pointing to unexpected location)
done! ✨ 🌟 ✨

BUT!

$ python3 -c "import buhtzology"
Traceback (most recent call last):
  File "", line 1, in 
ModuleNotFoundError: No module named 'buhtzology'
--
https://mail.python.org/mailman/listinfo/python-list


Re: PEP668 / pipx and "--editable" installs

2023-09-15 Thread c.buhtz--- via Python-list
Dear Rimu,

thanks for your reply. I'm willing to learn for sure.

On 2023-09-16 14:17 Rimu Atkinson via Python-list
 wrote:
> There's your problem - everything else is a result of this. There is 
> just no nice way to work with a combination of pypi, apt-get and 
> system-wide python.
> 
> Everyone uses virtual environments.

It is nothing bad about using virtual environments but also not about
not using them. In my own work I haven't see a use case where I needed
them. And I expect that some day I'll encounter a use case for it. This
here is not about pro and cons of virtual environments.

Please explain how the two problems I explained are influenced by not
using virtual environments.

As I explained I tried to use "pipx" (the X at the end!) because it
seems to be the recommended way today because of PEP668. And to my
knowledge pipx do use a virtual environment in the back. Nice.

But it did not work the way I expected.

I don't say that pipx is wrong or buggy. I assume I misunderstood
something in context of PEP668 and in the use of pipx. That is why I'm
asking here.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP668 / pipx and "--editable" installs

2023-09-17 Thread c.buhtz--- via Python-list
Thanks for your reply. btw: I do know what a virtual environment is and
how its works. No need to explain. And again: I do expect "pipx" to use
virtual environments. So this thread is not about pro and cons of using
virtual environments.

On 2023-09-17 11:57 Rimu Atkinson via Python-list
 wrote:
> The first problem can be avoided because virtual environments can use
> a different version of python than the system one. If you need an
> earlier version of python then you can use it instead.

But as I explained I used pipx to install it. So virtual environments
are used in that case.
Maybe I made not the problem clear enough: The problem is that the
installed application ("hyperorg") did not see the system package
"python3-dateutils".

How can I solve this without(!) using another Python version?
The behavior that the pipx-installed application is not able to see
system python packages (installed via "apt install python3-dateutils")
is unexpected to me.

Maybe there is a good reason for that? Explain it please?
Maybe I did something wrong? How can I make it right?
Maybe it is a bug or a use case that is not covered by current version
of pipx or Debian 12?

> The second problem can be avoided because virtual environments exist
> in a part of the file system

Also here I assume I didn't make my problem clear enough.
I tried to install a library (from source) with "pipx". But it did not
work somehow (no clear error message). The global python interpreter
did not see that library.

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


Re: PEP668 / pipx and "--editable" installs

2023-09-18 Thread c.buhtz--- via Python-list
On 2023-09-18 10:16 "Peter J. Holzer via Python-list"
 wrote:
> On 2023-09-15 14:15:23 +, c.buhtz--- via Python-list wrote:
> > I tried to install it via "pipx install -e .[develop]". It's
> > pyproject.toml has a bug: A missing dependency "dateutil". But
> > "dateutil" is not available from PyPi for Python 3.11 (the default
> > in Debian 12). But thanks to great Debian they have a
> > "python3-dateutil" package. I installed it.
> 
> This can be installed via pip:

I'm aware of this. But this is not the question.

I would like to know and understand why my via "pipx" installed package
"hyperorg" is not able to see the systems packages installed via "apt
install python3-dateutils"?

Is this the usual behavior? Is this correct?
What is the design decision behind it?

Is it really the intention of PEP668 that pipx-installed packages are
not allowed to use system packages?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP668 / pipx and "--editable" installs

2023-09-20 Thread c.buhtz--- via Python-list

Dear Peter,

maybe we have a missunderstanding.

Am 20.09.2023 14:43 schrieb Peter J. Holzer via Python-list:

> > "dateutil" is not available from PyPi for Python 3.11


That's quite a curious thing to write if you are aware that dateutil is
in fact available from PyPi for Python 3.11.


Do I miss something here?

See https://pypi.org/project/dateutils/ and also the open Issue about 
the missing support for Python 3.11 
https://github.com/dateutil/dateutil/issues/1233 ?

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