-
-
Notifications
You must be signed in to change notification settings - Fork 16.6k
pyrefly: init at 0.17.1 #412863
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
pyrefly: init at 0.17.1 #412863
Conversation
Closes #412559 |
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.
Welcome to Nixpkgs 💜 Here are some suggestions for your addition:
pkgs/by-name/py/pyrefly/package.nix
Outdated
rustPlatform.buildRustPackage { | ||
inherit pname version; |
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.
buildRustPackage now supports the finalAttrs
pattern too, so using a let-in here shouldn't be necessary
pkgs/by-name/py/pyrefly/package.nix
Outdated
}; | ||
|
||
# requires unstable rust features | ||
RUSTC_BOOTSTRAP = 1; |
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.
Place environment variables inside env
RUSTC_BOOTSTRAP = 1; | |
env.RUSTC_BOOTSTRAP = 1; |
pkgs/by-name/py/pyrefly/package.nix
Outdated
# requires unstable rust features | ||
RUSTC_BOOTSTRAP = 1; | ||
|
||
nativeBuildInputs = [ rustPlatform.cargoSetupHook ]; |
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.
Should not be necessary for buildRustPackage
pkgs/by-name/py/pyrefly/package.nix
Outdated
description = "A fast type checker and IDE for Python"; | ||
homepage = "https://github.com/facebook/pyrefly"; | ||
license = licenses.mit; | ||
mainProgram = pname; |
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.
The mainProgram is not guaranteed to always be the same as the package name, and it's better to spell it out explicitly
mainProgram = pname; | |
mainProgram = "pyrefly"; |
pkgs/by-name/py/pyrefly/package.nix
Outdated
|
||
nativeBuildInputs = [ rustPlatform.cargoSetupHook ]; | ||
|
||
meta = with lib; { |
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.
New uses of with lib;
are discouraged as they introduce unclear variable references and scoping rules. Prefix each item under lib explicitly instead
pkgs/by-name/py/pyrefly/package.nix
Outdated
nativeBuildInputs = [ rustPlatform.cargoSetupHook ]; | ||
|
||
meta = with lib; { | ||
description = "A fast type checker and IDE for Python"; |
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.
Descriptions shouldn't start with an article (see pkgs/README.md)
description = "A fast type checker and IDE for Python"; | |
description = "Fast type checker and IDE for Python"; |
pkgs/by-name/py/pyrefly/package.nix
Outdated
cargoDeps = rustPlatform.importCargoLock { | ||
# generated by running `cargo generate-lockfile` in the `pyrefly` directory | ||
lockFile = ./Cargo.lock; | ||
outputHashes = { | ||
"ruff_python_ast-0.0.0" = "sha256-YQmkmn6fWKmKz+Lw9wwgPG2O9E+2/ZJcclRs97SOWK4="; | ||
}; | ||
}; |
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 think the recommended practice nowadays is to use fetchCargoVendor
, and specify patches
that add the required lockfile. This has the advantage of not requiring explicit Git hashes in the Nix source file, and would also eliminate the postPatch
phase here
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 having some trouble with this. Since there's no Nvm, I just read your reply properly...Cargo.lock
present in the pyrefly
repo (removed in facebook/pyrefly@dfe73ff), I get a FileNotFound
error for it. Do I add the Cargo.lock
file via a patch?
specify patches that add the required lockfile
my bad. I'll do that
(sorry, I have never touched or even been near Rust, let alone in combination with Nix 😓 so a bit unfamiliar)
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.
Hmm... I tried this to generate a .patch
file (not sure how else to do it if there's an easier way):
- fork
facebook/pyrefly
- create new branch in fork
- generate
Cargo.lock
and add it where needed - make PR
- add
.patch
to end of URL: https://github.com/cybardev/pyrefly/pull/1.patch - download the
.patch
file generated by GitHub
But it still shows Cargo.lock
is missing (I did stage my .patch
file in the local repo):
error.txt
Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/hdwyx26pi61g77cg9r60gznc39gyrbz0-source
source root is source
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
Traceback (most recent call last):
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 349, in <module>
main()
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 345, in main
subcommand_func()
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 336, in <lambda>
"create-vendor-staging": lambda: create_vendor_staging(lockfile_path=Path(sys.argv[2]), out_dir=Path(sys.argv[3])),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 127, in create_vendor_staging
cargo_lock_toml = load_toml(lockfile_path)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/qswdimncl2mlgc42915qkc4a9dw7xkq3-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 23, in load_toml
with open(path, "rb") as f:
^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'Cargo.lock'
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.
For context, here's my current code:
- working: https://github.com/cybardev/nix-channel/blob/691d808e/pkgs/pyrefly/package.nix
- failing: https://github.com/cybardev/nix-channel/blob/697b0bd6/pkgs/pyrefly/package.nix
Failing is not because of empty hash. It fails with the previously posted error (not finding Cargo.lock
) and does not get to the stage of failing while outputting the correct hash.
It also seems way more convenient to just generate and add the lock file instead of a patch. Not sure how much of a "bad practice" that is considered... Just thinking about having to update the patch every new update. 😓
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.
Well that's how it is unfortunately until upstream decides to commit lockfiles again 🤷♀️
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 think I got it: 2df70bc
Followed this: https://github.com/NixOS/nixpkgs/blob/9a3bb2cd/doc/hooks/versionCheckHook.section.md
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.
Well that's how it is unfortunately until upstream decides to commit lockfiles again
Submitted an issue. What are they doing?? Why? They had to go out of their way to not commit the Cargo.lock...
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.
They fixed it. Apparently they are using their own in-house build system to do this, which does not generate the lockfile. I find this very strange as usually any cargo command that fetches the dependencies creates the lockfile, but ok. But now at least cargoHash
should just work...
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.
Buck does generate a lockfile but they chose not to commit it before. But yeah, next update will be much better without all the Python/Maturin bloat.
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.
@dtomvan Actually there's still issues... See facebook/pyrefly#432 (comment)
pkgs/by-name/py/pyrefly/package.nix
Outdated
src = fetchFromGitHub { | ||
owner = "facebook"; | ||
repo = "pyrefly"; | ||
rev = version; |
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.
Use tag
for tagged releases and rev
only for commit hashes
rev = version; | |
tag = version; |
@QuiNzX shared this code that uses
|
Interesting. I didn't know that the PyPI version has the lockfile - that is a very peculiar choice IMO. (We normally prefer packaging software directly from source, but I guess we can make an exception for this one.) I think the Python stuff is mainly for using Pyrefly as a wheel (Python library)? I'm not sure how, but it does appear to be something upstream supports. In that case, then I think it's fair to build this as a Python + Maturin package instead. |
Ok, sorry, I saw your message after the rebase push... I will do the Python version then. |
Also if we were to support the case of using Pyrefly as a library, then we should move the main derivation to {
python3Packages
}:
python3Packages.toPythonApplication python3Packages.pyrefly See the Nixpkgs manual for more detailed reasoning as to why we want to do this |
I can check with upstream but from what I understand it cannot be used like a Python library. That is, it is |
Oh yeah, then leave it in |
7edb455
to
2ce7b8a
Compare
I think I've ironed out the issues. Let me know if there's anything to change. Thanks for the review and help. 🙂 |
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 is looking very, very good. Just one last stretch!
pkgs/by-name/py/pyrefly/package.nix
Outdated
python3.pkgs.buildPythonApplication rec { | ||
pname = "pyrefly"; | ||
version = "0.17.1"; | ||
format = "pyproject"; |
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.
format
is deprecated, actually 😅
format = "pyproject"; | |
pyproject = true; |
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 think pyproject = true;
an indirect default nowadays. You can safely remove it. It causes a rebuild, and it has a different output. But with --check
I found out that the build isn't reproducible anyways:
error: derivation '/nix/store/pcinwg72q15sykpq7jc6pi8psh3sck2a-pyrefly-0.17.1.drv' may not be deterministic: output '/nix/store/a8w3n650dwvv0qiwly397wf7fq9m49dd-pyrefly-0.17.1-dist' differs
But diffoscope with-pyproject-true without-pyproject-true
only reports differences in the python bytecode, the pyrefly
binary, and lib/python3.12/site-packages/pyrefly-0.17.1.dist-info/RECORD
, where the latter contains a sha256sum of the pyrefly
binary so that doesn't really count. The new output still works though.
Diffoscope (pyproject
set/unset): diff.html.gz
Diffoscope (pyproject
unset, two builds): diff.html.gz
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.
5cd9812
to
37d02cd
Compare
Add another commit adding them as a maintainer, and then rebase the main commit on top of that I think |
I think I got it right? Let me know if this is ok or changes are needed. Thanks. (apologies, I have not used Git to this extent before 😓) |
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.
Excellent. Thank you so much!
Thanks for the reviews, help, and guidance. 😊 |
pkgs/by-name/py/pyrefly/package.nix
Outdated
maturinBuildHook | ||
]; | ||
|
||
nativeInstallCheckInputs = [ versionCheckHook ]; |
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 think it's normally nativeCheckInputs
for Python packages
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.
Changed in de8144a. Thanks.
Co-authored-by: QuiNzX <76129478+QuiNzX@users.noreply.github.com>
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.
Builds and runs. LGTM!
I am so sorry. I must've been mistaken. I was wrong about
It will definitely work when unset, so it doesn't entirely matter. But apparently the best practice isn't to only set it when needed, it should almost always be set, but it just isn't a default yet. They did set a Sorry for the confusion and the extra work, was just trying to do a thorough review, but I kinda achieved the opposite of what I wanted. I am new here, so I still make a bunch of mistakes. That being said, I see no reason why this could not get merged in its current state. The behaviour is the same whether it's set or not, because it's using maturin anyways, so it doesn't reach the setuptools fallback codepath. |
|
After locally verifying it works, I added |
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.