Skip to content

Commit

Permalink
doc: Add mkVirtualEnv doc
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Dec 30, 2024
1 parent de04140 commit 71ea337
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
5 changes: 4 additions & 1 deletion build/hooks/make-venv/make_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class FileCollisionError(Exception):
def __init__(self, inputs: list[Path]):
err = f"""Two or more packages are trying to provide the same file with different contents
Files: {' '.join((str(x) for x in inputs))}"""
Files: {' '.join((str(x) for x in inputs))}
See https://pyproject-nix.github.io/pyproject.nix/build/packages.html for strategies for dealing with file collisions"""
super().__init__(err)


Expand Down
48 changes: 46 additions & 2 deletions build/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ let
resolveBuildSystem = mkResolveBuildSystem pythonPkgsBuildHost;
resolveVirtualEnv = mkResolveVirtualEnv pkgsFinal;

# Make a virtual env from resolved dependencies
mkVirtualEnv =
name: spec:
pkgsFinal.stdenv.mkDerivation (finalAttrs: {
Expand Down Expand Up @@ -114,7 +113,52 @@ in
}:
makeScope newScope (
final:
(mkPythonSet {
{
# Create a dummy mkVirtualEnv function to make nixdoc happy

/*
Create a virtual environment from dependency specification
### Example
```nix
mkVirtualEnv "foo-env" {
foo = [ "extra" ];
}
```
### Example (skip file)
```nix
(mkVirtualEnv "foo-env" {
foo = [ "extra" ];
}).overrideAttrs(old: {
# Skip LICENSE file from package root.
venvSkip = [ "LICENSE" ];
})
```
### Example (ignore collisions)
```nix
(mkVirtualEnv "foo-env" {
foo = [ "extra" ];
}).overrideAttrs(old: {
# You could also ignore all collisions with:
# venvIgnoreCollisions = [ "*" ];
venvIgnoreCollisions = [ "lib/python${python.pythonVersion}/site-packages/build_tools" ];
})
```
*/
mkVirtualEnv =
# Venv name
name:
# Dependency specification
spec:
# Note: Funky throw construct is to satisfy deadnix not to get name -> _name formatting.
throw "${name} ${spec}";
}
// (mkPythonSet {
inherit python stdenv;
pkgsFinal = final;
pythonPkgsBuildHost = final.pythonPkgsHostHost;
Expand Down
3 changes: 2 additions & 1 deletion doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
- [lib](./build/lib/index.md)
- [renderers](./build/lib/renderers.md)
- [resolvers](./build/lib/resolvers.md)
- [packages.hooks](./build/hooks.md)
- [packages](./build/packages.md)
- [packages.hooks](./build/hooks.md)
- [hacks](./build/hacks.md)
- [util](./build/util.md)

Expand Down

0 comments on commit 71ea337

Please sign in to comment.