Re: [Python-ideas] Make partial a built-in

2016-09-19 Thread Stefan Behnel
אלעזר schrieb am 19.09.2016 um 17:59:
> If at all, it should be function.bind(). It was discussed and dropped; I
> don't remember why, but one problem is that it looks like an in-place
> modification.

IMHO, the main drawback of that solution is that it only works for
functions and not for any other callable in Python. It would introduce an
inconsistency without solving the problem in general.

Stefan


___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Ethan Furman

On 09/19/2016 06:45 PM, Chris Angelico wrote:


Yes we are (at least in that instance). With more real-world tests,
they're allowed to use all the standard library - this was the "in
some cases" bit. (We don't teach float multiplication, because it's
very complication, but we do teach some stuff about how bitwise
operations work. So yes, we are teaching low level stuff in high level
languages.)


Good.  Just remember that "bin(x)" does not print 2s-complement for negative 
numbers.  Had me pulling my hair out for a while.

--
~Ethan~
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] singledispatch for instance methods

2016-09-19 Thread Tim Mitchell
Hi All,

We have a modified version of singledispatch at work which works for
methods as well as functions.  We have open-sourced it as methoddispatch
(pypi: https://pypi.python.org/pypi/methoddispatch).

IMHO I thought it would make a nice addition to python stdlib.

What does everyone else think?
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Steven D'Aprano
On Mon, Sep 19, 2016 at 01:35:53PM -0700, João Matos wrote:
> Hello,
> 
> I don't see why creating a clear command would interfere with dict.clear() 
> which is a function/method.

For the same reason that you can't have a method called foo.while or 
foo.if or foo.raise. If clear is a "command" (a statement) it would need 
to be a keyword, like while, if and raise.


-- 
Steve
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Steven D'Aprano
On Mon, Sep 19, 2016 at 05:06:50PM -0700, Ethan Furman wrote:
> On 09/19/2016 04:38 PM, אלעזר wrote:
> 
> >I was talking specifically about advanced courses, in which an assignment
> > is "implement a side-channel attack using data" and you can use whatever
> > library you like.
> 
> Am I misunderstanding, or did you just say you want this new functionality 
> in order to implement attacks on people's computers?

I'm pretty sure you misinterpreted Elazar.

He was talking about an advanced programming course where the course 
allows the students to use any library they like. The "side-channel 
attack" part just happened to be an example (I think a particularly 
poorly thought out example, but nevermind).

The idea is that the student writes:

from __pip__ import somepackage

in their script, and the examiner merely needs to run their script in 
order to have somepackage automatically installed. (I really, really, 
REALLY hope that the examiner runs their code in a sandbox.)

I'm not sure how this reconciles with Elazar's earlier use-case that 
this feature is for the benefit of *beginners*. Presumably the examiner 
of an advanced programming course should be able to cope with installing 
a package. I would expect that for such an advanced course, being able 
to deal with external dependencies should be part of the assignment:

"If your lecturer cannot work out what dependencies are needed by your 
project, because you haven't documented it or provided an installer, 
then you will fail the assignment."



-- 
Steve
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Steven D'Aprano
On Mon, Sep 19, 2016 at 11:35:39PM +, אלעזר wrote:
> Xavier, how is connecting and installing different from a windows popup
> "this software requires changes to your firewall settings" or "requires
> elevated privileges" which already happens. I am all for a two-step
> process, but I think it should be more user friendly, and it can be done as
> a Python command from inside the script.

Installing dependencies must be a separate step from running the code. 
You personally might not care, but some people *do* care. They may have 
policies about downloading, or even legal requirements about what 
software they install and run, and so need to vet dependencies, not just 
blindly install whatever packages are required by a module.

They may need authority to install. I don't mean account privileges, I 
mean they may need their manager's approval. Perhaps the legal 
department needs to check the licence terms. Perhaps they need to pay 
for a licence, or get approval to spend the money on a licence. Or they 
may have a policy of "no unapproved software" because they are legally 
required to run a specific, known set of software which has been 
audited, not just any old rubbish they've downloaded off the internet.

Or maybe they just don't trust any old rubbish available on the internet 
and want the choice of whether or not to install it.

I know places where it is a firing offence, with no warnings or second 
chances, to download and install unapproved software on work computers. 
Your suggestion would make it unsafe to use Python in such an 
environment.

(Of course any Python script *could* try to reach out to the internet to 
download code, but the risk of this is low. But if the Python language 
had a built-in command to do this, the risk would be magnified.)


> If I send you a small script, it should be treated in the same way as if I
> send you a program - an installer - not as a code that you should
> incorporate into your already existing code base.

Some scripts are installers. Some scripts are not. You cannot assume 
that all scripts should be treated as installers. I normally run scripts 
as an unprivileged user. Even if I don't trust the code, the worst that 
happens is limited by the privileges of that user. But installers 
generally require greater trust and greater privileges -- I might run 
them as root, or using sudo, otherwise the installation will fail.

Keeping installation and execution as separate steps is a security 
measure.


-- 
Steve
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Steven D'Aprano
On Mon, Sep 19, 2016 at 04:55:26PM +, אלעזר wrote:
> A library in PyPi  still requires installing it, which undermine many of
> the benefits. It won't help me with my gist/activestate recipe, code that I
> send to a friend, etc. I want to lower the barrier of inexperienced users.

When you say users, are you talking about completely non-technical 
end-users who are not programmers at all? In their case, you should 
bundle the application and all its dependencies into a single frozen 
.exe file (for Windows), or equivalent for other platforms.

Otherwise, the users you are talking about are *programmers*, or at 
least "technical people" (sys admin, etc), who can be expected to run a 
couple of commands to install needed dependencies. Perhaps they are 
inexperienced, and still learning. In that case, teaching them to use 
pip is a good thing, especially since it isn't that hard:

python3 -m ensurepip
pip install foo bar baz  # whatever your dependencies are

(In principle at least. In practice, I have found pip to be not quite as 
foolproof as advertised. But that's not something the std lib can fix.)

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

-- 
Steve
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Steven D'Aprano
On Tue, Sep 20, 2016 at 09:34:12AM +1000, Chris Angelico wrote:

> It's more than that, though. When a student is given an assignment,
> it's usually to help said student to learn to *write code*, not to
> learn how to walk into the plumbing store of PyPI and look for
> something that approximates to the job being done.

That might be sufficient for theoretical computer science courses, but 
it is *far* from sufficient for learning to be a professional 
programmer. I think that programmer education lets students down hugely. 
Knowing how to "walk into the plumbing store" to get a standard plumbing 
fixture is a skill programmers desperately need.

(We also need better standard plumbing fixtures, but that's another 
story.)

Failure to teach appropriate use of external dependencies, including 
when to use them and when not to, is part of the reason so many 
programmers suffer under Not Invented Here syndrome. It is not always 
appropriate to use PyPI, but being able to use it is an essential skill 
for programmers.

To be a professional programmer, you need more skills than just writing 
code. You need to be able to estimate costs, write and use tests, write 
documentation, etc, and most relevant to this discussion, manage 
dependencies.

Notice I didn't say "install dependencies". There is more to dependency 
management than just automatically installing any failed import.




> Maybe it's
> different at university, but with my students, it's always been "no
> external libraries" (and in some cases, a common-sense avoidance of
> obvious solutions from the standard library - if you teach someone how
> to implement a sort and the response is simply "lst.sort()", it's not
> exactly implementing anything).

This is off-topic, but unless you are specifically doing an algorithms 
course, why would you bother teaching anyone to implement a sort? Do you 
teach them to implement their own float multiplication as well?


> So the use-case for this isn't nearly
> as big as it might be. By the time you get to writing large
> applications (again, taking it from my students' work: a Flask-based
> web app), it's not illogical to have a requirements.txt and standard
> pip incantations.

Indeed.


-- 
Steve
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
On Tue, Sep 20, 2016 at 3:06 AM Ethan Furman  wrote:

> On 09/19/2016 04:38 PM, אלעזר wrote:
>
> > I was talking specifically about advanced courses, in which an assignment
> >  is "implement a side-channel attack using data" and you can use whatever
> >  library you like.
>
> Am I misunderstanding, or did you just say you want this new functionality
> in order to implement attacks on people's computers?
>

This is completely off topic (the feature is irrelevant to the contents of
the course).
But - you are misunderstanding :) And yes I took a course in which I was
expected to demonstrate attacks on people's computers using e.g.
correlation power analysis. It was based on fake data but yes. They also
give courses in which you learn that there's these things called man in the
middle, buffer overflows and return-oriented programming!

Elazar
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Ethan Furman

On 09/19/2016 04:38 PM, אלעזר wrote:


I was talking specifically about advanced courses, in which an assignment
 is "implement a side-channel attack using data" and you can use whatever
 library you like.


Am I misunderstanding, or did you just say you want this new functionality in 
order to implement attacks on people's computers?

--
~Ethan~
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
But grepping and piping could work I assume?

On Tue, Sep 20, 2016 at 2:41 AM Chris Angelico  wrote:

> On Tue, Sep 20, 2016 at 9:27 AM, Xavier Combelle
>  wrote:
> > I find the idea of tracking the dependencies in the script might be a
> > good idea.
> > However, magically downloading without warning the user is in my point
> > of view for sure a bad idea.
> > I would far prefer that pip could scan a script to know the dependencies.
> > (A little bit like a requirements.txt but inside the script)
> > A special comment or docstring would do the job. for example
> >
> > """
> > pip_requirements:
> > - requests >0.0
> > - asyncio
> > 
> >
> > to run the script it would be at the first time a  two step process
> > for example:
> >
> > python3 -m pip --script-dependencies [--user] my_script.py
> > python3 my_script.py
>
> How about this:
>
> python3 -m pip install -r requirements.txt
> python3 my_script.py
>
> That already works, but the requirements have to be in a separate text
> file, not in the .py file itself. If you want a docstring-based
> solution, I'd piggy-back it on requirements.txt, and use the same
> format (eg if the docstring starts "pip_requirements:", the rest of it
> is a requirements.txt file). Downside: Docstrings can be easily parsed
> and read *IF* you can successfully import the module. Which you can't,
> if you still need all those dependencies. So there would have to be
> some kind of import hook that crafts a dummy package with an infinite
> number of dummy subpackages, to allow all forms of import to trivially
> succeed - "import X", "import X.Y", "from X.Y import Z", etc. This may
> well be more hassle than it's worth.
>
> ChrisA
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Chris Angelico
On Tue, Sep 20, 2016 at 9:27 AM, Xavier Combelle
 wrote:
> I find the idea of tracking the dependencies in the script might be a
> good idea.
> However, magically downloading without warning the user is in my point
> of view for sure a bad idea.
> I would far prefer that pip could scan a script to know the dependencies.
> (A little bit like a requirements.txt but inside the script)
> A special comment or docstring would do the job. for example
>
> """
> pip_requirements:
> - requests >0.0
> - asyncio
> 
>
> to run the script it would be at the first time a  two step process
> for example:
>
> python3 -m pip --script-dependencies [--user] my_script.py
> python3 my_script.py

How about this:

python3 -m pip install -r requirements.txt
python3 my_script.py

That already works, but the requirements have to be in a separate text
file, not in the .py file itself. If you want a docstring-based
solution, I'd piggy-back it on requirements.txt, and use the same
format (eg if the docstring starts "pip_requirements:", the rest of it
is a requirements.txt file). Downside: Docstrings can be easily parsed
and read *IF* you can successfully import the module. Which you can't,
if you still need all those dependencies. So there would have to be
some kind of import hook that crafts a dummy package with an infinite
number of dummy subpackages, to allow all forms of import to trivially
succeed - "import X", "import X.Y", "from X.Y import Z", etc. This may
well be more hassle than it's worth.

ChrisA
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
On Tue, Sep 20, 2016 at 2:34 AM Chris Angelico  wrote:

> On Tue, Sep 20, 2016 at 9:20 AM, Stephen J. Turnbull
>  wrote:
> > אלעזר writes:
> >
> >  > Another use case, though I admit not the top priority of anyone here,
> is
> >  > that of assignment checkers. In most courses I took at the
> university, the
> >  > person who checks the assignments says something like "you are
> allowed to
> >  > use only this this and this libraries", in order not to mess with
> unknown
> >  > dependencies from tens of students (I am talking about advanced
> courses,
> >  > where the method I use to solve the problem is unimportant or only
> requires
> >  > explanation). With this statement they can simply state "you can
> import
> >  > pip".
> It's more than that, though. When a student is given an assignment,
> it's usually to help said student to learn to *write code*, not to
> learn how to walk into the plumbing store of PyPI and look for
> something that approximates to the job being done. Maybe it's
> different at university, but with my students, it's always been "no
> external libraries" (and in some cases, a common-sense avoidance of
> obvious solutions from the standard library - if you teach someone how
> to implement a sort and the response is simply "lst.sort()", it's not
> exactly implementing anything). So the use-case for this isn't nearly
> as big as it might be. By the time you get to writing large
> applications (again, taking it from my students' work: a Flask-based
> web app), it's not illogical to have a requirements.txt and standard
> pip incantations.
>
> ChrisA
>

I was talking specifically about advanced courses, in which an assignment
is "implement a side-channel attack using data" and you can use whatever
library you like.

Elazar
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
Xavier, how is connecting and installing different from a windows popup
"this software requires changes to your firewall settings" or "requires
elevated privileges" which already happens. I am all for a two-step
process, but I think it should be more user friendly, and it can be done as
a Python command from inside the script.

If I send you a small script, it should be treated in the same way as if I
send you a program - an installer - not as a code that you should
incorporate into your already existing code base.

‪On Tue, Sep 20, 2016 at 2:28 AM ‫אלעזר‬‎  wrote:‬

> On Tue, Sep 20, 2016 at 2:20 AM Stephen J. Turnbull <
> turnbull.stephen...@u.tsukuba.ac.jp> wrote:
>
>> אלעזר writes:
>>
>>  > Another use case, though I admit not the top priority of anyone here,
>> is
>>  > that of assignment checkers. In most courses I took at the university,
>> the
>>  > person who checks the assignments says something like "you are allowed
>> to
>>  > use only this this and this libraries", in order not to mess with
>> unknown
>>  > dependencies from tens of students (I am talking about advanced
>> courses,
>>  > where the method I use to solve the problem is unimportant or only
>> requires
>>  > explanation). With this statement they can simply state "you can import
>>  > pip".
>>
>> In other words, you're advocating a feature that allows script writers
>> to download, install, and execute arbitrary, unsandboxed code on any
>> machine where the script is run.  That sounds ... *scary*, when put
>> that way.  Remember, you're advocating this on behalf of people who
>> by assumption are infants years below the age of consent.
>>
>> Let me understand. Your argument is "installing pip modules is unsafe,
> and therefore we should make it less usable, where the appropriate amount
> of (un)usability is running cmd and then `pip install unsafe`" ?
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
On Tue, Sep 20, 2016 at 2:20 AM Stephen J. Turnbull <
turnbull.stephen...@u.tsukuba.ac.jp> wrote:

> אלעזר writes:
>
>  > Another use case, though I admit not the top priority of anyone here, is
>  > that of assignment checkers. In most courses I took at the university,
> the
>  > person who checks the assignments says something like "you are allowed
> to
>  > use only this this and this libraries", in order not to mess with
> unknown
>  > dependencies from tens of students (I am talking about advanced courses,
>  > where the method I use to solve the problem is unimportant or only
> requires
>  > explanation). With this statement they can simply state "you can import
>  > pip".
>
> In other words, you're advocating a feature that allows script writers
> to download, install, and execute arbitrary, unsandboxed code on any
> machine where the script is run.  That sounds ... *scary*, when put
> that way.  Remember, you're advocating this on behalf of people who
> by assumption are infants years below the age of consent.
>
> Let me understand. Your argument is "installing pip modules is unsafe, and
therefore we should make it less usable, where the appropriate amount of
(un)usability is running cmd and then `pip install unsafe`" ?
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Xavier Combelle
Le 19/09/2016 à 18:25, אלעזר a écrit :

> Many proposals to add something to stdlib are rejected here with the
> suggestion to add such library to pypi first. As noted by someone,
> pypi is not as reachable as stdlib, and one should install that
> package first, which many people don't know how. Additionally, there
> is no natural distinction between 3rd party dependencies and
> in-project imports (at least in tiny projects).
>
> This can be made easier if the first line of the program will declare
> the required library, and executing it will try to download and
> install that library if it is not installed yet. Additionally, the 3rd
> party dependencies will be more explicit, and editors can then allow
> you to search for them as you type.
>
> Of course it is *not* an alternative for real dependency management,
> but it will ease the burden on small scripts and tiny projects - which
> today simply break with errors that many users does not understand,
> instead of simply asking permission to install the dependency.
>
> Elazar
>
I find the idea of tracking the dependencies in the script might be a
good idea.
However, magically downloading without warning the user is in my point
of view for sure a bad idea.
I would far prefer that pip could scan a script to know the dependencies.
(A little bit like a requirements.txt but inside the script)
A special comment or docstring would do the job. for example

"""
pip_requirements:
- requests >0.0
- asyncio


to run the script it would be at the first time a  two step process
for example:

python3 -m pip --script-dependencies [--user] my_script.py
python3 my_script.py

___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
Sounds good, thanks.

So I'll suggest adding the method mentioned in Paul's code as a promised
API, either as pip.install or otherwise. `pip.main(['install', 'boltons'])` is
not the clearest it can get.

Elazar

On Tue, Sep 20, 2016 at 2:02 AM David Mertz  wrote:

> >>> import pip
> >>> pip.main(['install', 'boltons'])
> Requirement already satisfied (use --upgrade to upgrade): boltons in
> ./anaconda/lib/python3.5/site-packages
> 0
>
> This is easy, short, and uses existing syntax and an existing module.
> Yes, I know technically the API isn't promised; I wouldn't object to making
> that API official.  But PLEASE, no new syntax for doing this!
>
> Btw. On failure:
>
> >>> pip.main(['install', 'nonesuch'])
> Collecting nonesuch
>   Could not find a version that satisfies the requirement nonesuch (from
> versions: )
> No matching distribution found for nonesuch
> 1
>
>
> On Mon, Sep 19, 2016 at 3:46 PM, אלעזר  wrote:
>
>> On Tue, Sep 20, 2016 at 1:40 AM Paul Moore  wrote:
>>
>>> On 19 September 2016 at 23:13, אלעזר  wrote:
>>> > Alternative syntax might be that of import decorators
>>> >
>>> > @from_pip("attrs")
>>> > import attr
>>>
>>> At which point you may as well just (insert disclaimer about "using
>>> pip's internal API isn't supported" here, and glossing over the fact
>>> that pip doesn't yet have an install function with this API) do
>>>
>>> import pip
>>> pip.install('attrs')
>>> import attr
>>>
>>
>> Please forgive me for my ignorance, but it doesn't work as written -
>> what's the actual method?
>>
>> Elazar
>>
>> ___
>> Python-ideas mailing list
>> Python-ideas@python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
>
> --
> Keeping medicines from the bloodstreams of the sick; food
> from the bellies of the hungry; books from the hands of the
> uneducated; technology from the underdeveloped; and putting
> advocates of freedom in prisons.  Intellectual property is
> to the 21st century what the slave trade was to the 16th.
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread David Mertz
>>> import pip
>>> pip.main(['install', 'boltons'])
Requirement already satisfied (use --upgrade to upgrade): boltons in
./anaconda/lib/python3.5/site-packages
0

This is easy, short, and uses existing syntax and an existing module.  Yes,
I know technically the API isn't promised; I wouldn't object to making that
API official.  But PLEASE, no new syntax for doing this!

Btw. On failure:

>>> pip.main(['install', 'nonesuch'])
Collecting nonesuch
  Could not find a version that satisfies the requirement nonesuch (from
versions: )
No matching distribution found for nonesuch
1


On Mon, Sep 19, 2016 at 3:46 PM, אלעזר  wrote:

> On Tue, Sep 20, 2016 at 1:40 AM Paul Moore  wrote:
>
>> On 19 September 2016 at 23:13, אלעזר  wrote:
>> > Alternative syntax might be that of import decorators
>> >
>> > @from_pip("attrs")
>> > import attr
>>
>> At which point you may as well just (insert disclaimer about "using
>> pip's internal API isn't supported" here, and glossing over the fact
>> that pip doesn't yet have an install function with this API) do
>>
>> import pip
>> pip.install('attrs')
>> import attr
>>
>
> Please forgive me for my ignorance, but it doesn't work as written -
> what's the actual method?
>
> Elazar
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Paul Moore
On 19 September 2016 at 21:35, João Matos  wrote:
> Hello,
>
> I don't see why creating a clear command would interfere with dict.clear()
> which is a function/method.
>
> Although my first idea was a clear command, I have no problem if it is a
> clear() function from site.py.
>
> I didn't suggest cls because it is normally used to mean class.
>
> I use Windows and tested a simple (possibly not the best of course) solution
> that seems to work in REPL (but not in IDLE).
>
> import os
> import sys
>
> def clear():
> if sys.platform == 'win32':
> os.system('cls')
> else:
> os.system('clear')

Ah, I think people had misunderstood your proposal of a "command" as
something where you didn't have to type the parentheses. I know I did.
If you're OK with what you type at the REPL being

>>> clear()

then that's much easier to achieve. For example, if you install click
(https://pypi.python.org/pypi/click) you can just add "from click
import clear" at the start of your REPL session (or add it to your
PYTHONSTARTUP if you want it always available) and you're done.

Adding similar functionality to the stdlib somewhere (for example os
or shutil - I doubt it's going to get accepted as a builtin) isn't
inconceivable. I'm still not sure the benefit is sufficient to be
worthwhile (it might be more useful to just bite the bullet and bundle
one of the many curses variants for Windows into the distribution, and
make the curses module cross-platform once and for all, rather than
implementing individual bits of functionality) but if someone wanted
to contribute a patch on the tracker, it might be accepted.

Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Paul Moore
On 19 September 2016 at 21:34, אלעזר  wrote:
> Paul, I understand what you say, except the part of compatibility with
> Python3.5. Of course such a change is targeting future version more than the
> current and previous versions. If we have this syntax for Python3.6, users
> of Python3.9 will find many copy-pastable answers written this way, and
> other answers will have comments saying "just add this statement to the
> beginning of your script".

Agreed. Sorry, I was being pessimistic. Blame it on spending too much
time writing code that needs to retain compatibility with 2.x, when I
haven't used 2.x myself for years...

Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread João Matos
Hello,

I don't see why creating a clear command would interfere with dict.clear() 
which is a function/method.

Although my first idea was a clear command, I have no problem if it is a 
clear() function from site.py.

I didn't suggest cls because it is normally used to mean class.

I use Windows and tested a simple (possibly not the best of course) 
solution that seems to work in REPL (but not in IDLE).

import os
import sys

def clear():
if sys.platform == 'win32':
os.system('cls')
else:
os.system('clear')


Best regards,

JM


segunda-feira, 19 de Setembro de 2016 às 03:33:45 UTC+1, Steven D'Aprano 
escreveu:

> On Sat, Sep 17, 2016 at 11:51:16AM +0100, João Matos wrote: 
> > Hello, 
> > 
> > I would like to suggest adding a clear command (not function) to Python. 
>
> While technically "clear" could be a command, I think it should not be. 
>
> First off, making clear a reserved keyword, and a statement, like print 
> in Python 2, raise or import, would be a major backwards compatibility 
> break. It would mean dict.clear() has to be renamed, and it would break 
> lots of existing code. 
>
> So making clear a keyword is not going to happen. 
>
> If could be a pseudo-built-in, like help(), quit() and exit(), added to 
> built-ins by the site module. In that case, it is *technically* possible 
> to have it operate without the parentheses: 
>
> class ClearType: 
> def __repr__(self): 
> # code to clear the screen here 
> ... 
>
> clear = ClearType() 
>
> so that when you enter clear at the interactive interpreter, __repr__ is 
> called and it clears the screen. But I would argue against it. Instead, 
> it is better to use the same convention that executable code that has 
> side-effects should be implemented as a function call. 
>
> So I suggest following the design of exit() and quit(): 
>
> py> exit 
> Use exit() or Ctrl-D (i.e. EOF) to exit 
>
>
> class ClearType: 
> def __repr__(self): 
> return "Use clear() or Ctrl-L (i.e. FF) to clear the screen" 
> def __call__(self): 
> # clear screen code goes here 
>
> clear = ClearType()  # or possibly cls ? 
>
>
>
> That is, *if* we add this function at all. 
>
> Personally, I agree with you. There are many different ways of clearing 
> the screen, but they depend on the specific terminal used, whether 
> readline is active or not, the operating system, etc. I think that 
> interactive use is important enough that we should have a standard way 
> of clearing the screen. I personally often find myself just holding down 
> the Enter key until I have a blank screen. 
>
> In this ticket: 
>
> http://bugs.python.org/issue27771 
>
> Raymond Hettinger mentions that it is an often-requested feature by 
> learners, and I believe that IDLE has an active task for this feature: 
>
> http://bugs.python.org/issue6143 
>
> but I don't see any tasks for a clear screen command for the default 
> REPL. 
>
> I'm in favour of adding a clear() *function* to the site.py module, 
> similar to exit/quit/help, but not making it "magical" or a keyword that 
> doesn't require brackets. But I don't know how to implement it for the 
> large variety of terminals and operating systems supported by Python. 
>
> (The fallback if all else fails is easy: get the height of the terminal, 
> in lines, and print that many blank lines.) 
>
>
> -- 
> Steve 
> ___ 
> Python-ideas mailing list 
> python...@python.org  
> https://mail.python.org/mailman/listinfo/python-ideas 
> Code of Conduct: http://python.org/psf/codeofconduct/ 
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
Paul, I understand what you say, except the part of compatibility with
Python3.5. Of course such a change is targeting future version more than
the current and previous versions. If we have this syntax for Python3.6,
users of Python3.9 will find many copy-pastable answers written this way,
and other answers will have comments saying "just add this statement to the
beginning of your script".

On Mon, Sep 19, 2016 at 11:24 PM Paul Moore  wrote:

> On 19 September 2016 at 19:52, אלעזר  wrote:
> > Of course it doesn't  address the issues - for example, running a python
> > script from the file manager will result in a failed execution,
> unexplained.
>
> What you're talking about here is deployment of Python "applications"
> (where in your case, you're focusing on single-file scripts, but the
> problem is broader). Beyond a certain point, as I'm sure you realise,
> you can't solve this issue - someone tries to run a Unix-only script
> on Windows, for example. So really, we're looking at ways of improving
> the current state of affairs. As things stand, deploying "standalone
> applications" in Python is not particularly easy, with dependency
> management being only one of the issues.
>
> Some options for deployment come to mind - I'm sure none of them seem
> quite as easy as "just run this script", but you should remember that
> even "just run this script" doesn't always work as well as you'd like
> - on Unix you need to make the script executable and have a shebang
> line, on Windows the file extension needs to be right and registered.
> Not all users have the right (or sometimes any) Python version on
> their PATH, etc. So even "just run this script" isn't always simple
> even if the script has no dependencies outside the stdlib.
>
> So, some options:
>
> 1. The previously-mentioned rwt makes "just run this script" work as
> you want, as long as you have rwt installed. Conceded, it isn't
> available by default, but it's not hard to install as a one-off task.
> And there's a discussion ongoing about including it with pip as "pip
> run" so "pip run myscript.py" (or "py -m pip run myscript.py" on
> Windows - remember what I said about PATH? ;-)) will run a script with
> its dependencies.
> 2. You can bundle your script with its dependencies using zipapp. On
> Unix, you can even make the resulting file executable, and on Windows,
> the .pyz extension is registered for this.
> 3. Someone could write a tool to scan a script for a
> specially-formatted comment at the top that described its
> dependencies, and installed them. That (in effect) adds an "install"
> step before the script can be run, but lots of utilities have that, so
> it's not completely unheard of. And if it's GUI users you're concerned
> about, you could make that a GUI utility. Drag the script onto it, it
> lists the dependencies and confirms you want them installed, then
> offers to run the script.
> 4. There are existing platform-specific options like py2exe or
> cx_Freeze. Probably a bit heavyweight for a "simple script", though.
>
> Of course, none of these options cover the use case of "I saw this
> nice script on Stack Overflow, so I copied it, and now I want to run
> it on my PC". But honestly, if it has some dependencies, and the
> script author didn't say "you need to install FOO and BAR", or the
> user doesn't know how to install those dependencies, you're probably
> out of luck anyway. Even if the proposed "from __pypi__ import foo"
> syntax existed, I doubt many scripts posted on the web would use it -
> if only because then, Python 3.5 users wouldn't be able to run the
> scripts!
>
> IMO, for command line use, rwt is 99% of the way to what you want. For
> GUI use, there's nothing specific to this problem right now, but
> someone could certainly write something. A syntax change to the
> language would likely be *less* useful, as people would not be able to
> use it unless they were deliberately only targeting Python 3.7 and
> later, which seems optimistic at best...
>
> Paul
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread MRAB

On 2016-09-19 19:48, Chris Angelico wrote:

On Tue, Sep 20, 2016 at 4:43 AM, MRAB  wrote:

On 2016-09-19 18:20, אלעזר wrote:


Obviously

from __pip__ import "run-lambda>=0.1.0"

Which is ugly but not my fault :)


[snip]
One possible problem I can see is that if it's quoted you might think that
it's an expression and that you could also write:

package = "run-lambda>=0.1.0"
from __pip__ import package


One surprisingly effective option is this:

import blargle.spam # Solution: pip install blarg

Comes out looking like this:

Traceback (most recent call last):
  File "useblarg.py", line 1, in 
import blargle.spam # Solution: pip install blarg
ModuleNotFoundError: No module named 'blargle'

(in older Pythons, that says "ImportError" rather than the more
specific subclass, but same diff)

You can put whatever you like onto that command line.


One further suggestion:

import blargle.spam in "blarg"

The syntax would be:

"import" module_name ["in" quoted_pypi_name]

___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Paul Moore
On 19 September 2016 at 19:52, אלעזר  wrote:
> Of course it doesn't  address the issues - for example, running a python
> script from the file manager will result in a failed execution, unexplained.

What you're talking about here is deployment of Python "applications"
(where in your case, you're focusing on single-file scripts, but the
problem is broader). Beyond a certain point, as I'm sure you realise,
you can't solve this issue - someone tries to run a Unix-only script
on Windows, for example. So really, we're looking at ways of improving
the current state of affairs. As things stand, deploying "standalone
applications" in Python is not particularly easy, with dependency
management being only one of the issues.

Some options for deployment come to mind - I'm sure none of them seem
quite as easy as "just run this script", but you should remember that
even "just run this script" doesn't always work as well as you'd like
- on Unix you need to make the script executable and have a shebang
line, on Windows the file extension needs to be right and registered.
Not all users have the right (or sometimes any) Python version on
their PATH, etc. So even "just run this script" isn't always simple
even if the script has no dependencies outside the stdlib.

So, some options:

1. The previously-mentioned rwt makes "just run this script" work as
you want, as long as you have rwt installed. Conceded, it isn't
available by default, but it's not hard to install as a one-off task.
And there's a discussion ongoing about including it with pip as "pip
run" so "pip run myscript.py" (or "py -m pip run myscript.py" on
Windows - remember what I said about PATH? ;-)) will run a script with
its dependencies.
2. You can bundle your script with its dependencies using zipapp. On
Unix, you can even make the resulting file executable, and on Windows,
the .pyz extension is registered for this.
3. Someone could write a tool to scan a script for a
specially-formatted comment at the top that described its
dependencies, and installed them. That (in effect) adds an "install"
step before the script can be run, but lots of utilities have that, so
it's not completely unheard of. And if it's GUI users you're concerned
about, you could make that a GUI utility. Drag the script onto it, it
lists the dependencies and confirms you want them installed, then
offers to run the script.
4. There are existing platform-specific options like py2exe or
cx_Freeze. Probably a bit heavyweight for a "simple script", though.

Of course, none of these options cover the use case of "I saw this
nice script on Stack Overflow, so I copied it, and now I want to run
it on my PC". But honestly, if it has some dependencies, and the
script author didn't say "you need to install FOO and BAR", or the
user doesn't know how to install those dependencies, you're probably
out of luck anyway. Even if the proposed "from __pypi__ import foo"
syntax existed, I doubt many scripts posted on the web would use it -
if only because then, Python 3.5 users wouldn't be able to run the
scripts!

IMO, for command line use, rwt is 99% of the way to what you want. For
GUI use, there's nothing specific to this problem right now, but
someone could certainly write something. A syntax change to the
language would likely be *less* useful, as people would not be able to
use it unless they were deliberately only targeting Python 3.7 and
later, which seems optimistic at best...

Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Chris Angelico
On Tue, Sep 20, 2016 at 4:52 AM, אלעזר  wrote:
> Wow chris, that's a nice one!
>
> Of course it doesn't  address the issues - for example, running a python
> script from the file manager will result in a failed execution, unexplained.

True, it doesn't; but if anything else goes wrong, you have the same
problem. Python is built around the use of exceptions. So I would just
add something around the outside - if you're telling people to
download and run this script, tell them that if it doesn't work first
time, they should open up a terminal/console and run it from there.
That'd cope with any sort of error (including that Python itself isn't
installed, which is something you can't fix from within Python).

ChrisA
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
Wow chris, that's a nice one!

Of course it doesn't  address the issues - for example, running a python
script from the file manager will result in a failed execution, unexplained.

On Mon, Sep 19, 2016 at 9:48 PM Chris Angelico  wrote:

> On Tue, Sep 20, 2016 at 4:43 AM, MRAB  wrote:
> > On 2016-09-19 18:20, אלעזר wrote:
> >>
> >> Obviously
> >>
> >> from __pip__ import "run-lambda>=0.1.0"
> >>
> >> Which is ugly but not my fault :)
> >>
> > [snip]
> > One possible problem I can see is that if it's quoted you might think
> that
> > it's an expression and that you could also write:
> >
> > package = "run-lambda>=0.1.0"
> > from __pip__ import package
>
> One surprisingly effective option is this:
>
> import blargle.spam # Solution: pip install blarg
>
> Comes out looking like this:
>
> Traceback (most recent call last):
>   File "useblarg.py", line 1, in 
> import blargle.spam # Solution: pip install blarg
> ModuleNotFoundError: No module named 'blargle'
>
> (in older Pythons, that says "ImportError" rather than the more
> specific subclass, but same diff)
>
> You can put whatever you like onto that command line.
>
> ChrisA
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Chris Angelico
On Tue, Sep 20, 2016 at 4:43 AM, MRAB  wrote:
> On 2016-09-19 18:20, אלעזר wrote:
>>
>> Obviously
>>
>> from __pip__ import "run-lambda>=0.1.0"
>>
>> Which is ugly but not my fault :)
>>
> [snip]
> One possible problem I can see is that if it's quoted you might think that
> it's an expression and that you could also write:
>
> package = "run-lambda>=0.1.0"
> from __pip__ import package

One surprisingly effective option is this:

import blargle.spam # Solution: pip install blarg

Comes out looking like this:

Traceback (most recent call last):
  File "useblarg.py", line 1, in 
import blargle.spam # Solution: pip install blarg
ModuleNotFoundError: No module named 'blargle'

(in older Pythons, that says "ImportError" rather than the more
specific subclass, but same diff)

You can put whatever you like onto that command line.

ChrisA
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread MRAB

On 2016-09-19 18:20, אלעזר wrote:

Obviously

from __pip__ import "run-lambda>=0.1.0"

Which is ugly but not my fault :)


[snip]
One possible problem I can see is that if it's quoted you might think 
that it's an expression and that you could also write:


package = "run-lambda>=0.1.0"
from __pip__ import package

___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
Ryan I assume any error could be translated to your version through the
`from ` statement too?

Regarding the rabbit hole, the internet connection and privileges were
required for running this script in the first place. I only suggest giving
the developer - perhaps not a software engineer at all - an easy way not to
require the (possibly inexperienced) user to do it manually.

Put it another way, you a copy-pasted code from SO is not needed to use
only stdlib now.

On Mon, Sep 19, 2016 at 8:34 PM Ryan Gonzalez  wrote:

> This sounds like a great idea, but I've seen stuff like this done before,
> and it never ends well. You end up with a gargantuan-sized rabbit hole,
> since running a basic script could now involve using an internet connection
> and potentially root permissions.
>
> IF one were to go this route, I prefer bundling a `requirements.txt` into
> the distribution and then doing something like this in the script:
>
> import pkgcheck
> pkgcheck.check_requirements('requirements.txt')
>
> If any of the requirements were missing, then something like this would
> happen:
>
> Traceback (most recent call last):
> ...
> MissingPackageError: This script requires package(s) which are not
> installed: mypackage>=1.0, other_package
>
> That way, you don't get the weird import errors, but you don't have to
> worry about all the subtleties of automatic downloading.
>
> --
> Ryan
> [ERROR]: Your autotools build scripts are 200 lines longer than your
> program. Something’s wrong.
> http://kirbyfan64.github.io/
> On Sep 19, 2016 11:26 AM, "אלעזר"  wrote:
>
>> Many proposals to add something to stdlib are rejected here with the
>> suggestion to add such library to pypi first. As noted by someone, pypi is
>> not as reachable as stdlib, and one should install that package first,
>> which many people don't know how. Additionally, there is no natural
>> distinction between 3rd party dependencies and in-project imports (at least
>> in tiny projects).
>>
>> This can be made easier if the first line of the program will declare the
>> required library, and executing it will try to download and install that
>> library if it is not installed yet. Additionally, the 3rd party
>> dependencies will be more explicit, and editors can then allow you to
>> search for them as you type.
>>
>> Of course it is *not* an alternative for real dependency management, but
>> it will ease the burden on small scripts and tiny projects - which today
>> simply break with errors that many users does not understand, instead of
>> simply asking permission to install the dependency.
>>
>> Elazar
>>
>> ___
>> Python-ideas mailing list
>> Python-ideas@python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Ryan Gonzalez
This sounds like a great idea, but I've seen stuff like this done before,
and it never ends well. You end up with a gargantuan-sized rabbit hole,
since running a basic script could now involve using an internet connection
and potentially root permissions.

IF one were to go this route, I prefer bundling a `requirements.txt` into
the distribution and then doing something like this in the script:

import pkgcheck
pkgcheck.check_requirements('requirements.txt')

If any of the requirements were missing, then something like this would
happen:

Traceback (most recent call last):
...
MissingPackageError: This script requires package(s) which are not
installed: mypackage>=1.0, other_package

That way, you don't get the weird import errors, but you don't have to
worry about all the subtleties of automatic downloading.

--
Ryan
[ERROR]: Your autotools build scripts are 200 lines longer than your
program. Something’s wrong.
http://kirbyfan64.github.io/
On Sep 19, 2016 11:26 AM, "אלעזר"  wrote:

> Many proposals to add something to stdlib are rejected here with the
> suggestion to add such library to pypi first. As noted by someone, pypi is
> not as reachable as stdlib, and one should install that package first,
> which many people don't know how. Additionally, there is no natural
> distinction between 3rd party dependencies and in-project imports (at least
> in tiny projects).
>
> This can be made easier if the first line of the program will declare the
> required library, and executing it will try to download and install that
> library if it is not installed yet. Additionally, the 3rd party
> dependencies will be more explicit, and editors can then allow you to
> search for them as you type.
>
> Of course it is *not* an alternative for real dependency management, but
> it will ease the burden on small scripts and tiny projects - which today
> simply break with errors that many users does not understand, instead of
> simply asking permission to install the dependency.
>
> Elazar
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Paul Moore
On 19 September 2016 at 17:59, Joonas Liik  wrote:
> using pip from within python is not that difficult already.
> as can be seen with a glance to:
> http://stackoverflow.com/questions/12332975/installing-python-module-within-code

Note that pip does not officially support any use of its internal API
- it is purely a command line tool, and should only be invoked as a
subprocess. Having said that, simple use of pip's internal API isn't
difficult and if you keep to the higher-level APIs, things *shouldn't*
break (but if they do, you get to keep both pieces :-)).

For the use case of running simple scripts with dependencies, rwt
(https://pypi.python.org/pypi/rwt) might be a reasonable solution. You
can declare your dependencies in your script, then run it with rwt
which will install those dependencies to a temporary location, then
run the script with those dependencies active, and then tidy up
afterwards.

Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Paul Moore
On 19 September 2016 at 18:20, אלעזר  wrote:
> Obviously
>
> from __pip__ import "run-lambda>=0.1.0"

If we were going to go down this route (which I'm not at all convinced
we should) it should be "from __pypi__ import" not "from __pip__
import" (as PyPI is where the code is coming from, not pip...)

With importlib, it would probably be perfectly possible to write a
module loader that worked like this. Of course, it's not accessible
until you manually install it (with pip) and activate it, but for a
prototype that demonstrates how the final version would work, and to
thrash out how the various corner cases would be handled, that's a
perfectly acceptable compromise. If the design of a 3rd-party
implementation looks clean and useful, it would be much easier to
debate whether it belongs in the stdlib (if for no other reason than
the fact that many of the "how would X work" questions could be
answered by reference to the prototype).

Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
Obviously

from __pip__ import "run-lambda>=0.1.0"

Which is ugly but not my fault :)

On Mon, Sep 19, 2016 at 8:16 PM Sven R. Kunze  wrote:

> I can definitely understand your point.
>
> The only issue with it (besides that it doesn't seem to be a good way for
> dependency management) is how do you manage the syntax involved here?
>
> Pip provides distributions. Each distribution contains a set of packages
> and modules. The latter can be imported, the former not. That's also due to
> the fact that the name of distribution can contain minuses:
>
>
> from __pip__ import nova-lxd   # would this work?
>
> What about versions?
>
> from __pip__ import run-lambda>=0.1.0   # would this work?
>
>
> Maybe, I thinking too complicated here but if it works for, say,
> "requests" people tend to want it for special cases as well. :)
>
>
> Cheers,
>
> Sven
>
> On 19.09.2016 18:55, אלעזר wrote:
>
> A library in PyPi  still requires installing it, which undermine many of
> the benefits. It won't help me with my gist/activestate recipe, code that I
> send to a friend, etc. I want to lower the barrier of inexperienced users.
>
> As a documentation of dependencies it will suffice indeed.
>
> Elazar
>
> On Mon, Sep 19, 2016 at 7:38 PM Ethan Furman  wrote:
>
>> On 09/19/2016 09:25 AM, אלעזר wrote:
>>
>> > Many proposals to add something to stdlib are rejected here with the
>> suggestion to add such library to pypi first. As noted by someone, pypi is
>> not as reachable as stdlib, and one should install that package first,
>> which many people don't know how. Additionally, there is no natural
>> distinction between 3rd party dependencies and in-project imports (at least
>> in tiny projects).
>> >
>> > This can be made easier if the first line of the program will declare
>> the required library, and executing it will try to download and install
>> that library if it is not installed yet. Additionally, the 3rd party
>> dependencies will be more explicit, and editors can then allow you to
>> search for them as you type.
>> >
>> > Of course it is *not* an alternative for real dependency management,
>> but it will ease the burden on small scripts and tiny projects - which
>> today simply break with errors that many users does not understand, instead
>> of simply asking permission to install the dependency.
>>
>> This should start out as a library on PyPI.  (Sorry, couldn't resist. ;)
>>
>> Actually, it should.  Perhaps a name of "import_pip" would make sense?
>> Any hurdles faced by this library would be (mostly) the same as a stdlib
>> version.
>>
>> --
>> ~Ethan~
>> ___
>> Python-ideas mailing list
>> Python-ideas@python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
>
> ___
> Python-ideas mailing 
> listPython-ideas@python.orghttps://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Sven R. Kunze

I can definitely understand your point.

The only issue with it (besides that it doesn't seem to be a good way 
for dependency management) is how do you manage the syntax involved here?


Pip provides distributions. Each distribution contains a set of packages 
and modules. The latter can be imported, the former not. That's also due 
to the fact that the name of distribution can contain minuses:



from __pip__ import nova-lxd   # would this work?

What about versions?

from __pip__ import run-lambda>=0.1.0   # would this work?


Maybe, I thinking too complicated here but if it works for, say, 
"requests" people tend to want it for special cases as well. :)



Cheers,

Sven


On 19.09.2016 18:55, אלעזר wrote:
A library in PyPi  still requires installing it, which undermine many 
of the benefits. It won't help me with my gist/activestate recipe, 
code that I send to a friend, etc. I want to lower the barrier of 
inexperienced users.


As a documentation of dependencies it will suffice indeed.

Elazar

On Mon, Sep 19, 2016 at 7:38 PM Ethan Furman > wrote:


On 09/19/2016 09:25 AM, אלעזר wrote:

> Many proposals to add something to stdlib are rejected here with
the suggestion to add such library to pypi first. As noted by
someone, pypi is not as reachable as stdlib, and one should
install that package first, which many people don't know how.
Additionally, there is no natural distinction between 3rd party
dependencies and in-project imports (at least in tiny projects).
>
> This can be made easier if the first line of the program will
declare the required library, and executing it will try to
download and install that library if it is not installed yet.
Additionally, the 3rd party dependencies will be more explicit,
and editors can then allow you to search for them as you type.
>
> Of course it is *not* an alternative for real dependency
management, but it will ease the burden on small scripts and tiny
projects - which today simply break with errors that many users
does not understand, instead of simply asking permission to
install the dependency.

This should start out as a library on PyPI.  (Sorry, couldn't
resist. ;)

Actually, it should.  Perhaps a name of "import_pip" would make
sense?  Any hurdles faced by this library would be (mostly) the
same as a stdlib version.

--
~Ethan~
___
Python-ideas mailing list
Python-ideas@python.org 
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/



___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread אלעזר
Thanks Joonas. I withdraw my proposal - nothing more is strictly needed. It
should be idiomatic somehow, but I don't have any specific suggestion.

On Mon, Sep 19, 2016 at 7:59 PM Joonas Liik  wrote:

> On 19 September 2016 at 19:55, אלעזר  wrote:
> > A library in PyPi  still requires installing it, which undermine many of
> the
> > benefits. It won't help me with my gist/activestate recipe, code that I
> send
> > to a friend, etc. I want to lower the barrier of inexperienced users.
> >
> > As a documentation of dependencies it will suffice indeed.
> >
> > Elazar
> >
> > On Mon, Sep 19, 2016 at 7:38 PM Ethan Furman  wrote:
> >>
> >> On 09/19/2016 09:25 AM, אלעזר wrote:
> >>
> >> > Many proposals to add something to stdlib are rejected here with the
> >> > suggestion to add such library to pypi first. As noted by someone,
> pypi is
> >> > not as reachable as stdlib, and one should install that package
> first, which
> >> > many people don't know how. Additionally, there is no natural
> distinction
> >> > between 3rd party dependencies and in-project imports (at least in
> tiny
> >> > projects).
> >> >
> >> > This can be made easier if the first line of the program will declare
> >> > the required library, and executing it will try to download and
> install that
> >> > library if it is not installed yet. Additionally, the 3rd party
> dependencies
> >> > will be more explicit, and editors can then allow you to search for
> them as
> >> > you type.
> >> >
> >> > Of course it is *not* an alternative for real dependency management,
> but
> >> > it will ease the burden on small scripts and tiny projects - which
> today
> >> > simply break with errors that many users does not understand, instead
> of
> >> > simply asking permission to install the dependency.
> >>
> >> This should start out as a library on PyPI.  (Sorry, couldn't resist. ;)
> >>
> >> Actually, it should.  Perhaps a name of "import_pip" would make sense?
> >> Any hurdles faced by this library would be (mostly) the same as a stdlib
> >> version.
> >>
> >> --
> >> ~Ethan~
> >> ___
> >> Python-ideas mailing list
> >> Python-ideas@python.org
> >> https://mail.python.org/mailman/listinfo/python-ideas
> >> Code of Conduct: http://python.org/psf/codeofconduct/
> >
> >
> > ___
> > Python-ideas mailing list
> > Python-ideas@python.org
> > https://mail.python.org/mailman/listinfo/python-ideas
> > Code of Conduct: http://python.org/psf/codeofconduct/
>
> using pip from within python is not that difficult already.
> as can be seen with a glance to:
>
> http://stackoverflow.com/questions/12332975/installing-python-module-within-code
>
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] from __pip__ import

2016-09-19 Thread Ethan Furman

On 09/19/2016 09:25 AM, אלעזר wrote:


Many proposals to add something to stdlib are rejected here with the suggestion 
to add such library to pypi first. As noted by someone, pypi is not as 
reachable as stdlib, and one should install that package first, which many 
people don't know how. Additionally, there is no natural distinction between 
3rd party dependencies and in-project imports (at least in tiny projects).

This can be made easier if the first line of the program will declare the 
required library, and executing it will try to download and install that 
library if it is not installed yet. Additionally, the 3rd party dependencies 
will be more explicit, and editors can then allow you to search for them as you 
type.

Of course it is *not* an alternative for real dependency management, but it 
will ease the burden on small scripts and tiny projects - which today simply 
break with errors that many users does not understand, instead of simply asking 
permission to install the dependency.


This should start out as a library on PyPI.  (Sorry, couldn't resist. ;)

Actually, it should.  Perhaps a name of "import_pip" would make sense?  Any 
hurdles faced by this library would be (mostly) the same as a stdlib version.

--
~Ethan~
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread eryk sun
On Mon, Sep 19, 2016 at 1:12 PM, Paul Moore  wrote:
> By the way - if you're on a system with readline support included with
> Python, GNU readline apparently has a binding for clear-screen
> (CTRL-L) so you may well have this functionality already (I don;'t use
> Unix or readline, so I can't comment for sure).

Hooking Ctrl+L to clear the screen can be implemented for Windows
Vista and later via the ReadConsole pInputControl parameter, as called
by PyOS_StdioReadline. It should be possible to match how GNU readline
works -- i.e. clear the screen, reprint the prompt, flush the input
buffer, and write the current line's input back to the input buffer.

The pInputControl parameter can also be used to implement Unix-style
Ctrl+D to end a read anywhere on a line, whereas the classic
[Ctrl+Z][Enter] has to be entered at the start of a line.
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Paul Moore
On 19 September 2016 at 13:10, Paul Moore  wrote:
>
> For this particular suggestion, though, I don't think that's the case.
> I think it's going to either be something that's accepted into the
> stdlib, or something that's rejected as too platform-specific or messy
> to standardise, and people should roll their own implementation.

Note, by the way, that in the form of a Python function, this
capability is already available in lots of places - colorama and click
include it, for a start. And even the stdlib has a version in the
curses module (albeit not available on Windows).

In the light of this, there seems little reason to water down this
proposal to "provide a clear screen function in the stdlib".

Taken in its original form of "add a command to the REPL to clear the
screen", the main issue is that the standard Python REPL simply
doesn't have a concept of "REPL commands", so there's nowhere really
to add that functionality without a relatively major overhaul. People
who want a richer REPL can look at other options like IDLE, or
IPython/Jupyter.

By the way - if you're on a system with readline support included with
Python, GNU readline apparently has a binding for clear-screen
(CTRL-L) so you may well have this functionality already (I don;'t use
Unix or readline, so I can't comment for sure).

So the proposal becomes limited to:

"""
Add a capability to the standard REPL to recognise and support
"commands" (as distinct from executable Python code) and provide a
"clear screen" command.
"""

This feature is only needed for users of the standard Python REPL, on
systems without readline support (i.e. Windows). I don't think that's
a significant enough benefit to warrant the change (even if we take
into account the potential opportunity for additional commands that
we'd get from adding command support to the REPL).

Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Chris Angelico
On Mon, Sep 19, 2016 at 9:56 PM, Steven D'Aprano  wrote:
> On Mon, Sep 19, 2016 at 06:38:00PM +1000, Chris Angelico wrote:
>
>> Sounds good to me. This is definitely sounding complicated and messy
>> enough to justify (a) writing a function to clear the screen, and (b)
>> testing that function thoroughly as a PyPI module before pushing
>> anything into the stdlib.
>
> This isn't Node.js where standard operating procedure
> is to rely on the third-party npm ecosystem even for tiny, ten line
> functions. And we should be *glad* that's not the case:

I agree; however, the bar for getting something onto PyPI is far lower
than the stdlib, and it makes it far easier to get a bit of testing
(hey, folks, here's what I'm playing with, can you try pip-installing
it and see if it works on your platform please). So the "first on
PyPI, then in the stdlib" route does have a lot of merit. But you're
quite right that we don't want to depend on a ton of packages

ChrisA
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Paul Moore
On 19 September 2016 at 12:56, Steven D'Aprano  wrote:
>
> For relatively small pieces of functionality, if it is useful enough, we
> should just add it to the std lib, and if it isn't, we should just say
> it isn't useful enough. We shouldn't condemn supporters of the idea to
> this false hope that if they can convince a thousand, or a million,
> people to download their package, it will be added to PyPI

"... to the stdlib".

Agreed. However, there are libraries already on PyPI that try to act
in the role of "useful bits that aren't in the stdlib". The boltons
project is one that I know of. Maybe a middle ground between stdlib
inclusion and outright rejection would be the suggestion to submit the
code to one of those 3rd party projects? There's no implication that
doing so means that there's any better chance of getting accepted for
the stdlib, but it does offer an option for people who want to publish
their idea for wider use.

For this particular suggestion, though, I don't think that's the case.
I think it's going to either be something that's accepted into the
stdlib, or something that's rejected as too platform-specific or messy
to standardise, and people should roll their own implementation.

I'm inclined to think there may be some scope for a blog entry or
HOWTO on customising your personal Python environment - what
facilities there are to do so, what other options (such as different
REPLs) are available, and how to judge whether it's worth doing or
not. Lots of people (myself included at times!) seem to be unaware of
the options available. It's not something I'm likely to ever write,
but if anyone is interested in doing so, it might be useful background
for this type of discussion.

Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Steven D'Aprano
On Mon, Sep 19, 2016 at 06:38:00PM +1000, Chris Angelico wrote:

> Sounds good to me. This is definitely sounding complicated and messy
> enough to justify (a) writing a function to clear the screen, and (b)
> testing that function thoroughly as a PyPI module before pushing
> anything into the stdlib.

This isn't Node.js where standard operating procedure 
is to rely on the third-party npm ecosystem even for tiny, ten line 
functions. And we should be *glad* that's not the case:

http://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/

People don't often install minor or small packages off PyPI as a matter 
of course: they either roll their own, or do without, depending on which 
is more painful, or whether they are even allowed to download 
third-party software (not everybody is), or whether managing the 
dependency is more or less work than writing their own.

I get it that not everything belongs in the std lib, and I get it that 
for *some* people (but not all) its easy to rely on packages in PyPI. 
But there's quite considerable friction in getting *small* things off 
PyPI. For starters, you have to know it exists, you have to trust that 
its functional and well-written. There is a huge amount of junk, 
abandoned and "version 0.1" packages on PyPI that nobody in their right 
mind should use. Dependencies don't come for free, they add complexity 
and cost to a project. Not everything belongs as a package on PyPI either.

If the cost of dealing with the added dependency is greater than 
the benefit gained, people won't use third-party packages on PyPI. For 
small but useful functionality, saying "Put it on PyPI" is effectively 
just a dismissal.

For relatively small pieces of functionality, if it is useful enough, we 
should just add it to the std lib, and if it isn't, we should just say 
it isn't useful enough. We shouldn't condemn supporters of the idea to 
this false hope that if they can convince a thousand, or a million, 
people to download their package, it will be added to PyPI.


-- 
Steve
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] ___repr__ on collections.UserDict, collections.UserList, collections.UserString

2016-09-19 Thread David Kendal
Hi,

  the UserDict, UserList, and UserString classes in the collections
module ought to provide __repr__ implementations along the following
lines:

def __repr__(self):
return '%s(%r)' % (type(self).__name__, self.data)

so that they give useful immediate information in the repl to the
effect that they are not mere dicts/lists/strs but user-defined
container types.

dpk (David P. Kendal) · Nassauische Str. 36, 10717 DE · http://dpk.io/
 The reason we had no idea how cats worked was because, since Newton,
 we had proceeded by the simple principle that essentially, to see how
 things work, we took them apart. If you try and take a cat apart to
 see how it works, the first thing you have on your hands is a non-
 working cat.   -- Douglas Adams

___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Terry Reedy

On 9/19/2016 4:31 AM, Paul Moore wrote:


shutil.get_terminal_size() is available on all platforms.


On windows, it works with Command Prompt and PowerShell but fails in 
IDLE, as it must.  In the absence of knowledge, it guesses the default 
of 80 x 24 (as documented).  AFAIK, there is no way whether an answer of 
80 x 24 is correct or arbitrary nonsense.  Returning 0 x 0 instead would 
be more informative.




Terry Jan Reedy

___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Chris Angelico
On Mon, Sep 19, 2016 at 6:31 PM, Paul Moore  wrote:
> On 19 September 2016 at 03:40, Chris Angelico  wrote:
>> On Mon, Sep 19, 2016 at 12:32 PM, Steven D'Aprano  
>> wrote:
>>> (The fallback if all else fails is easy: get the height of the terminal,
>>> in lines, and print that many blank lines.)
>>
>> Assuming you can get the height in lines. Have you tried that in the
>> default Windows shell? I don't think tcgetattr works on Windows.
>
> shutil.get_terminal_size() is available on all platforms.
>
> I don't think it would be unreasonable to add shutil.clear_terminal()
> (at the moment, get_terminal_size is the only "terminal handling"
> function in shutil, but it would be the obvious place to add others if
> we chose to do so).

Sounds good to me. This is definitely sounding complicated and messy
enough to justify (a) writing a function to clear the screen, and (b)
testing that function thoroughly as a PyPI module before pushing
anything into the stdlib.

ChrisA
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Suggestion: Clear screen command for the REPL

2016-09-19 Thread Paul Moore
On 19 September 2016 at 03:40, Chris Angelico  wrote:
> On Mon, Sep 19, 2016 at 12:32 PM, Steven D'Aprano  wrote:
>> (The fallback if all else fails is easy: get the height of the terminal,
>> in lines, and print that many blank lines.)
>
> Assuming you can get the height in lines. Have you tried that in the
> default Windows shell? I don't think tcgetattr works on Windows.

shutil.get_terminal_size() is available on all platforms.

I don't think it would be unreasonable to add shutil.clear_terminal()
(at the moment, get_terminal_size is the only "terminal handling"
function in shutil, but it would be the obvious place to add others if
we chose to do so).

Paul
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/