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

poetry install --with dev doesn't install pre-commit hooks #23

Open
Mews opened this issue Jun 16, 2024 · 6 comments
Open

poetry install --with dev doesn't install pre-commit hooks #23

Mews opened this issue Jun 16, 2024 · 6 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Mews
Copy link
Collaborator

Mews commented Jun 16, 2024

Running poetry install --with dev doesn't install the pre-commit hooks, as of right now they need to be installed manually through pre-commit install

@indrajithi
Copy link
Collaborator

I have created script.py for this. I thought it was getting installed from here.

[tool.poetry.scripts]
post_install = "scripts:post_install"

@indrajithi indrajithi added bug Something isn't working good first issue Good for newcomers labels Jun 16, 2024
@Mews
Copy link
Collaborator Author

Mews commented Jun 16, 2024

For me I had to do pre-commit install to get the hooks :/
I can try to look into it but I've never used poetry before.

@Mews
Copy link
Collaborator Author

Mews commented Jun 16, 2024

Maybe this is something you could take a look at, though I agree that using something native to poetry would be better than using extensions: https://pypi.org/project/poetry-pre-commit-plugin/

@Mews
Copy link
Collaborator Author

Mews commented Jun 16, 2024

From what I can tell the post_install function is just never getting ran.
I tried changing it to this

import subprocess

def post_install() -> None:
    with open("test.txt", "w") as f:
        f.write("this function ran")
        
    subprocess.run(["poetry", "run", "pre-commit", "install"], check=True)

And no file is created when running poetry install.

@Mews
Copy link
Collaborator Author

Mews commented Jun 16, 2024

From what I can tell the [tool.poetry.scripts] option is actually for making cli scripts, so basically it lets you register a command for the cli. So what the pyproject.toml is telling poetry is actually that it should register post_install as a console command. And sure enough, if you just type post_install in the command line, you get this:

Traceback (most recent call last):
  File "C:\Users\Public\codg\forks\Scripts\\post_install", line 3, in <module>
    from scripts import post_install
ModuleNotFoundError: No module named 'scripts'

@Mews
Copy link
Collaborator Author

Mews commented Jun 17, 2024

I found this post by the creator of poetry and he says he doesn't support running scripts on installation, so its probably best to just have to person contributing run the pre-commit commands manually, or to use the extension I sent earlier (although it looks like you can't install the push hook automatically through the extension)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants