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

Support nested requirements.txt for Python? #1619

Closed
sheeeng opened this issue Dec 2, 2024 · 8 comments
Closed

Support nested requirements.txt for Python? #1619

sheeeng opened this issue Dec 2, 2024 · 8 comments
Labels
question Further information is requested

Comments

@sheeeng
Copy link

sheeeng commented Dec 2, 2024

If the requirements-development.txt include a nested link to requirements.txt, it fails.

How can we support nested requirements.txt for Python?

0002.18: Requirements changed, running pip install -r /nix/store/l1a8wwdq2c6v05cr0f8bibnjj92fgqas-requirements.txt...
--- devenv:python:virtualenv stderr:
0000.02: ERROR: Could not open requirements file: [Errno 2] No such file or directory: '/nix/store/requirements.txt'
  # https://github.com/cachix/devenv/blob/741e23a22f3dc9e53075be3eaa795ea9ed6f5129/examples/python/devenv.nix
  languages.python = {
    enable = true;
    venv.enable = true;
    venv.requirements = ./requirements-development.txt;
  };
# requirements-development.txt
--requirement=requirements.txt
codespell==2.3.0
symspellpy==6.7.8
vale==3.9.1.0
# requirements.txt
mkdocs==1.6.1
pygments==2.18.0
pymdown-extensions==10.12

See https://devenv.sh/community/get-involved/ for how to contact the community.

Feel free to also post a question here.

@sheeeng sheeeng added the question Further information is requested label Dec 2, 2024
@clotodex
Copy link
Contributor

clotodex commented Dec 3, 2024

Do you need them to be referenced by each other?
If not you could combine them in devenv instead

@sheeeng
Copy link
Author

sheeeng commented Dec 3, 2024

Do you need them to be referenced by each other? If not you could combine them in devenv instead

Preferably referenced by another file. What do you mean by combine them in devenv?

@dz0ny
Copy link
Contributor

dz0ny commented Dec 3, 2024

try with

  languages.python = {
    enable = true;
    venv.enable = true;
    venv.requirements = ${./.}/requirements-development.txt;
  };

or

  languages.python = {
    enable = true;
    venv.enable = true;
    venv.requirements = ${config.env.DEVENV_ROOT} + "/requirements-development.txt";
  };

The idea is to inject absolute path not relative one.

@sheeeng
Copy link
Author

sheeeng commented Dec 4, 2024

Thanks for the tip, @dz0ny.

However, it does not work as expected. Somehow, it refuses to accept the other --requirement=requirements.txt.

venv.requirements = "${./.}/requirements-development.txt";
--- devenv:python:virtualenv failed with error: Task exited with status: exit status: 1
--- devenv:python:virtualenv stdout:
0002.52: Requirements changed, running pip install -r /nix/store/gcrrm2121zwh623rh7k6lnh0ka923yac-requirements.txt...
--- devenv:python:virtualenv stderr:
0000.03: ERROR: Invalid requirement: '/nix/store/1w3xhq2aj1qp440v3bw7syimzysmrj1y-l55kkpj1biwidsdvqs71fvs4dg5zk156-source/requirements-development.txt': Expected package name at the start of dependency specifier
0000.03:     /nix/store/1w3xhq2aj1qp440v3bw7syimzysmrj1y-l55kkpj1biwidsdvqs71fvs4dg5zk156-source/requirements-development.txt
0000.03:     ^ (from line 1 of /nix/store/gcrrm2121zwh623rh7k6lnh0ka923yac-requirements.txt)
0000.03: Hint: It looks like a path. The path does exist. 
venv.requirements = "${config.env.DEVENV_ROOT}/requirements-development.txt";
--- devenv:python:virtualenv failed with error: Task exited with status: exit status: 1
--- devenv:python:virtualenv stdout:
0003.47: Requirements changed, running pip install -r /nix/store/r2m99br9mqf9ghyrbd851gggc52dxv6d-requirements.txt...
--- devenv:python:virtualenv stderr:
0000.03: ERROR: Invalid requirement: '/Users/USERNAME/.config/home-manager/requirements-development.txt': Expected package name at the start of dependency specifier
0000.03:     /Users/USERNAME/.config/home-manager/requirements-development.txt
0000.03:     ^ (from line 1 of /nix/store/r2m99br9mqf9ghyrbd851gggc52dxv6d-requirements.txt)
0000.03: Hint: It looks like a path. The path does exist. 

@sheeeng
Copy link
Author

sheeeng commented Dec 4, 2024

Using the main requirements.txt that is not referring to other files show errors too.

venv.requirements = "${./.}/requirements.txt";
0002.90: Requirements changed, running pip install -r /nix/store/86d7azxy1klg5fsmcxcaggn72k9kh1h6-requirements.txt...
--- devenv:python:virtualenv stderr:
0000.02: ERROR: Invalid requirement: '/nix/store/mmgh0vqz395b2wh4qdn1b7g73rq8lzhg-gy5mkq17rrcs934qnxxgsbzyrhfdbl1z-source/requirements.txt': Expected package name at the start of dependency specifier
0000.02:     /nix/store/mmgh0vqz395b2wh4qdn1b7g73rq8lzhg-gy5mkq17rrcs934qnxxgsbzyrhfdbl1z-source/requirements.txt
0000.02:     ^ (from line 1 of /nix/store/86d7azxy1klg5fsmcxcaggn72k9kh1h6-requirements.txt)
0000.02: Hint: It looks like a path. The path does exist. The argument you provided (/nix/store/mmgh0vqz395b2wh4qdn1b7g73rq8lzhg-gy5mkq17rrcs934qnxxgsbzyrhfdbl1z-source/requirements.txt) appears to be a requirements file. If that is the case, use the '-r' flag to install the packages specified within it.
---

@dz0ny
Copy link
Contributor

dz0ny commented Dec 4, 2024

(builtins.readFile ./requirements.txt) + "\n" + (builtins.readFile ./requirements-development.txt); Would also be a way to do it but you would need to remove the "nested" include. Maybe with this helper readFileWithoutFirstLine = file: builtins.substring (builtins.stringLength (builtins.readFile file) - 1) 1 (builtins.readFile file);

@sheeeng
Copy link
Author

sheeeng commented Dec 4, 2024

(builtins.readFile ./requirements.txt) + "\n" + (builtins.readFile ./requirements-development.txt); Would also be a way to do it but you would need to remove the "nested" include. Maybe with this helper readFileWithoutFirstLine = file: builtins.substring (builtins.stringLength (builtins.readFile file) - 1) 1 (builtins.readFile file);

These help! Thanks, @dz0ny!

@sheeeng sheeeng closed this as completed Dec 4, 2024
@domenkozar
Copy link
Member

domenkozar commented Dec 4, 2024

There's also #981

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants