Skip to content

bpo-31128: Allow pydoc to bind to arbitrary hostnames #3011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 14, 2017

Conversation

feanil
Copy link
Contributor

@feanil feanil commented Aug 6, 2017

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@feanil feanil changed the title Allow pydoc to bind to arbitrary hostnames. 31128-Allow pydoc to bind to arbitrary hostnames. Aug 6, 2017
@feanil feanil changed the title 31128-Allow pydoc to bind to arbitrary hostnames. bpo-31128-Allow pydoc to bind to arbitrary hostnames. Aug 6, 2017
Copy link

@rajathagasthya rajathagasthya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Verified locally:

~/dev/cpython $ ./python.exe -m pydoc -h localhost -p 5000
Server ready at http://localhost:5000/
Server commands: [b]rowser, [q]uit
server>

def __init__(self, port, callback):
self.host = 'localhost'
def __init__(self, host, port, callback):
self.host = host
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this class is considered part of the module’s public API, this change would break compatibility. Alternative ways to achieve the same result could be:

  • add host after the existing params, with default value to keep compat
  • allow the existing port to be a (host, port) tuple

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merwok, I considered that but figured it was a class inside a underscored method so its not guaranteed to remain compatible. I figured it would be better to opt for the more readable signature instead of being backwards compatible. If it's a blocker to make this compatible let me know but if we're implying that this function should be treated as if it is public we may want to remove the prefixed underscore but that will definitely break people.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Thanks for noting these classes are inside a private method, that excludes compat considerations. Patch looks fine.

@Mariatta
Copy link
Member

@merwok Aren't you a Core Developer? So this should not be "awaiting core review" anymore. 🤔

@Mariatta
Copy link
Member

Oh I see, I think it's because you did not "approve" the PR yet ...

@merwok
Copy link
Member

merwok commented Aug 15, 2017

I used to be, but I’m not part of the github team :)

@@ -913,7 +913,7 @@ def my_url_handler(url, content_type):
text = 'the URL sent was: (%s, %s)' % (url, content_type)
return text

serverthread = pydoc._start_server(my_url_handler, port=0)
serverthread = pydoc._start_server(my_url_handler, hostname='localhost', port=0)
self.assertIn('localhost', serverthread.docserver.address)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this test does not validate that the patch is correct, since it would also pass without the code change! But it’s probably fine for this patch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is localhost specified anywhere else in the pydoc.py file? If it isn't then while you're right it isn't testing a difference from the default from the public API, this does help make sure that at least the value is being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brettcannon just making sure you don't want me to do anything here? The one place that 'localhost' is used in pydoc.py is for the default vaule of the hostname parameter for the browse() function to not break backwards compatibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment before Brett’s: technically, this test does not prove that the patch is correct, since 'localhost' is the value that was used before your changes.

@Mariatta
Copy link
Member

@merwok I see that you are still a committer in b.p.o. I hope you'll continue contributing as core developer 😄 If interested, perhaps check with @brettcannon of what needs to happen?

@brettcannon
Copy link
Member

I just need @merwok to tell me he wants to be a core dev again, then I can add him on GitHub. 😄

@feanil
Copy link
Contributor Author

feanil commented Aug 26, 2017

Checking back in on this, I just wanted to confirm that there is nothing left to do on my end for this, and that it's just waiting for someone on the core team to review and merge(hopefully)?

@brettcannon
Copy link
Member

@feanil yep, the awaiting core review label means you're waiting on a core dev to review this and either ask for changes or merge it.

Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, just a question of whether the CLI switch is the right letter.

Also don't forget to add yourself to Misc/ACKS and to write a news entry. 😄

Lib/pydoc.py Outdated
@@ -2675,6 +2678,9 @@ class BadUsage(Exception): pass
{cmd} -k <keyword>
Search for a keyword in the synopsis lines of all available modules.

{cmd} -h <hostname>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using -h is a bit dodgy since it's so commonly used as shorthand for --help. Unfortunately I don't have a better suggestion beyond -n.

@@ -913,7 +913,7 @@ def my_url_handler(url, content_type):
text = 'the URL sent was: (%s, %s)' % (url, content_type)
return text

serverthread = pydoc._start_server(my_url_handler, port=0)
serverthread = pydoc._start_server(my_url_handler, hostname='localhost', port=0)
self.assertIn('localhost', serverthread.docserver.address)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is localhost specified anywhere else in the pydoc.py file? If it isn't then while you're right it isn't testing a difference from the default from the public API, this does help make sure that at least the value is being used.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I didn't expect the Spanish Inquisition!. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@brettcannon brettcannon changed the title bpo-31128-Allow pydoc to bind to arbitrary hostnames. bpo-31128: Allow pydoc to bind to arbitrary hostnames Aug 28, 2017
@merwok
Copy link
Member

merwok commented Aug 30, 2017

@brettcannon Alright please add me to the team! I can at least review distutils PRs since not many other people would do that, and hopefully get back to contributing.

@brettcannon
Copy link
Member

@merwok Invite sent! (and sorry to @feanil for the noise on his PR 😄 )

@merwok merwok self-assigned this Aug 30, 2017
This should prevent users from conflating help with the hostname.
@feanil
Copy link
Contributor Author

feanil commented Aug 31, 2017

I didn't expect the Spanish Inquisition!

@bedevere-bot
Copy link

Nobody expects the Spanish Inquisition!

@brettcannon, @merwok: please review the changes made to this pull request.

Misc/ACKS Outdated
@@ -1770,3 +1770,4 @@ Jelle Zijlstra
Gennadiy Zlobin
Doug Zongker
Peter Åstrand
Feanil Patel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is (mostly) sorted, can you move your name up with the other P?

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I didn't expect the Spanish Inquisition!. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@merwok
Copy link
Member

merwok commented Aug 31, 2017

By the way, is the command-line interface documented in the reST docs? If so, please add the new option there too. You could mention that it’s useful in containers, since that was the motivating use case.

@feanil
Copy link
Contributor Author

feanil commented Sep 1, 2017

I didn't expect the Spanish Inquisition!

@bedevere-bot
Copy link

Nobody expects the Spanish Inquisition!

@brettcannon, @merwok: please review the changes made to this pull request.

@merwok merwok merged commit 6a396c9 into python:master Sep 14, 2017
@feanil feanil deleted the fix-issue-31128 branch March 15, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants