cnpryer / huak

My experimental Python package manager.
https://cnpryer.github.io/huak/
MIT License
616 stars 34 forks source link

Add freeze command #897

Open abhi3700 opened 7 months ago

abhi3700 commented 7 months ago

Description

This PR is to add freeze command in huak so that it can create a requirements.txt file in the same directory as pyproject.toml.

Usage

In a project with pyproject.toml:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "flet-demo"
version = "0.0.1"
description = ""
dependencies = [
    "flet ==0.21.2",
]

[project.optional-dependencies]
dev = [
    "build==1.2.1",
]

[tool.huak.task]
counter = "python3 src/flet_demo/counter.py"
todo = "python3 src/flet_demo/todo.py"

$ huak freeze works like this:

$ huak freeze
Dependencies extracted successfully.

with requirements.txt as:

flet==0.21.2

To create a custom file:

$ huak freeze -n deps.txt
Dependencies extracted successfully.

with deps.txt as:

flet==0.21.2
cnpryer commented 7 months ago

Hi thanks for the PR!

Is huak run pip freeze > requirements.txt sufficient?

abhi3700 commented 7 months ago

Hi thanks for the PR!

Is huak run pip freeze > requirements.txt sufficient?

No. Because that adds all the other dependencies that may not be required like this:

Details: ```txt annotated-types==0.6.0 anyio==4.3.0 arrow==1.3.0 binaryornot==0.4.4 build==1.2.1 certifi==2024.2.2 chardet==5.2.0 charset-normalizer==3.3.2 click==8.1.7 cookiecutter==2.6.0 fastapi==0.110.0 flet==0.21.2 flet-core==0.21.2 flet-runtime==0.21.2 h11==0.14.0 httpcore==1.0.5 httptools==0.6.1 httpx==0.27.0 idna==3.6 Jinja2==3.1.3 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 oauthlib==3.2.2 packaging==23.2 pydantic==2.6.4 pydantic_core==2.16.3 Pygments==2.17.2 pypng==0.20220715.0 pyproject_hooks==1.0.0 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 python-slugify==8.0.4 PyYAML==6.0.1 qrcode==7.4.2 repath==0.9.0 requests==2.31.0 rich==13.7.1 six==1.16.0 sniffio==1.3.1 starlette==0.36.3 text-unidecode==1.3 types-python-dateutil==2.9.0.20240316 typing_extensions==4.10.0 urllib3==2.2.1 uvicorn==0.29.0 uvloop==0.19.0 watchdog==4.0.0 watchfiles==0.21.0 websockets==12.0 ```

In fact, the intension is to just add the pyproject.toml dependencies into requirements.txt. This would:

cnpryer commented 7 months ago

I see but then we are defining what freeze means ourselves as something different, and I don't really like that definition. The point of freezing to a requirements file is to take a snapshot of the current environment.

I think what you're looking for is a way to export the pyproject.toml to a requirements file.

Another thing to note is that I plan to bundle uv with Huak. So at some point uv can be used for environment reproducibility.

abhi3700 commented 7 months ago

Well I can change the name if that's not matching the purpose. Also, didn't know about uv merging plan.

But, can we reproduce this with uv?

Moreover, I personally don't like uv as it is nowhere close to Rust's cargo-like package manager, which huak is pretty much close to.