nox icon indicating copy to clipboard operation
nox copied to clipboard

Wrong starting directory when noxfile.py is a symlink

Open rsyring opened this issue 1 year ago • 5 comments

I have a project where I want the noxfille to be a symlink to a different shared file. When I do this, it throws off the paths b/c nox follows the symlink and starts in that directory instead of starting in the directory where the symlink is.

 ❯ ls -l noxfile.py 
lrwxrwxrwx 1 rsyring rsyring 21 May 15 23:09 noxfile.py -> ./template/noxfile.py

 ❯ nox -s cwd
nox > Running session cwd
nox > Creating virtual environment (uv) using python3 in .nox/cwd
cwd is: /home/rsyring/projects/copier-py-package/template

Was this an intentional design decision? If not, how about starting where the symlink is instead (i.e. don't follow it)?

Thanks for your work on this project and consideration.

rsyring avatar May 16 '24 03:05 rsyring

Thanks, PR welcome. Take a look in load_nox_module in tasks.py.

cjolowicz avatar May 16 '24 05:05 cjolowicz

That happens here: https://github.com/wntrblm/nox/blob/a6e1a4efaeea3d67dd2c47b80b9b8836a4aa579a/nox/tasks.py#L86

The one below is fine (takes the global path of the dir), maybe it should just use that and reassemble the name.

henryiii avatar May 19 '24 04:05 henryiii

I actually use this behavior with the repo tool to symlink a nox-file into the root of of my repo client clone directory and expect that the sessions I reference occur in a sub directory. It probably isn't a huge deal if you modify this behavior (I can also make it symlink the folders/change the paths.) but I thought I should note that there is someone out here who uses this behavior.

jamesharris-garmin avatar Jun 04 '24 14:06 jamesharris-garmin

What I'm thinking we can provide a .noxfiledir attribute (or similar name) that gives the original directory to the noxfile. For most users, this might just be handy to have (say if they've cd'd in their session), but for the case where the noxfile is a symlink, it would be the original noxfile dir, while the working directory would be the symlink dir.

henryiii avatar Oct 07 '24 17:10 henryiii

(Or would it make sense to have a .noxfile attribute, and let the user compute dirs with it? We already have sessions.global_config.noxfile, maybe we could ensure that was unresolved?)

henryiii avatar Oct 07 '24 17:10 henryiii