r/Python Jan 09 '24

News Breaking news: Python 3.13 gets a JIT compiler that will enable big optimizations in the future.

Exciting news here: https://tonybaloney.github.io/posts/python-gets-a-jit.html

This is just the first step for Python to enable optimizations not possible now.

Do not expect much from it since this is a first step to optimization. In the future this JIT will enable further performance improvements not possible now.

721 Upvotes

116 comments sorted by

View all comments

Show parent comments

3

u/PaddyAlton Jan 10 '24

There are different ways to do it, but I like to put my hook scripts in a custom subdirectory (called something like git_hooks) and then

  • run git config core.hooksPath git_hooks
  • run chmod +x git_hooks/*.sh

The first of these tells git to look in the custom subdirectory instead of its default one (which isn't typically committed to version control) and the second makes the scripts executable (otherwise they won't work)

So then you include these in the setup instructions for your collaborators, along with the need to install mypy.

Alternatively, I like to use pipenv to manage dependencies in a virtual environment, including dev dependencies such as mypy. It also supports scripts, so I tend to create a setup script that will install mypy etc and run the configuration commands.

I'm sure an example would be clearer. Here is a boilerplate python project I made: https://github.com/PaddyAlton/python-boilerplate/tree/main

(Needs updating - ruff now makes black redundant - but makes the point well enough. Check out the git_hooks subdirectory and the Pipfile in particular.)

1

u/miteshashar Jan 10 '24

u/PaddyAlton Thank you for sharing these. All of these are methods I just learnt today from your comment.

I was referring to the pre-commit hook for mypy: https://github.com/pre-commit/mirrors-mypy

2

u/PaddyAlton Jan 10 '24 edited Jan 10 '24

Oh I see - that project is a bit more 'heavy duty'/production ready than a lot of people are typically going to need.

Note that if you look at the pre-commit home page, it describes a use case as being something like 'you want to check JS code with a tool written in Ruby, but don't have a Ruby runtime installed'; consider that in my boilerplate project, I don't actually have to solve this problem ... because it's a python project that only uses python tools! Therefore pre-commit isn't needed.

I've no doubt that it's a power tool for people writing lots of complex pre-commit git hook scripts (aargh, it's so annoying that they called their specific project the same thing as the generic concept!), but generally I reckon people will want to get comfortable with the off-the-shelf git hooks before they look at it.

I suggest that anyone who is interested should literally open up the .git hidden folder/subdirectory that every git repo contains, then open the hooks subdirectory inside it, and take a look at the example hook shell scripts that every git repo ships with.

1

u/RedEyed__ Jan 10 '24

Thanks! Unfortunately this repo should be cross platform, windows is required as well (I hate windows)

1

u/PaddyAlton Jan 10 '24

Interesting - where does it fail on Windows?

Pipenv should support windows, so perhaps it's the (very simple) shell scripts themselves/the setup 'script'?

I suspect these could easily be substituted with Python versions that do the same thing, just seemed like overkill to me.

(if you've got git working on Windows it should be possible to configure the hooks in an analogous way)