Re: Windows installer from python source code without access to source code

2023-03-31 Thread 2QdxY4RzWzUUiLuE
On 2023-04-01 at 10:49:18 +1100,
Chris Angelico  wrote:

> [...] I don't have access to the Gmail source code but I'm using the
> service [...]

You have access to Gmail's front end source code.  Your web browser runs
it every time you use the service (and probably while you aren't using
the service, too).  My educated guess is that Google expended some
effort to hinder you from looking at and/or analyzing (or do you say
analysing?) that code, and that their lawyers will come knocking at your
metaphorical door if they so much as think you are using that code in
some way other than running it inside your web browser.  If only this
situation were a cruel April Fool's Day joke.

You don't have access to Gmail's back end source code.

Many/Most web apps follow this pattern to varying degrees.  I do not
know whether this setup meets the OP's requirements.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError

2023-03-31 Thread Chris Angelico
On Sat, 1 Apr 2023 at 11:42, Clint Olsen  wrote:
>
> On Friday, March 31, 2023 at 4:14:51 PM UTC-7, Chris Angelico wrote:
> > Okay, so that deals with the part from the subject line, leaving a
> > slightly different problem: The caught exception is not of the same
> > type as you were expecting. First question: Can you reproduce the
> > issue on command? If so, I would recommend trying this:
> >
> > except BaseException as e:
> > print("Got an exception!", type(e))
> > print(id(type(e)))
> > print(id(asyncio.CancelledError)
> > except:
> > print("Weird things are happening")
> > import sys
> > print(sys.exc_info())
> > print(id(sys.exc_info()[0]))
> > print(id(asyncio.CancelledError))
> >
> > Basically, I want to know whether (a) BaseException has changed, which
> > would be a nightmare; and (b) whether asyncio.CancelledError has
> > changed.
> >
> > This is the kind of bizarre behaviour that can happen if a module is
> > reloaded, or if there are multiple versions loaded for some reason.
> > But if that ISN'T what's happening, there'll have to be some other
> > explanation.
>
> Here's what I see:
>
> Got an exception! 
> 8204064
> 8204064
>

Can you confirm that it is indeed failing to catch the exception? Try this:

except asyncio.CancelledError:
print("Cancelled correctly")

followed by the same type checking from above. Since the ID is the
same, I would expect it to match!

Can you post a full runnable example that exhibits the problem?

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


Re: built-in pow() vs. math.pow()

2023-03-31 Thread Oscar Benjamin
On Fri, 31 Mar 2023 at 20:24, Peter J. Holzer  wrote:
>
> On 2023-03-31 07:39:25 +0100, Barry wrote:
> > On 30 Mar 2023, at 22:30, Chris Angelico  wrote:
> > > It's called math.pow. That on its own should be a strong indication
> > > that it's designed to work with floats.
> >
> > So long as you know that the math module is provided to give access
> > the C math.h functions.
> >
>
> Well, that's the first line in the docs:
>
> | This module provides access to the mathematical functions defined by
> | the C standard.
>
> Of course a Python programmer may not necessarily know what mathematical
> functions the C standard defines or even what C is.

Or they might know that and might also realise that it is not really
an accurate description of Python's math module e.g. math.factorial,
math.gcd, math.isqrt which are all integer functions. How many of
these 60 names are defined by the C standard:

In [6]: dir(math)
Out[6]:
['__doc__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 'acos',
 'acosh',
 'asin',
 'asinh',
 'atan',
 'atan2',
 'atanh',
 'ceil',
 'comb',
 'copysign',
 'cos',
 'cosh',
 'degrees',
 'dist',
 'e',
 'erf',
 'erfc',
 'exp',
 'expm1',
 'fabs',
 'factorial',
 'floor',
 'fmod',
 'frexp',
 'fsum',
 'gamma',
 'gcd',
 'hypot',
 'inf',
 'isclose',
 'isfinite',
 'isinf',
 'isnan',
 'isqrt',
 'ldexp',
 'lgamma',
 'log',
 'log10',
 'log1p',
 'log2',
 'modf',
 'nan',
 'perm',
 'pi',
 'pow',
 'prod',
 'radians',
 'remainder',
 'sin',
 'sinh',
 'sqrt',
 'tan',
 'tanh',
 'tau',
 'trunc']

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


Re: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError

2023-03-31 Thread Clint Olsen
On Friday, March 31, 2023 at 4:14:51 PM UTC-7, Chris Angelico wrote:
> Okay, so that deals with the part from the subject line, leaving a 
> slightly different problem: The caught exception is not of the same 
> type as you were expecting. First question: Can you reproduce the 
> issue on command? If so, I would recommend trying this: 
> 
> except BaseException as e: 
> print("Got an exception!", type(e)) 
> print(id(type(e))) 
> print(id(asyncio.CancelledError) 
> except: 
> print("Weird things are happening") 
> import sys 
> print(sys.exc_info()) 
> print(id(sys.exc_info()[0])) 
> print(id(asyncio.CancelledError)) 
> 
> Basically, I want to know whether (a) BaseException has changed, which 
> would be a nightmare; and (b) whether asyncio.CancelledError has 
> changed. 
> 
> This is the kind of bizarre behaviour that can happen if a module is 
> reloaded, or if there are multiple versions loaded for some reason. 
> But if that ISN'T what's happening, there'll have to be some other 
> explanation. 

Here's what I see:

Got an exception! 
8204064
8204064

Thanks,

-Clint

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


Re: Windows installer from python source code without access to source code

2023-03-31 Thread Chris Angelico
On Sat, 1 Apr 2023 at 10:34, Jim Schwartz  wrote:
>
> Yea. You’re right. I probably need a lawyer someday. Thanks.
>

If your needs are basic, you shouldn't need a lawyer. Copyright law
and treaties DO protect you. But it's important to be aware that no
amount of legal protection - whether you hire a lawyer or not, and
whether you identify copyright and license or not - will stop people
from copying your code. NOTHING will stop people from copying your
code if they have access to it. All you can do is discourage them.

So that brings us back to the original question: Why protect your
*source code* specifically? There are two extremes available to
everyone:

1) Distribute the source code. Let everyone see it. Stick a license on
it that permits them to use it, modify it, distribute modified
versions. Set your code free and let it be used.

2) Don't distribute the program *at all*. Don't distribute the source
OR the binary. Instead, permit people to *access* the program - which,
in today's world, usually means a web service.

Both of these are very popular and work well. I don't have access to
the Gmail source code but I'm using the service. I don't have access
to the Twitch.tv source code but I'm using the service. Meanwhile, I
have Python programs running on a Debian system using the Linux
kernel, invoked using bash, served from an ext4 mass storage device,
etc, etc. I have the binary code for all of these, and I'm legally
guaranteed access to the source if I want it, so there's no incentive
to steal it.

The middle ground of "distribute binaries but stop people from
accessing the source" is a much narrower use-case, and I would say
that it's not actually a single use-case but a family of them, each
with different needs and requirements. So it's essential to know what
you're actually trying to protect, and why.

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


Re: Windows installer from python source code without access to source code

2023-03-31 Thread Jim Schwartz
Yea. You’re right. I probably need a lawyer someday. Thanks. 

Sent from my iPhone

> On Mar 31, 2023, at 5:12 PM, Thomas Passin  wrote:
> 
> On 3/31/2023 5:16 PM, Jim Schwartz wrote:
>> What license do I have to choose so people can't use my code?  I don't know
>> this stuff.
> 
> It would help if you would explain what you want to accomplish and why. Do 
> you expect to make money off your software?  If not, why do want so badly to 
> protect it?
> 
> The most basic answer is that your code is automatically protected by 
> copyright law unless you say differently.  But it is still a good idea to 
> state outright what actions would be allowed and what would be forbidden.
> 
> If you do expect to make money, you could look at what phone apps developers 
> include with their apps.  And it would be good to consult a lawyer who 
> practices in this field.
> 
> 
>> -Original Message-
>> From: Python-list  On
>> Behalf Of Chris Angelico
>> Sent: Friday, March 31, 2023 7:09 AM
>> To: python-list@python.org
>> Subject: Re: Windows installer from python source code without access to
>> source code
>>> On Fri, 31 Mar 2023 at 23:01, Jim Schwartz  wrote:
>>> 
>>> I want a windows installer to install my application that's written in
>>> python, but I don't want the end user to have access to my source code.
>>> 
>>> 
>>> 
>>> Is that possible using python?  I was using cx-freeze, but that has
>>> the source code available.  So does pyinstaller.  I think gcc does, too.
>>> 
>>> 
>>> 
>>> Does anyone know of a way to do this?
>>> 
>> Fundamentally no, it's not. Python code will always be distributed as some
>> form of bytecode. The only way to make it available without revealing
>> anything is to put it on a server and let people access it without running
>> it themselves.
>> But why is that a problem? Copyright law protects you from people stealing
>> your code and making unauthorized changes to it, and if you're not worried
>> about them making changes, there's no reason to hide the source code
>> (whatever you distribute would be just as copiable). Are you concerned that
>> people will see your bugs? We all have them.
>> ChrisA
>> --
>> https://mail.python.org/mailman/listinfo/python-list
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError

2023-03-31 Thread Chris Angelico
On Sat, 1 Apr 2023 at 10:05, Clint Olsen  wrote:
>
> On Friday, March 31, 2023 at 3:23:24 PM UTC-7, Chris Angelico wrote:
> > On Sat, 1 Apr 2023 at 09:19, Clint Olsen  wrote:
> > > Attempting to catch asyncio.CancelledError or asyncio.CancelledError does 
> > > not work. The function in question looks like:
> > >>> asyncio.exceptions.CancelledError is asyncio.CancelledError
> > True
> >
> > Does that answer the question?
>
> No, I couldn't catch either exception even though they are the same.
>

Okay, so that deals with the part from the subject line, leaving a
slightly different problem: The caught exception is not of the same
type as you were expecting. First question: Can you reproduce the
issue on command? If so, I would recommend trying this:

except BaseException as e:
print("Got an exception!", type(e))
print(id(type(e)))
print(id(asyncio.CancelledError)
except:
print("Weird things are happening")
import sys
print(sys.exc_info())
print(id(sys.exc_info()[0]))
print(id(asyncio.CancelledError))

Basically, I want to know whether (a) BaseException has changed, which
would be a nightmare; and (b) whether asyncio.CancelledError has
changed.

This is the kind of bizarre behaviour that can happen if a module is
reloaded, or if there are multiple versions loaded for some reason.
But if that ISN'T what's happening, there'll have to be some other
explanation.

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


Re: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError

2023-03-31 Thread Clint Olsen
On Friday, March 31, 2023 at 3:23:24 PM UTC-7, Chris Angelico wrote:
> On Sat, 1 Apr 2023 at 09:19, Clint Olsen  wrote: 
> > Attempting to catch asyncio.CancelledError or asyncio.CancelledError does 
> > not work. The function in question looks like: 
> >>> asyncio.exceptions.CancelledError is asyncio.CancelledError 
> True 
> 
> Does that answer the question? 

No, I couldn't catch either exception even though they are the same.

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


Re: Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError

2023-03-31 Thread Chris Angelico
On Sat, 1 Apr 2023 at 09:19, Clint Olsen  wrote:
>
> I'm having some issues with task cancellation inside a signal handler. My 
> tasks do get cancelled, but I see odd behavior:
>
> Traceback (most recent call last):
>   File 
> "/home/utils/release/sw/tools/python-3.9.7/lib/python3.9/site-packages/grpc/aio/_call.py",
>  line 406, in _consume_request_iterator
> async for request in request_iterator:
>   File "/home/foo/lib/python/rush/client.py", line 105, in send_status
> status = await sendq.get()
>   File 
> "/home/utils/Python/3.9/3.9.7-20211101/lib/python3.9/asyncio/queues.py", line 
> 166, in get
> await getter
> asyncio.exceptions.CancelledError: Client killed with signal 2
>
> Attempting to catch asyncio.CancelledError or asyncio.CancelledError does not 
> work. The function in question looks like:
>
> 101 async def send_status():
> 102 while True:
> 103 logging.info('Waiting for sendq')
> 104 try:
> 105 status = await sendq.get()
> 106
> 107 if not status:
> 108 break
> 109
> 110 logging.info(f'Sendq status {status}')
> 111
> 112 message = rush_pb2.Status(**status)
> 113 yield message
> 114 except asyncio.exceptions.CancelledError as err:
> 115 logging.error(f'Weird error {err}')
> 116 #raise asyncio.CancelledError
> 117 break
>
> If I use "except:" it does catch this exception.
>
> What's going on here?
>

>>> asyncio.exceptions.CancelledError is asyncio.CancelledError
True

Does that answer the question?

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


Re: When is logging.getLogger(__name__) needed?

2023-03-31 Thread dn via Python-list

On 01/04/2023 02.01, Loris Bennett wrote:

Hi,

In my top level program file, main.py, I have

   def main_function():

   parser = argparse.ArgumentParser(description="my prog")

   ...

   args = parser.parse_args()
   config = configparser.ConfigParser()

   if args.config_file is None:
   config_file = DEFAULT_CONFIG_FILE
   else:
   config_file = args.config_file

   config.read(config_file)

   logging.config.fileConfig(fname=config_file)
   logger = logging.getLogger(__name__)

   do_some_stuff()
   
   my_class_instance = myprog.MyClass()


   def do_some_stuff():

   logger.info("Doing stuff")

This does not work, because 'logger' is not known in the function
'do_some_stuff'.

However, if in 'my_prog/my_class.py' I have

   class MyClass:

   def __init__(self):

   logger.debug("created instance of MyClass")

this 'just works'.

I can add

   logger = logging.getLogger(__name__)

to 'do_some_stuff', but why is this necessary in this case but not in
the class?

Or should I be doing this entirely differently?


Yes: differently.

To complement @Peter's response, two items for consideration:

1 once main_function() has completed, have it return logger and other 
such values/constructs. The target-identifiers on the LHS of the 
function-call will thus be within the global scope.


2 if the purposes of main_function() are condensed-down to a few 
(English, or ..., language) phrases, the word "and" will feature, eg

- configure env according to cmdLN args,
- establish log(s),
- do_some_stuff(),  ** AND **
- instantiate MyClass.

If these (and do_some_stuff(), like MyClass' methods) were split into 
separate functions* might you find it easier to see them as separate 
sub-solutions? Each sub-solution would be able to contribute to the 
whole - the earlier ones as creating (outputting) a description, 
constraint, or basis; which becomes input to a later function/method.



* there is some debate amongst developers about whether "one function, 
one purpose" should be a rule, a convention, or tossed in the trash. YMMV!


Personal view: SOLID's "Single" principle applies: there should be only 
one reason (hanging over the head of each method/function, like the 
Sword of Damocles) for it to change - or one 'user' who could demand a 
change to that function. In other words, an updated cmdLN option 
shouldn't affect a function which establishes logging, for example.



Web.Refs:
https://people.engr.tamu.edu/choe/choe/courses/20fall/315/lectures/slide23-solid.pdf
https://www.hanselminutes.com/145/solid-principles-with-uncle-bob-robert-c-martin
https://idioms.thefreedictionary.com/sword+of+Damocles
https://en.wikipedia.org/wiki/Damocles

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Python 3.9 asyncio: Task cancel() throws asyncio.exceptions.CancelledError instead of asyncio.CancelledError

2023-03-31 Thread Clint Olsen
I'm having some issues with task cancellation inside a signal handler. My tasks 
do get cancelled, but I see odd behavior:

Traceback (most recent call last):
  File 
"/home/utils/release/sw/tools/python-3.9.7/lib/python3.9/site-packages/grpc/aio/_call.py",
 line 406, in _consume_request_iterator
async for request in request_iterator:
  File "/home/foo/lib/python/rush/client.py", line 105, in send_status
status = await sendq.get()
  File "/home/utils/Python/3.9/3.9.7-20211101/lib/python3.9/asyncio/queues.py", 
line 166, in get
await getter
asyncio.exceptions.CancelledError: Client killed with signal 2

Attempting to catch asyncio.CancelledError or asyncio.CancelledError does not 
work. The function in question looks like:

101 async def send_status():
102 while True:
103 logging.info('Waiting for sendq')
104 try:
105 status = await sendq.get()
106
107 if not status:
108 break
109
110 logging.info(f'Sendq status {status}')
111
112 message = rush_pb2.Status(**status)
113 yield message
114 except asyncio.exceptions.CancelledError as err:
115 logging.error(f'Weird error {err}')
116 #raise asyncio.CancelledError
117 break

If I use "except:" it does catch this exception.

What's going on here?

Thanks,

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


Re: Windows installer from python source code without access to source code

2023-03-31 Thread Thomas Passin

On 3/31/2023 5:16 PM, Jim Schwartz wrote:

What license do I have to choose so people can't use my code?  I don't know
this stuff.


It would help if you would explain what you want to accomplish and why. 
Do you expect to make money off your software?  If not, why do want so 
badly to protect it?


The most basic answer is that your code is automatically protected by 
copyright law unless you say differently.  But it is still a good idea 
to state outright what actions would be allowed and what would be forbidden.


If you do expect to make money, you could look at what phone apps 
developers include with their apps.  And it would be good to consult a 
lawyer who practices in this field.




-Original Message-
From: Python-list  On
Behalf Of Chris Angelico
Sent: Friday, March 31, 2023 7:09 AM
To: python-list@python.org
Subject: Re: Windows installer from python source code without access to
source code

On Fri, 31 Mar 2023 at 23:01, Jim Schwartz  wrote:


I want a windows installer to install my application that's written in
python, but I don't want the end user to have access to my source code.



Is that possible using python?  I was using cx-freeze, but that has
the source code available.  So does pyinstaller.  I think gcc does, too.



Does anyone know of a way to do this?



Fundamentally no, it's not. Python code will always be distributed as some
form of bytecode. The only way to make it available without revealing
anything is to put it on a server and let people access it without running
it themselves.

But why is that a problem? Copyright law protects you from people stealing
your code and making unauthorized changes to it, and if you're not worried
about them making changes, there's no reason to hide the source code
(whatever you distribute would be just as copiable). Are you concerned that
people will see your bugs? We all have them.

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



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


RE: Windows installer from python source code without access to source code

2023-03-31 Thread Jim Schwartz
What license do I have to choose so people can't use my code?  I don't know
this stuff.

-Original Message-
From: Python-list  On
Behalf Of Chris Angelico
Sent: Friday, March 31, 2023 7:09 AM
To: python-list@python.org
Subject: Re: Windows installer from python source code without access to
source code

On Fri, 31 Mar 2023 at 23:01, Jim Schwartz  wrote:
>
> I want a windows installer to install my application that's written in 
> python, but I don't want the end user to have access to my source code.
>
>
>
> Is that possible using python?  I was using cx-freeze, but that has 
> the source code available.  So does pyinstaller.  I think gcc does, too.
>
>
>
> Does anyone know of a way to do this?
>

Fundamentally no, it's not. Python code will always be distributed as some
form of bytecode. The only way to make it available without revealing
anything is to put it on a server and let people access it without running
it themselves.

But why is that a problem? Copyright law protects you from people stealing
your code and making unauthorized changes to it, and if you're not worried
about them making changes, there's no reason to hide the source code
(whatever you distribute would be just as copiable). Are you concerned that
people will see your bugs? We all have them.

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

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


Re: Python not showing correct version

2023-03-31 Thread Eryk Sun
On 3/31/23, Thomas Passin  wrote:
>
> The store app doesn't install py.exe, does it?

That's a significant downside of the store app. You can install Python
3.7-3.11 from the store, and run them explicitly as "python3.7.exe",
"pip3.7.exe", "python3.11.exe", "pip3.11.exe", etc. But without the
launcher there's no shebang support for scripts, so you can't easily
associate a script with a particular Python version or a particular
virtual environment. Shell shortcuts/links (.LNK files) can work
around the lack of shebang support (add .LNK to the PATHEXT
environment variable). But having to create a separate shell link is
inconvenient, and it's not cross-platform.

The OP installed the standard Python 3.8 distribution, which does
install the launcher by default. The launcher can run all installed
versions, including store app installations. By default it runs the
highest available version, which will probably be the 3.10 store app
in the OP's case. To make 3.8 the default without having to remove
3.10, set the environment variables "PY_PYTHON=3.8" and
"PY_PYTHON3=3.8" in the user environment.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python not showing correct version

2023-03-31 Thread Thomas Passin

On 3/31/2023 2:18 PM, Eryk Sun wrote:

On 3/31/23, Sumeet Firodia  wrote:


One more thing is that pip --version also refers to python 3.10

C:\Users\admin>pip --version
pip 23.0.1 from
C:\Users\admin\AppData\Local\Packages
\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0
\LocalCache\local-packages\Python310\site-packages\pip
(python 3.10)


You're running pip from the store app distribution of Python 3.10.
Your settings have the store app set as the default for the "python"
and "pip" commands. To change this, open the system settings for "App
execution aliases" and disable the "python.exe", "pythonw.exe", and
"pip.exe" aliases. You might have to also disable the alias for
"python3.exe" if it's causing problems (e.g. if you don't want a
shebang like "#!/usr/bin/env python3" to run the store app). It
shouldn't cause problems to leave the "python3.10.exe" and
"pip3.10.exe" aliases enabled.


Ha! The store app doesn't install py.exe, does it?  I forgot about that 
as a possibility, because I've always stayed away from store apps. If it 
were me, I'd uninstall the store app and get an installer from python.org.


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


Re: built-in pow() vs. math.pow()

2023-03-31 Thread Peter J. Holzer
On 2023-03-31 07:39:25 +0100, Barry wrote:
> On 30 Mar 2023, at 22:30, Chris Angelico  wrote:
> > It's called math.pow. That on its own should be a strong indication
> > that it's designed to work with floats.
> 
> So long as you know that the math module is provided to give access
> the C math.h functions.
> 

Well, that's the first line in the docs:

| This module provides access to the mathematical functions defined by
| the C standard.

Of course a Python programmer may not necessarily know what mathematical
functions the C standard defines or even what C is.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python not showing correct version

2023-03-31 Thread Eryk Sun
On 3/31/23, Sumeet Firodia  wrote:
>
> One more thing is that pip --version also refers to python 3.10
>
> C:\Users\admin>pip --version
> pip 23.0.1 from
> C:\Users\admin\AppData\Local\Packages
> \PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0
> \LocalCache\local-packages\Python310\site-packages\pip
> (python 3.10)

You're running pip from the store app distribution of Python 3.10.
Your settings have the store app set as the default for the "python"
and "pip" commands. To change this, open the system settings for "App
execution aliases" and disable the "python.exe", "pythonw.exe", and
"pip.exe" aliases. You might have to also disable the alias for
"python3.exe" if it's causing problems (e.g. if you don't want a
shebang like "#!/usr/bin/env python3" to run the store app). It
shouldn't cause problems to leave the "python3.10.exe" and
"pip3.10.exe" aliases enabled.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows installer from python source code without access to source code

2023-03-31 Thread Eryk Sun
On 3/31/23, Jim Schwartz  wrote:
> I want a windows installer to install my application that's written in
> python, but I don't want the end user to have access to my source code.

Cython can compile a script to C source code for a module or
executable (--embed). The source can be compiled and linked normally.
For example, the following builds a "hello.exe" executable based on a
"hello.py" script.

> cython -3 --embed hello.py
> set "PYI=C:\Program Files\Python311\include"
> set "PYL=C:\Program Files\Python311\libs"
> cl /I"%PYI%" hello.c /link /libpath:"%PYL%"
> copy hello.exe embed
> embed\hello.exe
Hello, World!

I extracted the complete embeddable distribution of Python 3.11 into
the "embed" directory. You can reduce the size of the installation, if
needed, by minimizing the zipped standard library and removing pyd
extensions and DLLs that your application doesn't use.

The generated "hello.c" is large and not particularly easy to read,
but here are some snippets [...]:

[...]
/* Implementation of 'hello' */
static PyObject *__pyx_builtin_print;
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_print[] = "print";
static const char __pyx_k_Hello_World[] = "Hello, World!";
[...]
  /* "hello.py":1
 * print("Hello, World!") # <<
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Hello_World);
if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error)
[...]
  /* "hello.py":1
 * print("Hello, World!") # <<
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_,
  NULL);
if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
[...]
int wmain(int argc, wchar_t **argv) {
[...]
if (argc && argv)
Py_SetProgramName(argv[0]);
Py_Initialize();
if (argc && argv)
PySys_SetArgv(argc, argv);
[...]
  m = PyInit_hello();
[...]
if (Py_FinalizeEx() < 0)
return 2;
[...]
return 0;
[...]
-- 
https://mail.python.org/mailman/listinfo/python-list


[Python-announce] python-oracledb 1.3.0

2023-03-31 Thread Anthony Tuininga
What is python-oracledb?

python-oracledb is a Python extension module that enables access to Oracle
Database for Python and conforms to the Python database API 2.0
specifications with a number of enhancements. This module is intended to
eventually replace cx_Oracle.

Where do I get it?

https://pypi.org/project/oracledb/1.3.0/

The easiest method to install/upgrade python-oracledb is via pip as in

python -m pip install oracledb --upgrade

What's new?

This release adds support for binding and fetching data of type
oracledb.DB_TYPE_JSON in thin mode. It also addresses a large number of
smaller enhancements and bug fixes.

See the full release notes for all of the details:
https://python-oracledb.readthedocs.io/en/latest/release_notes.html#oracledb-1-3-0-march-2023

Please provide any feedback via GitHub issues:
https://github.com/oracle/python-oracledb/issues or discussions:
https://github.com/oracle/python-oracledb/discussions
___
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: Windows installer from python source code without access to source code

2023-03-31 Thread Alan Gauld
On 31/03/2023 13:00, Jim Schwartz wrote:
> I want a windows installer to install my application that's written in
> python, but I don't want the end user to have access to my source code.  

Others have commented that at some level it will always be thre but on a
more pragmatic level tools like py2exe bundle up a Python app as an exe
file which might be all you need?

I'm sure if a user dug deep enough they could still find the source (or
something close) but to deter casual browsing it might be what you want.

Caveat: I've never used py2exe in anger and my experiements were before
Python3 so ive no idea what it does today! But a quick check suggests it
still exists and works with python3 code - last major release was in Nov
2022.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: When is logging.getLogger(__name__) needed?

2023-03-31 Thread Peter Otten

On 31/03/2023 15:01, Loris Bennett wrote:

Hi,

In my top level program file, main.py, I have

   def main_function():

   parser = argparse.ArgumentParser(description="my prog")

   ...

   args = parser.parse_args()
   config = configparser.ConfigParser()

   if args.config_file is None:
   config_file = DEFAULT_CONFIG_FILE
   else:
   config_file = args.config_file

   config.read(config_file)

   logging.config.fileConfig(fname=config_file)
   logger = logging.getLogger(__name__)

   do_some_stuff()

   my_class_instance = myprog.MyClass()

   def do_some_stuff():

   logger.info("Doing stuff")

This does not work, because 'logger' is not known in the function
'do_some_stuff'.

However, if in 'my_prog/my_class.py' I have

   class MyClass:

   def __init__(self):

   logger.debug("created instance of MyClass")

this 'just works'.


Take another look at your code -- you'll probably find


   logger = logging.getLogger(__name__)


on the module level in my_class.py.


to 'do_some_stuff', but why is this necessary in this case but not in
the class?


Your problem has nothing to do with logging -- it's about visibility
("scope") of names:

>>> def use_name():
print(name)


>>> def define_name():
name = "Loris"


>>> use_name()
Traceback (most recent call last):
  File "", line 1, in 
use_name()
  File "", line 2, in use_name
print(name)
NameError: name 'name' is not defined

Binding (=assigning to) a name inside a function makes it local to that
function. If you want a global (module-level) name you have to say so:

>>> def define_name():
global name
name = "Peter"


>>> define_name()
>>> use_name()
Peter

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


Re: Windows installer from python source code without access to source code

2023-03-31 Thread Thomas Passin

On 3/31/2023 10:14 AM, jkn wrote:

On Friday, March 31, 2023 at 1:09:12 PM UTC+1, Chris Angelico wrote:

On Fri, 31 Mar 2023 at 23:01, Jim Schwartz  wrote:


I want a windows installer to install my application that's written in
python, but I don't want the end user to have access to my source code.



Is that possible using python? I was using cx-freeze, but that has the
source code available. So does pyinstaller. I think gcc does, too.



Does anyone know of a way to do this?


Fundamentally no, it's not. Python code will always be distributed as
some form of bytecode. The only way to make it available without
revealing anything is to put it on a server and let people access it
without running it themselves.

But why is that a problem? Copyright law protects you from people
stealing your code and making unauthorized changes to it, and if
you're not worried about them making changes, there's no reason to
hide the source code (whatever you distribute would be just as
copiable). Are you concerned that people will see your bugs? We all
have them.

ChrisA


The OP is asking for source code not to be available, not bytecode.
There are obfuscating tools like PyArmor you might want to have a look at.


The byte code can be decompiled, though, so the attempt to hide the code 
won't be completely successful if someone wants to make the effort.  The 
same is true, e.g., about Java.  The class files don't include the 
source, but they can be decompiled.


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


Re: Windows installer from python source code without access to source code

2023-03-31 Thread jkn
On Friday, March 31, 2023 at 1:09:12 PM UTC+1, Chris Angelico wrote:
> On Fri, 31 Mar 2023 at 23:01, Jim Schwartz  wrote: 
> > 
> > I want a windows installer to install my application that's written in 
> > python, but I don't want the end user to have access to my source code. 
> > 
> > 
> > 
> > Is that possible using python? I was using cx-freeze, but that has the 
> > source code available. So does pyinstaller. I think gcc does, too. 
> > 
> > 
> > 
> > Does anyone know of a way to do this? 
> >
> Fundamentally no, it's not. Python code will always be distributed as 
> some form of bytecode. The only way to make it available without 
> revealing anything is to put it on a server and let people access it 
> without running it themselves. 
> 
> But why is that a problem? Copyright law protects you from people 
> stealing your code and making unauthorized changes to it, and if 
> you're not worried about them making changes, there's no reason to 
> hide the source code (whatever you distribute would be just as 
> copiable). Are you concerned that people will see your bugs? We all 
> have them. 
> 
> ChrisA

The OP is asking for source code not to be available, not bytecode.
There are obfuscating tools like PyArmor you might want to have a look at.
-- 
https://mail.python.org/mailman/listinfo/python-list


When is logging.getLogger(__name__) needed?

2023-03-31 Thread Loris Bennett
Hi,

In my top level program file, main.py, I have

  def main_function():

  parser = argparse.ArgumentParser(description="my prog")

  ...

  args = parser.parse_args()
  config = configparser.ConfigParser()

  if args.config_file is None:
  config_file = DEFAULT_CONFIG_FILE
  else:
  config_file = args.config_file

  config.read(config_file)

  logging.config.fileConfig(fname=config_file)
  logger = logging.getLogger(__name__)

  do_some_stuff()
  
  my_class_instance = myprog.MyClass()

  def do_some_stuff():

  logger.info("Doing stuff")

This does not work, because 'logger' is not known in the function
'do_some_stuff'.

However, if in 'my_prog/my_class.py' I have

  class MyClass:

  def __init__(self):

  logger.debug("created instance of MyClass")

this 'just works'.

I can add 

  logger = logging.getLogger(__name__)

to 'do_some_stuff', but why is this necessary in this case but not in
the class?

Or should I be doing this entirely differently?

Cheers,

Loris

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


Re: Python not showing correct version

2023-03-31 Thread Thomas Passin

On 3/31/2023 8:27 AM, Sumeet Firodia wrote:

Hi Barry,

This is getting more complicated.
As per the command you shared, below is the output

C:\Users\admin>py -3.8 -m pip --version
pip 19.2.3 from
C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\pip
(python 3.8)

For pip --version below is the output

C:\Users\admin>pip --version
pip 23.0.1 from
C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip
(python 3.10)

Now if I want to upgrade the pip version it says requirement already met

C:\Users\admin>python -m pip install --upgrade pip
Requirement already satisfied: pip in
c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages
(23.0.1)

Please let me know how can I cleanup everything so that I dont see python
3.10.10 and can work with 3.8

Thanks
Sumeet

On Fri, 31 Mar 2023 at 14:21, Barry Scott  wrote:





On 31 Mar 2023, at 09:33, Sumeet Firodia  wrote:

Thanks Barry.

One more thing is that pip --version also refers to python 3.10

C:\Users\admin>pip --version
pip 23.0.1 from

C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip
(python 3.10)

Use this command to ensure that pip matches the python you wish to use:

py -3.8 -m pip --version

Barry



The issue here is I am trying to use snowpark for which I need python

3.8 but because of this I am not able to proceed with next steps.


Thanks
Sumeet

On Thu, 30 Mar 2023 at 22:45, Barry Scott 
> wrote:




On 30 Mar 2023, at 15:17, Sumeet Firodia 
ssfiro...@gmail.com>> wrote:




Hi Team,

I have installed Python 3.8 for Snowpark but when I check the version

in

command prompt it shows me Python 3.10.10.

C:\Users\admin>python --version
Python 3.10.10


Try this:

py -3.8

And this to list all version of python installed:

py -0




Also when I try to uninstall 3.10 it says no such version is

installed.


C:\Users\admin>pip uninstall python 3.10.10
WARNING: Skipping python as it is not installed.
WARNING: Skipping 3.10.10 as it is not installed.


PIP is for installing python modules not the python program.
The python program is installed by running the .exe that you get from

python.org , for example.

Use the standard Windows method to uninstall a program.
Search the web for "windows uninstall software" if you are not sure how

to do this.


Barry



Can you please help me here as my snowpark assignment is stuck

because of

this issue.


We have been telling you to type "py -3.8" instead of typing "python". 
We have been telling you to type "py -3.8 -m pip" instead of "python -m 
pip".  Now you complain that you did something else and got a wrong result.


If you want to upgrade pip for Python 3.8, then follow the pattern and 
type "py -3.8 -m pip install --upgrade pip".  Everywhere you would have 
typed "python" type "py -3.8" instead.


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


Re: Python not showing correct version

2023-03-31 Thread Sumeet Firodia
Hi Barry,

This is getting more complicated.
As per the command you shared, below is the output

C:\Users\admin>py -3.8 -m pip --version
pip 19.2.3 from
C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\pip
(python 3.8)

For pip --version below is the output

C:\Users\admin>pip --version
pip 23.0.1 from
C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip
(python 3.10)

Now if I want to upgrade the pip version it says requirement already met

C:\Users\admin>python -m pip install --upgrade pip
Requirement already satisfied: pip in
c:\users\admin\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages
(23.0.1)

Please let me know how can I cleanup everything so that I dont see python
3.10.10 and can work with 3.8

Thanks
Sumeet

On Fri, 31 Mar 2023 at 14:21, Barry Scott  wrote:

>
>
> > On 31 Mar 2023, at 09:33, Sumeet Firodia  wrote:
> >
> > Thanks Barry.
> >
> > One more thing is that pip --version also refers to python 3.10
> >
> > C:\Users\admin>pip --version
> > pip 23.0.1 from
> C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip
> (python 3.10)
>
> Use this command to ensure that pip matches the python you wish to use:
>
> py -3.8 -m pip --version
>
> Barry
>
> >
> > The issue here is I am trying to use snowpark for which I need python
> 3.8 but because of this I am not able to proceed with next steps.
> >
> > Thanks
> > Sumeet
> >
> > On Thu, 30 Mar 2023 at 22:45, Barry Scott  > wrote:
> >>
> >>
> >>> On 30 Mar 2023, at 15:17, Sumeet Firodia  ssfiro...@gmail.com>> wrote:
> >>>
> 
>  Hi Team,
> 
>  I have installed Python 3.8 for Snowpark but when I check the version
> in
>  command prompt it shows me Python 3.10.10.
> 
>  C:\Users\admin>python --version
>  Python 3.10.10
> >>
> >> Try this:
> >>
> >> py -3.8
> >>
> >> And this to list all version of python installed:
> >>
> >> py -0
> >>
> >>
> 
>  Also when I try to uninstall 3.10 it says no such version is
> installed.
> 
>  C:\Users\admin>pip uninstall python 3.10.10
>  WARNING: Skipping python as it is not installed.
>  WARNING: Skipping 3.10.10 as it is not installed.
> >>
> >> PIP is for installing python modules not the python program.
> >> The python program is installed by running the .exe that you get from
> python.org , for example.
> >> Use the standard Windows method to uninstall a program.
> >> Search the web for "windows uninstall software" if you are not sure how
> to do this.
> >>
> >> Barry
> >>
> 
>  Can you please help me here as my snowpark assignment is stuck
> because of
>  this issue.
> 
>  Thanks
>  Sumeet
> 
> 
> >>> --
> >>> https://mail.python.org/mailman/listinfo/python-list
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows installer from python source code without access to source code

2023-03-31 Thread Chris Angelico
On Fri, 31 Mar 2023 at 23:01, Jim Schwartz  wrote:
>
> I want a windows installer to install my application that's written in
> python, but I don't want the end user to have access to my source code.
>
>
>
> Is that possible using python?  I was using cx-freeze, but that has the
> source code available.  So does pyinstaller.  I think gcc does, too.
>
>
>
> Does anyone know of a way to do this?
>

Fundamentally no, it's not. Python code will always be distributed as
some form of bytecode. The only way to make it available without
revealing anything is to put it on a server and let people access it
without running it themselves.

But why is that a problem? Copyright law protects you from people
stealing your code and making unauthorized changes to it, and if
you're not worried about them making changes, there's no reason to
hide the source code (whatever you distribute would be just as
copiable). Are you concerned that people will see your bugs? We all
have them.

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


Windows installer from python source code without access to source code

2023-03-31 Thread Jim Schwartz
I want a windows installer to install my application that's written in
python, but I don't want the end user to have access to my source code.  

 

Is that possible using python?  I was using cx-freeze, but that has the
source code available.  So does pyinstaller.  I think gcc does, too.

 

Does anyone know of a way to do this?

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


Re: Python not showing correct version

2023-03-31 Thread Barry Scott



> On 31 Mar 2023, at 09:33, Sumeet Firodia  wrote:
> 
> Thanks Barry.
> 
> One more thing is that pip --version also refers to python 3.10
> 
> C:\Users\admin>pip --version
> pip 23.0.1 from 
> C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip
>  (python 3.10)

Use this command to ensure that pip matches the python you wish to use:

py -3.8 -m pip --version

Barry

> 
> The issue here is I am trying to use snowpark for which I need python 3.8 but 
> because of this I am not able to proceed with next steps.
> 
> Thanks
> Sumeet
> 
> On Thu, 30 Mar 2023 at 22:45, Barry Scott  > wrote:
>> 
>> 
>>> On 30 Mar 2023, at 15:17, Sumeet Firodia >> > wrote:
>>> 
 
 Hi Team,
 
 I have installed Python 3.8 for Snowpark but when I check the version in
 command prompt it shows me Python 3.10.10.
 
 C:\Users\admin>python --version
 Python 3.10.10
>> 
>> Try this:
>> 
>> py -3.8
>> 
>> And this to list all version of python installed:
>> 
>> py -0
>> 
>> 
 
 Also when I try to uninstall 3.10 it says no such version is installed.
 
 C:\Users\admin>pip uninstall python 3.10.10
 WARNING: Skipping python as it is not installed.
 WARNING: Skipping 3.10.10 as it is not installed.
>> 
>> PIP is for installing python modules not the python program.
>> The python program is installed by running the .exe that you get from 
>> python.org , for example.
>> Use the standard Windows method to uninstall a program.
>> Search the web for "windows uninstall software" if you are not sure how to 
>> do this.
>> 
>> Barry
>> 
 
 Can you please help me here as my snowpark assignment is stuck because of
 this issue.
 
 Thanks
 Sumeet
 
 
>>> -- 
>>> https://mail.python.org/mailman/listinfo/python-list

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


Re: Python not showing correct version

2023-03-31 Thread Sumeet Firodia
Thanks Barry.

One more thing is that pip --version also refers to python 3.10

C:\Users\admin>pip --version
pip 23.0.1 from
C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pip
(python 3.10)

The issue here is I am trying to use snowpark for which I need python 3.8
but because of this I am not able to proceed with next steps.

Thanks
Sumeet

On Thu, 30 Mar 2023 at 22:45, Barry Scott  wrote:

>
>
> On 30 Mar 2023, at 15:17, Sumeet Firodia  wrote:
>
>
> Hi Team,
>
> I have installed Python 3.8 for Snowpark but when I check the version in
> command prompt it shows me Python 3.10.10.
>
> C:\Users\admin>python --version
> Python 3.10.10
>
>
> Try this:
>
> py -3.8
>
> And this to list all version of python installed:
>
> py -0
>
>
>
> Also when I try to uninstall 3.10 it says no such version is installed.
>
> C:\Users\admin>pip uninstall python 3.10.10
> WARNING: Skipping python as it is not installed.
> WARNING: Skipping 3.10.10 as it is not installed.
>
>
> PIP is for installing python modules not the python program.
> The python program is installed by running the .exe that you get from
> python.org, for example.
> Use the standard Windows method to uninstall a program.
> Search the web for "windows uninstall software" if you are not sure how to
> do this.
>
> Barry
>
>
> Can you please help me here as my snowpark assignment is stuck because of
> this issue.
>
> Thanks
> Sumeet
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: built-in pow() vs. math.pow()

2023-03-31 Thread Barry


> On 30 Mar 2023, at 22:30, Chris Angelico  wrote:
> 
> On Fri, 31 Mar 2023 at 08:13, Oscar Benjamin  
> wrote:
>> 
>>> On Thu, 30 Mar 2023 at 17:31, Andreas Eisele  
>>> wrote:
>>> 
>>> I sometimes make use of the fact that the built-in pow() function has an 
>>> optional third argument for modulo calculation, which is handy when dealing 
>>> with tasks from number theory, very large numbers, problems from Project 
>>> Euler, etc. I was unpleasantly surprised that math.pow() does not have this 
>>> feature, hence "from math import *" overwrites the built-in pow() function 
>>> with a function that lacks functionality. I am wondering for the rationale 
>>> of this. Does math.pow() do anything that the built-in version can not do, 
>>> and if not, why is it even there?
>> 
>> It is useful for when you want the pure floating point power which has
>> an approximately fixed computational cost (unlike integer powers).
>> Perhaps it would have been better if it was named fpow similar to fsum
>> vs sum.
>> 
> 
> It's called math.pow. That on its own should be a strong indication
> that it's designed to work with floats.

So long as you know that the math module is provided to give access the C 
math.h functions.

Barry

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

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