Skip to content

GH-1564: Add "Last Modified" trailer to PEP HTML pages #1565

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

Closed
wants to merge 1 commit into from

Conversation

Mariatta
Copy link
Member

@Mariatta Mariatta commented Mar 8, 2020

Obtain the last modified date by making GET request to GitHub.
Don't render anything if there's any error with the GET request.

Add tests, and mock the network call.

API call: https://api.github.com/repos/python/peps/commits?path=pep-0012.txt
Display the date from ["commit"]["committer"]["date"]

The url is the GitHub history of the pep file, e.g. https://github.com/python/peps/commits/master/pep-0012.txt

Closes #1564

Screen Shot 2020-03-07 at 6 59 25 PM

Obtain the last modified date by making GET request to GitHub.
Don't render anything if there's any error with the GET request.

Add tests, and mock the network call.

Closes #1564
@Mariatta Mariatta requested a review from berkerpeksag March 8, 2020 04:13
@Mariatta
Copy link
Member Author

Mariatta commented Mar 8, 2020

Instead of getting the last commit date through git as suggested by @nealmcb in #1564, I chose to retrieve the info using GitHub API.
I find it easier and cleaner than having to make a git subprocess call (which returns text that we have to parse). Additionally, we already have requests library as a dependency of this repo, and the API call does not require any authorization. So we don't have to store GitHub API token. (but it is probably better to do so).

@berkerpeksag please review when you have the chance.


json_data = data.json()
if len(json_data) > 0:
commit_date = json_data[0]['commit']['committer']['date']
Copy link

Choose a reason for hiding this comment

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

Are there any failure conditions in which this would generate a KeyError?

Copy link

Choose a reason for hiding this comment

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

As far as I'm aware, github's API will always return [] upon finding no results or error, and when results are found for the repository's commits, there will always be an accessible commit.committer.date field. So, the KeyError would not occur in any situation (that I'm aware of) where data.json() returns something with a length > 0 when targeted at that specific URL.

@nealmcb
Copy link

nealmcb commented Mar 8, 2020

Wow - fast work, @Mariatta!

The issue also discusses the benefits of adding metadata such as datePublished and dateModified so that search engines can display more useful information to users.
If we plan to add that also, then looking for multiple data points per PEP might affect the tradeoff between doing local git operations and using web requests. The former also presumably would make error handling easier, and generation of the full footer more robust.

@Mariatta
Copy link
Member Author

@berkerpeksag will you have time to look into this and review, and perhaps help merge?

@nealmcb regarding additional metadata like datePublished or dateModified, I think those will come from the content of PEP file, which we already have access to. It will not come from git so I think the current solution will work.

Sorry for the delay in following up on this.

@berkerpeksag
Copy link
Member

@berkerpeksag will you have time to look into this and review, and perhaps help merge?

Yes, sorry for my late response. Will try to have a look this weekend.

@merwok
Copy link
Member

merwok commented Mar 27, 2020

Thanks for working on this Mariatta! Better links to git repo and history page can help people find more information and address the criticism/confusion in the original mail thread (or forum, I forgot).

It doesn’t feel great that a local build process, working on local files and with all info in a local git repo, now needs to send many external requests to one repo host.

Using git plumbing commands in subprocess wouldn’t be so bad? Or maybe one of the Python git libs could be nicer to use? (I could investigate that next week)

Comment on lines +208 to +213
try:
data = requests.get(
'https://api.github.com/repos/python/peps/commits?path={}'.format(pep_filename)
)
except Exception:
return commit_info
Copy link

Choose a reason for hiding this comment

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

Suggested change
try:
data = requests.get(
'https://api.github.com/repos/python/peps/commits?path={}'.format(pep_filename)
)
except Exception:
return commit_info
try:
data = requests.get(
'https://api.github.com/repos/python/peps/commits?path={}'.format(pep_filename)
)
data.raise_for_status()
except Exception:
return commit_info

It might be worthwhile to add data.raise_for_status(), to ensure that we always raise an exception here if we get an http error code like 404, 401, etc. Otherwise, it might raise a JSONDecodeError when we call data.json(). Realistically, I don't expect this will happen anytime soon to the github API under normal circumstances, but I think it would be a good general best practice to avoid making the PEP pages dependent on an external API returning a parse-able JSON response every time.

In general, I think it would also be better to catch requests.exceptions.RequestException instead of Exception, but I don't think it's an overly substantial concern in this case.

@berkerpeksag
Copy link
Member

It doesn’t feel great that a local build process, working on local files and with all info in a local git repo, now needs to send many external requests to one repo host.

That would be nice, but current solution looks good to me as well.

Perhaps we could pass per_page=1 to avoid fetching and parsing unnecessary data.

I'll try to get this merge this weekend.

@hugovk
Copy link
Member

hugovk commented Aug 12, 2024

The PEPs now have their own repo: https://github.com/python/peps and own website: https://peps.python.org/ and also have "Last modified" footers that link to GitHub. For example: https://peps.python.org/pep-0750/

@Mariatta Please could you close this PR?

@hugovk hugovk closed this Aug 16, 2024
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.

Add Last-modified: date and metadata to HTML view of PEPs
6 participants