Re: venv questions

2022-08-30 Thread Dennis Lee Bieber
On Mon, 29 Aug 2022 22:57:50 -0400, gene heskett 
declaimed the following:

>Greetings all;
>
>The command to setup a venv, "python -m venv venv" has no man page that 
>I have
>found.
>

https://docs.python.org/3/library/venv.html



-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make a variable's late binding crosses the module boundary?

2022-08-30 Thread dn
On 31/08/2022 05.26, Schachner, Joseph (US) wrote:
> The way we do this, is in main.py, call a "globalizer" function in each other 
> file:
> 
> # call globalizers to get shortcuts as global variables
> funcs.globalizer(interface, variable_dict)
> util.globalizer(interface, variable_dict)
> sd.globalizer(interface, variable_dict)
> tests.globalizer(interface, variable_dict)
> ut.globalizer(interface, variable_dict)
> 
> Obviously, you may not need a shared interface in which case you can just 
> pass the variable dictionary.
> 
> In each file, you have a function:
> def globalizer(interface, variables_dict):
> # create global variables for this .py file for shared interface and the 
> variables
> 
> 
> This works well, making sure separate python files shared exactly the same 
> things we want to be global.
> 
>  Joseph S.
> 
> Teledyne Confidential; Commercially Sensitive Business Data
> 
> -Original Message-
> From: Stefan Ram  
> Sent: Tuesday, August 30, 2022 1:09 AM
> To: python-list@python.org
> Subject: Re: How to make a variable's late binding crosses the module 
> boundary?
> 
> dn  writes:
>> Build module.py as:
>> ***
>> CONSTANT = 1
> 
>> def func():
>>pass
>> ***
> 
>> then in the terminal:
>> ***
>> Python 3.9.13 (main, May 18 2022, 00:00:00) [GCC 11.3.1 20220421 (Red 
>> Hat 11.3.1-2)] on linux Type "help", "copyright", "credits" or 
>> "license" for more information.
> from module import func as f
> 
>   In CPython one then can also:
> 
> print( f.__globals__[ "CONSTANT" ])
> import sys
> module = sys.modules[ f.__globals__[ "__name__" ]] print( module.CONSTANT ) 
> CONSTANT = module.CONSTANT print( CONSTANT )


The conversation seems to be wandering some way from the OP. Whereas
both of these answers are clever (and I assume work), the question
becomes: why would you want to do this? (especially as it looks ugly and
'smells' a bit convoluted). An example use-case from your experience?


Delving into the list-archive, to get back to the OP: the first message
in the thread quotes another message that's (apparently) not present.

However, in there somewhere is:

> from test import *

So, the elephant-in-the-room has always been a very stinky 'code-smell'
- which pretty much every text or web-tutorial will say is a bad idea.

Why is a bad idea?
Why is it there then?
When to use it?
[Socratic questioning]

Same question, but the other way around: why has Python been equipped
with modules, classes, functions, etc? To quote The Zen of Python:
"Namespaces are one honking great idea -- let's do more of those!".
Programming paradigms and architectural principles all contain reference
and recommendation to independent code-units, coupling and cohesion,
boundary crossing and interfaces (etc). Python doesn't enact a formal
interface construct (thank you great, high, Python, gods!), but that
doesn't remove the issues behind them (as the OP-code demonstrates).
Instead it requires a Python-idiomatic approach.

Should the question be: "how to I smash two namespaces into one and have
it work 'my way'?", or should the question become "how does Python
enable passing/retention of values between namespaces?".

NB The OP likely reduced the 'problem' to 'minimum-code' for the benefit
of the list, but what is the motivation behind it? Why would one want to
be able to do this? Rationale? Use-case?

Enquiring minds and all that...
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Download Python 3.10.6 for windows

2022-08-30 Thread Eryk Sun
On 8/30/22, George Rwaga  wrote:
>
> 1. I installed Python 3.10.6 in the default directory
> C:\Users\x.x\AppData\local\programs\Python\Python310
> After the installation, there was no shortcut on my desktop.

Shortcuts are created in the start menu. The installer doesn't modify
the user's desktop or the desktop of all users, which many users don't
want and would find annoying. Just copy the shortcuts from the start
menu to the desktop if that's what you want. Right-click the icon in
the start menu and choose to open the location. You can copy shortcuts
from the opened Explorer window.

> 2. I then decided to install Python3.10.6 in a customized directory
> C:\program files\Python\Python310
> I am being asked to verify access to this directly. I went to properties,
> made what I thought were the relevant changes. But I keep getting asked to
> verify access.

Installing to "Program Files" requires elevating to get administrator
access. All users have the right to read and execute files in a
directory created in "Program Files", but adding, removing, or
deleting files and directories requires administrator access, as it
should.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Running two separate servers (was Re: venv questions)

2022-08-30 Thread gene heskett

On 8/30/22 06:52, Chris Angelico wrote:

On Tue, 30 Aug 2022 at 19:51, gene heskett  wrote:

So I'm thinking of venv's named rock64prusa, and rock64ender5+, each with
"port#" on my local net. So chromium could have two tabs open, one to
localhost:5000 and one to localhost:5001, totally independent of each other.


As I said, that has absolutely nothing to do with venvs, so you'd have
to figure out how to change their port numbers independently.

(Although you could probably add an env var to the venv's activation
script, if that would help.)

ChrisA
The short script as /etc/default/octoprint has that PORT item. I see no 
reason it

couldn't be renamed and edited to affect the desired separation.
(venv) gene@rock64:~/printrun/Printrun/venv$ cat /etc/default/octoprint
==
# Configuration for /etc/init.d/octoprint

# The init.d script will only run if this variable non-empty.
OCTOPRINT_USER=gene

# base directory to use, change this for cura in both copies so cura can 
see it on the /sshnet

# make it unique and get rid of the dot.
BASEDIR=/home/gene/.octoprint

# configuration file to use, relocate this for uniqueness
CONFIGFILE=/home/gene/.octoprint/config.yaml

# On what port to run daemon, default is 5000, anything not it use for 
2nd ender5+ version

PORT=5000

# Path to the OctoPrint executable, you need to set this to match your 
installation!

# change the venv to a unique name
DAEMON=/home/gene/OctoPrint/venv/bin/octoprint

# What arguments to pass to octoprint, usually no need to touch this
DAEMON_ARGS="--port=$PORT"

# Umask of files octoprint generates, Change this to 000 if running 
octoprint as its own, separate user

UMASK=022

# Process priority, 0 here will result in a priority 20 process.
# -2 ensures Octoprint has a slight priority over user processes.
NICELEVEL=-2

# Should we run at startup?
START=yes
EOF

Edit two copies of this in defaults with individual names,

Edit 2 copies of /etc/init.d/octoprint with unique names

make two uniquely named venv's.

The two should never meet nor interfere with each other. So far, I've got
it running in a venv named prusa-mk3s. Now checking to see if it see's a
gcode file uploaded directly from cura here on this machine.

Short answer is no, octoprint cannot see an uploads directory in the 
prusa-mk3s directory.
In fact, it cannot see, or even create a new uploads directory. But I 
made one with mc, put
a gcode file there, not seen, got po'd and gave it 755 perms, bingo, it 
needed exec perms,
and cura wasn't setting them. Chalk up another bitch at cura. Or at 
octoprint, gcode is a text file

fur crying in the beer.  The rwXrwXrwX should not affect it IMO.

I need another batch of cable clips to neaten up the ender5+, so let me 
see if it can do that.
Now that I have the rules in hand, maybe I can make a second copy work 
at the same time.


IF I can figure out how to make it use a unique name for its PID identifier
.
Might have to change a character in the launchers name w/o changing the 
script. Or better yet,

rename the executable?

IDK. And hour lateer, cable clips went nice and clean, so the first 
instance is working fine.


And there isn't a PID for octoprint anyplace in /var unless its under 
the snakes umbrella.


Progress, discovering bugs and work-arounds in octoprint. Now I'm 
waiting on the mail for parts. Among other things a bigger PSU for the 
rock64. See if that reduces the video glitches from usb activity.


Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
 - Louis D. Brandeis
Genes Web page 

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


Re: Download Python 3.10.6 for windows

2022-08-30 Thread MRAB

On 2022-08-30 16:09, George Rwaga wrote:

I last installed an updated version of python more than  a year back. I am
trying to download (from  https://www.python.org/downloads/ ) and install
Python 3.10.6 for Windows - but I keep running into problems.

1. I installed Python 3.10.6 in the default directory
C:\Users\x.x\AppData\local\programs\Python\Python310
After the installation, there was no shortcut on my desktop. I thought I
would just go to Python310 and create a shortcut. But I am unable to find
AppData.


In the File Explorer window, select the View tab and turn on the Hidden 
Items checkbox. The AppData folder should then become visible.


Alternatively, enter "%appdata%" in the path bar, and that should take 
you to a subfolder of the AppData folder. You can then navigate from there.



2. I then decided to install Python3.10.6 in a customized directory
C:\program files\Python\Python310
I am being asked to verify access to this directly. I went to properties,
made what I thought were the relevant changes. But I keep getting asked to
verify access.

My R and RStudio are installed in C:\program files.

How should I proceed?



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


Re: Coffee

2022-08-30 Thread Michael F. Stemper

On 29/08/2022 07.16, Stefan Ram wrote:

|Python's obviously a great tool for all kinds of programming things,
|and I would say if you're only gonna use one programming
|language in your live, Python will probably the right one.
Brian Kernighan

   I transcribed this from the recent video
   "Coffee with Brian Kernighan".


For those who'd like to see the whole chat:


--
Michael F. Stemper
Deuteronomy 24:17
--
https://mail.python.org/mailman/listinfo/python-list


Download Python 3.10.6 for windows

2022-08-30 Thread George Rwaga
I last installed an updated version of python more than  a year back. I am
trying to download (from  https://www.python.org/downloads/ ) and install
Python 3.10.6 for Windows - but I keep running into problems.

1. I installed Python 3.10.6 in the default directory
C:\Users\x.x\AppData\local\programs\Python\Python310
After the installation, there was no shortcut on my desktop. I thought I
would just go to Python310 and create a shortcut. But I am unable to find
AppData.
2. I then decided to install Python3.10.6 in a customized directory
C:\program files\Python\Python310
I am being asked to verify access to this directly. I went to properties,
made what I thought were the relevant changes. But I keep getting asked to
verify access.

My R and RStudio are installed in C:\program files.

How should I proceed?

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


RE: How to make a variable's late binding crosses the module boundary?

2022-08-30 Thread Schachner, Joseph (US)
The way we do this, is in main.py, call a "globalizer" function in each other 
file:

# call globalizers to get shortcuts as global variables
funcs.globalizer(interface, variable_dict)
util.globalizer(interface, variable_dict)
sd.globalizer(interface, variable_dict)
tests.globalizer(interface, variable_dict)
ut.globalizer(interface, variable_dict)

Obviously, you may not need a shared interface in which case you can just pass 
the variable dictionary.

In each file, you have a function:
def globalizer(interface, variables_dict):
# create global variables for this .py file for shared interface and the 
variables


This works well, making sure separate python files shared exactly the same 
things we want to be global.

 Joseph S.

Teledyne Confidential; Commercially Sensitive Business Data

-Original Message-
From: Stefan Ram  
Sent: Tuesday, August 30, 2022 1:09 AM
To: python-list@python.org
Subject: Re: How to make a variable's late binding crosses the module boundary?

dn  writes:
>Build module.py as:
>***
>CONSTANT = 1

>def func():
>pass
>***

>then in the terminal:
>***
>Python 3.9.13 (main, May 18 2022, 00:00:00) [GCC 11.3.1 20220421 (Red 
>Hat 11.3.1-2)] on linux Type "help", "copyright", "credits" or 
>"license" for more information.
 from module import func as f

  In CPython one then can also:

print( f.__globals__[ "CONSTANT" ])
import sys
module = sys.modules[ f.__globals__[ "__name__" ]] print( module.CONSTANT ) 
CONSTANT = module.CONSTANT print( CONSTANT )

  .


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


[Python-announce] rounder: A Python package for rounding numbers in complex objects

2022-08-30 Thread Marcin Kozak
Hi all!

When you work with numbers and need to print them, more often than not you
want to round them. You can use the built-in round() function:
>>> round(1.123, 2)
1.12
>>> x = [1.123, 44.32, 12.11234]
>>> [round(x_i, 2) for x_i in x]
[ 1.12, 44.32, 12.11]

However, when you want to round numbers in a more complex Python object,
you need to be careful; you may also need to write a dedicated function to
round numbers in this object, and you may need to update it if the object's
structure changes.

Now, you do not need to do that: use the rounder Python package instead. It
will round numbers in any non-nested or nested Python object, using the
following functions:
* round_object(obj, digits), which rounds numbers in the object to a
provided number of decimal digits
* ceil_object(obj), which rounds numbers up to the nearest integer
* floor_object(obj), which rounds numbers down to the nearest integer
* signif_object(obj, digits), which rounds numbers to a number of
significant digits

So, for example:

>>> obj = {'float': 1.345442, 'list': [1.1222, 1.1226, "string"], 'set':
{1.1222, 1.1226}, 'tuple': (1.1222, 1.1226)}
>>> round_object(obj, 2)
{'float': 1.35, 'list': [1.12, 1.12, "string"], 'set': {1.12}, 'tuple':
(1.12, 1.12)}
>>> signif_object(obj, 3)
{'float': 1.35, 'list': [1.12, 1.12, "string"], 'set': {1.12}, 'tuple':
(1.12, 1.12)}

The package offers also two other functions:
* signif(x, digits), to round a number to significant digits
* map_object(map_function, obj, use_copy=False)

The latter function is a generalized function that applies callable
map_function to all numbers in obj. Consider this simplistic example:
>>> map_object(lambda x: x**2, {'a': 3, 'b': [1, 2, 3]})
{'a': 9, 'b': [1, 4, 9]}

The package works with objects of many different types, not only those
shown above. It works under both Windows and Linux. You can install it from
PyPi:
$ pip install rounder

You will learn more about it from its GitHub repo:
https://github.com/nyggus/rounder.

Happy rounding!

Pozdrawiam,
Marcin
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


Re: Running two separate servers (was Re: venv questions)

2022-08-30 Thread Chris Angelico
On Tue, 30 Aug 2022 at 19:51, gene heskett  wrote:
> So I'm thinking of venv's named rock64prusa, and rock64ender5+, each with
> "port#" on my local net. So chromium could have two tabs open, one to
> localhost:5000 and one to localhost:5001, totally independent of each other.
>

As I said, that has absolutely nothing to do with venvs, so you'd have
to figure out how to change their port numbers independently.

(Although you could probably add an env var to the venv's activation
script, if that would help.)

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


Re: Running two separate servers (was Re: venv questions)

2022-08-30 Thread gene heskett

On 8/29/22 23:22, Chris Angelico wrote:

On Tue, 30 Aug 2022 at 12:59, gene heskett  wrote:

But that might create another problem. how to differentiate the servers,
both of which
will want to use localhost:5000 to serve up their web pages we run
things with.

Suggested solutions?

This is nothing to do with venvs, so I'm forking the thread.

By far the easiest way to differentiate them is to NOT have them both
on localhost:5000. Depending on how you invoke the servers, you should
be able to find a way to configure one (or both) of them to a
different port; common methods include a "--port" argument, setting
the PORT environment variable, and poking in the code to find the
number 5000 and changing it to some other value.

(Less common methods include poking in ctypes to find the number 5000
and changing it to some other value. Mentioned only because I realise
the alternative interpretation of my previous comment.)

Another method would be to change the "localhost" part. The standard
for IP addresses is that 127.x.y.z means localhost, regardless of what
x, y, and z are; so you could have one of them bind to 127.0.0.2 and
the other to 127.0.0.3, which you could then use in your browser the
same way (http://127.0.0.2:5000/ and http://127.0.0.3:5000/
respectively).

But if you can't change anything else, you'll have to make the two
processes cooperate in some way, or worst case, just make sure you
shut one down before you start the other up.

ChrisA

That is a limitation I'd druther not have to deal with Chris. I want two
separate octoprint servers running with no interaction between them.

So I'm thinking of venv's named rock64prusa, and rock64ender5+, each with
"port#" on my local net. So chromium could have two tabs open, one to
localhost:5000 and one to localhost:5001, totally independent of each other.

I already have that in my /etc/hosts file. No dns resolving involved.

And from snooping just now, the port # is set it /etc/default/octoprint, 
so copy
/etc/default/octoprint to octoprint-prusa, and to octoprint-ender5+, do 
the same in
/etc/init.d, and change the port # & venv name  in the -ender5+ version. 
Then

reconfigure the ender5+ version to drive that printer.

With the venv isolation, it should work, with a browser tab at 
localhost:5000 and
another tab at localhost:5001, each pointing at its own directory tree 
in /home/gene.


The separation is also because of the way linux finds usb facilities, the
prusa is always /dev/ttyACM0 and the ender5+ is almost always /dev/ttyUSB0.
in this case I've a 4 port usb hub with port disabling switches plugged
into the rock64.

One of the things I want to try is plugging in a startech usb3 to sata 
adapter

with a small SSD plugged into it, and move the /tmp directory off that poor
u-sd card to prolong its life.

And each with its own input buffer that cura can see from here. The new 
cura 5.1
has its own set of problems, not being able to see octoprints defaulted 
input buffer
hidden behind a dotted directory being a starter, toss in that it has no 
way to look at
.. and that requires a user session of mc just to move the gcode 
produced to be printed

from a local dir here to the input buffer of that instance of octoprint.

Back at this come daylight.  Thank you Chris.

Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
 - Louis D. Brandeis
Genes Web page 

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