astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
20.62k stars 609 forks source link

Question regarding import for pkgs #7615

Open AnirudhG07 opened 1 day ago

AnirudhG07 commented 1 day ago

Hi, thanks for the amazing tool uv. I am making a python package bept for some project. I am new to python packages and I wanted to know that in my src/bept/main.py, I am using bept.something.somefile, but is there a way i can do src.bept.something, that way I would be able to access some files outside of src. (or is there any other way for it? main goal: have test directory use codes in src.) I know its a bit case specific, but some help would be really appreciated!

Current version of uv = 0.4.15

danielhollas commented 12 hours ago

Hi @AnirudhG07,

I think this is usually done by installing your package in a virtual environment in an editable mode (so that any changes that you make are immediately reflected), and then you can refer to your package and modules from your tests as you normally would (e.g. bept.something).

For example if you use pytest

uv venv
uv pip install --editable .
. .venv/bin/activate
pytest

If you use the more modern workflow that uv shipped in version 0.4, I think simply running your test command via uv run should take care of all that automatically. (but I don't have that much experience here)

(not affiliated with astral team, just passing by :-))

AnirudhG07 commented 12 hours ago

Alright. Thanks, ill try it out But still is there a way i can change bept.something to src.bept.something?