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
Use permalinks in ecosystem diff references #5704
Conversation
yield Path(checkout_dir) | ||
yield await self._get_commit(checkout_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... because Repository
is immutable (and I liked that it was immutable) we can't just get the commit SHA on clone and stash it on the Repository
object. Instead, we yield it and it's attached to the Diff
object for later display. It also turns out that the previously yielded Path
was identical to the input argument so I removed that.
We probably ought to just have the ecosystem checks pinned to a specific SHA that's updated on a schedule by a bot and then we can skip the retrieval and just assign it to the Repository
at creation time. That seems pretty low priority though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also happy to hear alternative approaches if anyone has ideas! This seemed liked the simplest way to retain immutability but this was my first time looking at this script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could replace the value:
self._replace(ref=await self._get_commit(checkout_dir))
But, otherwise I think this is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how we'd get the new Repository
object back to the relevant owner without a bunch of changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, didn't think about that (_replace
returns a new object). I think this is fine then. We can iterate it later.
process = await create_subprocess_exec( | ||
*git_command, | ||
git_clone_process = await create_subprocess_exec( | ||
*git_clone_command, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed these before extracting _get_commit
into a separate function. I don't think the extra clarity hurts though.
scripts/check_ecosystem.py
Outdated
async def _get_commit(self: Self, checkout_dir: Path) -> str: | ||
"""Return the commit sha for the repository in the checkout directory.""" | ||
git_sha_process = await create_subprocess_exec( | ||
*["git", "rev-parse", "head"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
*["git", "rev-parse", "head"], | |
*["git", "rev-parse", "HEAD"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly this worked locally but failed with ambiguous argument 'head': unknown revision or path not in the working tree
in CI — curious to see if this changes anything but I doubt it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! https://stackoverflow.com/a/56346962
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That resolved it :)
@@ -45,11 +45,11 @@ async def clone(self: Self, checkout_dir: Path) -> AsyncIterator[Path]: | |||
"""Shallow clone this repository to a temporary directory.""" | |||
if checkout_dir.exists(): | |||
logger.debug(f"Reusing {self.org}:{self.repo}") | |||
yield Path(checkout_dir) | |||
yield await self._get_commit(checkout_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the commit SHA to the Repository
object as that's where I think it should be logically? I think adding it to ref
should be the same meaning as branches are just pointers to specific commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also mean that the repo.url_for
function/call need not be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that first but we cannot because it's immutable. We definitely could decide to make it mutable, but I liked the immutable design. More commentary at #5704 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed that comment. Give me a minute.
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Oh shoot! Sorry, I fixed the wrong long line :p |
No problem :) |
if lnum: | ||
url += f"#L{lnum}" | ||
return url | ||
|
||
async def _get_commit(self: Self, checkout_dir: Path) -> str: | ||
"""Return the commit sha for the repository in the checkout directory.""" | ||
git_sha_process = await create_subprocess_exec( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use subprocess.check_output
with text=True
here, it will also check the output status automatically
ruff/scripts/update_schemastore.py
Line 18 in 0666add
check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I'd rather not make a blocking call in an async function though 👿
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinux
Windows
|
Summary
Closes #5702
cc @dhruvmanila as I see you assigned yourself to the issue
Test Plan
Ran locally e.g.
<a href='https://github.com/zulip/zulip/blob/fcede324202ac5bc3de0691d2d6e168d0f18c120/zproject/prod_settings_template.py#L144'>zproject/prod_settings_template.py:144:26:</a>
Should succeed in CI as well.