Skip to content
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

Modernize Python code #1769

Closed
wants to merge 1 commit into from
Closed

Conversation

gaborbernat
Copy link
Contributor

Use f-strings, walrus operator and raise SystemExit instead of sys.exit.

Signed-off-by: Bernát Gábor bgabor8@bloomberg.net

Use f-strings, walrus operator and raise SystemExit instead of sys.exit.

Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
Comment on lines 33 to +39
if sys.platform == "win32":
import subprocess

completed_process = subprocess.run([uv, *sys.argv[1:]], env=env)
sys.exit(completed_process.returncode)
else:
os.execvpe(uv, [uv, *sys.argv[1:]], env=env)
completed_process = subprocess.run(cmd, env=env)
raise SystemExit(completed_process.returncode)

os.execvpe(uv, cmd, env=env)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I kinda prefer the if/else here -- I feel like it makes it more explicit that it's a binary choice: for Windows we do one thing; for all other platforms, we do a different thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But raise SystemExit makes it redundant, 🤔 so I prefer this 😆 the raise makes it explicit that the execution of that branch ends there.

Copy link
Member

@AlexWaygood AlexWaygood Feb 20, 2024

Choose a reason for hiding this comment

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

I agree with you that calling sys.exit is redundant, since all it does internally is raise SystemExit, so I too prefer raising SystemExit directly as a matter of style. But I'd still personally find it more readable, in this specific instance, to do this:

    if sys.platform == "win32":
        import subprocess

        completed_process = subprocess.run(cmd, env=env)
        raise SystemExit(completed_process.returncode)
    else:
        os.execvpe(uv, cmd, env=env)

even though, as you say, the else is, strictly speaking, redundant.

Make a bikesheddy PR, expect bikesheddy review comments ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer my style, but if there's one more maintainer vote on the previous form can revert 👍

@charliermarsh
Copy link
Member

I think we're technically 3.7-compatible right now, so we may have to decide whether that's correct or not.

@gaborbernat
Copy link
Contributor Author

I think we're technically 3.7-compatible right now, so we may have to decide whether that's correct or not.

https://github.com/astral-sh/uv/blob/main/pyproject.toml#L10 seems to strongly disagree 😆 any modern installer would refuse installing the package in 3.7 because of that.

@zanieb
Copy link
Member

zanieb commented Feb 20, 2024

We should be as backwards compatible as possible here. I do not think we should make these cosmetic changes.

@gaborbernat
Copy link
Contributor Author

Backwards compatible to what? Python 1.0? As pointed out above, the pyproject.toml metadata already makes you incompatible with anything before 3.8 for any installer that's not 5+ years old…

@zanieb
Copy link
Member

zanieb commented Feb 20, 2024

We do not want to encourage use of Python 3.7, but we are compatible except for that line preventing installation with it. I think we should consider explicitly breaking runtime compatibility separately.

Separate from the compatibility comments, I'm unwilling to make stylistic changes to such critical code unless accompanied by other necessary changes — the risk of breaking things for our users is not worth it.

I hope this doesn't come across as harsh, this just isn't the time for us to be reviewing these kinds of changes. We're focused on fixing bugs and improving correctness to unblock new users.

@zanieb zanieb closed this Feb 20, 2024
@gaborbernat
Copy link
Contributor Author

Fine, :-) I'll go away then.

@zanieb
Copy link
Member

zanieb commented Feb 20, 2024

We do appreciate you!

@notatallshaw
Copy link
Contributor

notatallshaw commented Feb 20, 2024

FYI just two days ago Pip dropped functional and runtime support for Python 3.7: pypa/pip#11944

The motivating factor there was vendoring other Python packages. Something uv doesn't have to worry about I guess.

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.

5 participants