-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add doc readme for tying version to pre-commit #98
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #98 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 590 590
Branches 118 140 +22
=========================================
Hits 590 590 ☔ View full report in Codecov by Sentry. |
This is sort of a meta question, but do people commonly pin pyright only via pre-commit? And not via dev-requirements or some other similar functionality provided by a package manager? How do people run it locally? I guess still within pre-commit somehow? |
Yep, I tend to run it via pre-commit (
I tend to use a pre-commit hook (https://github.com/floatingpurr/sync_with_poetry) that will ensure the versions defined in Note: it's kind of annoying running pyright (or mypy) in pre-commit because each pre-commit tool runs in its own venv which doesn't contain the project dependencies. Because all static checkers need to know your dependencies, you often have to add an explicit list of your deps in I think the ideal stack is not there yet. I like what pre-commit brings to the table, even if I don't agree with all the choices. |
I've scratched my own itch. There now exists a pre-commit hook that binds the additional dependencies of a hook to a set of poetry groups. This way, each software version is either defined once in the repo or synchronized in the CI. |
Sorry for the delay on properly reviewing and merging this; I've been busy and I wanted to come up with other sections to add for other possible sources for the version. Given the above, are you still wanting this to be documented like is in the PR as it is? |
I'd say syncing Poetry & Pre-Commit is independent from syncing pre-commit and GHA, so I'd say it's still relevant ? |
I did the one for poetry.lock:
reading See this repo for details (can't promise it will stay forever) From looking at the pdm lockfile format, I think the same code would work (apart from changing the filename of course). I haven't tried. For |
Hm, honestly I think in most of these cases, it's more straightforward to just run the package manager and print out a version, rather than cargo installing a whole package or something. Adding this must package-manager specific documentation is starting to feel pretty heavy 😅 |
At some level, it may be simpler for me to just look for the |
Maybe, but I'm not sure all package manager allow getting a version number without parsing human-readable output.
$ poetry --no-ansi show pyright
name : pyright
version : 1.1.357
description : Command line wrapper for pyright
dependencies
- nodeenv >=1.6.0
$ poetry --no-ansi show pyright | grep ' version' | cut '-d:' -f2 | xargs
1.1.357 Note: the Personally, I really don't like this line. I find it ugly and I'm annoyed that it will break when Poetry maintainers decide to change the human-readable format of the output. In the end, it would be exactly as easy to read the version from the lockfile directly with grep, ignoring that it's a toml file, but I really don't like that for the same reasons. You could say that it's a problem with poetry not providing a machine-readable output, and/or GHA not providing a builtin tool to query toml files, and/or yq not providing full toml support. You could also write a small python script that interacts with poetry as a lib, but it's undocumented. Also, what about requirements.txt ? there's no package manager to ask in this case (well, maybe I think if you want to go this way, the only standard path I see is to say "if pyright is already installed when the action is launched, then we'll use the same version of pyright as installed" [EDIT: ah that's what you suggested]. But it means we'd install pyright twice, the first time for nohing Just to make sure I had understood correctly, and though I'm perfectly ok with my contribution not being merged at the moment, but you said:
...and I understand you changed your mind on that. Did you have in mind that the way to extract locked version from different package managers would be more straightforward in general? if it helps, my suggestion of using a rust crate was just because it happened to exist, but we could do a python script too. |
(just because I had it around, and in case we change our minds, here's the requirements version) # .github/get_pyright_version.py
# /// script
# dependencies = ["requirements-parser", "setuptools"]
# ///
import requirements
def get_pyright_version():
with open('requirements.txt') as f:
reqs = list(requirements.parse(f))
for req in reqs:
if req.name == 'pyright':
return req.specs[0][1]
raise ValueError('pyright not found in requirements.txt')
if __name__ == '__main__':
print(get_pyright_version()) $ pipx run --python=python3.10 .github/get_pyright_version.py
1.1.357 |
I think I expected getting info out of the various places to be as simple a one-liner as I've used for
The most consistent way on GitHub Actions is probably going to be to use npm, given actions themselves are in Node (so it'll always be working). But, that's not really a big deal.
I don't think that method would require two installs; I can just look on That being said, your original comment was that you wanted to have this work for pre-commit. Is pre-commit already downloading pyright and putting it on PATH such that this would work? Apologies for waffling back and forth on this; I'm just trying to make sure that a final solution covers the most uses cases without being too complicated. I hadn't thought of "use the version on PATH" before (or at least, I probably forgot about it, or didnt't think of a way to make it not confusing.) |
I understand, and once again, it's not the only way.
Wait, are we talking about changing the action or documenting it ? In the action, I agree that Node is best. But for the end user, they have equal access to anything that's pre-installed on the VM.
Nope, this solution won't work with pre-commit, but what I currently have works and will continue to work. My original goal was just to document it, to share with others.
No worries, no need to apologize, I just wanted to make sure I had understood your opinion properly. Again, I don't need anything more for my case to work. |
In #107 I'm adding |
(do you want me to make another pass or would you rather do it ?) |
Feel free, I'm pretty swamped so you'd probably beat be to it. |
Related to #9
Added a doc section for listing recipes for tying the version with a pyright version specified elsewhere, added a first recipe for pre-commit.
Would have happily added
poetry.lock
but it seems not to be easily yq-parsable.