No description
Find a file
Tobias Pflug e80f0acd83
Merge pull request #63 from nix-community/flamegraphs
Add development tool to generate flame graphs for nix-instantiate
2020-02-27 10:21:25 +01:00
bin Add CLI to supplement git hashes 2019-12-28 21:45:51 +00:00
hooks Turn pyproject.toml patching into a hook 2020-02-23 14:37:01 +00:00
pkgs/poetry poetry: 1.0.2 -> 1.0.3 2020-02-01 21:56:43 +00:00
tests Provide withDefaults and withoutDefaults 2020-02-25 14:24:48 +01:00
tools Add development tools to generate flame graphs for nix-instantiate 2020-02-27 08:44:42 +00:00
.envrc Add .envrc for direnv 2020-02-27 08:44:43 +00:00
.gitignore Add flamegraph artifacts to CI 2020-02-27 08:58:12 +00:00
.gitlab-ci.yml Add flamegraph artifacts to CI 2020-02-27 08:58:12 +00:00
check-fmt ci: add nix code formatting check 2019-12-13 18:35:18 +01:00
cli.nix nixpkgs-fmt fixup 2020-01-22 17:21:03 +00:00
default.nix Drop meta attribute for mkPoetryPackages/mkPoetryEnv 2020-02-26 09:24:23 +01:00
extensions.json Add support for eggs 2020-01-08 14:03:01 +00:00
flake.lock Add nix flake 2019-11-19 20:00:38 +00:00
flake.nix nixpkgs-fmt: format all the nix code 2019-12-11 13:31:22 +01:00
generate.py Add support for eggs 2020-01-08 14:03:01 +00:00
lib.nix Add support for python version constraints from pyproject.toml 2020-02-24 12:25:51 +00:00
Makefile Properly fetch sdists with extension 2019-06-24 17:01:27 +01:00
mk-poetry-dep.nix Turn pyproject.toml patching into a hook 2020-02-23 14:37:01 +00:00
overlay.nix Add overlay files 2019-11-19 16:34:50 +00:00
overrides.nix Add overrides for fancycompleter and pylint 2020-02-26 18:55:41 +01:00
pep425.nix Improve PEP425 support 2019-12-17 18:13:11 +01:00
pep508.nix Fix platform_python_implementation field 2020-01-22 18:33:24 +00:00
README.md Provide API documentation in README 2020-02-26 10:15:49 +01:00
semver.nix Add full operator support 2020-01-09 12:48:07 +00:00
shell.nix Add development tools to generate flame graphs for nix-instantiate 2020-02-27 08:44:42 +00:00

poetry2nix

poetry2nix turns Poetry projects into Nix derivations without the need to actually write Nix expressions. It does so by parsing pyproject.toml and poetry.lock and converting them to Nix derivations on the fly.

API

The poetry2nix public API consists of the following attributes:

mkPoetryApplication

Creates a Python application using the Python interpreter specified based on the designated poetry project and lock files. mkPoetryApplication takes an attribute set with the following attributes (attributes without default are mandatory):

  • src: project source.
  • projectDir: path to the root of the project.
  • pyproject: path to pyproject.toml (default: projectDir + "/pyproject.toml").
  • poetrylock: poetry.lock file path (default: projectDir + "/poetry.lock").
  • overrides: Python overrides to apply (default: [defaultPoetryOverrides]).
  • meta: application meta data (default: {}).
  • python: The Python interpreter to use (default: pkgs.python3).

Example

poetry2nix.mkPoetryApplication {
    src = lib.cleanSource ./.;
    projectDir = ./.;
}

See ./pkgs/poetry/default.nix for a working example.

mkPoetryEnv

Creates an environment that provides a Python interpreter along with all dependencies declared by the designated poetry project and lock files. mkPoetryEnv takes an attribute set with the following attributes (attributes without default are mandatory):

  • projectDir: path to the root of the project.
  • pyproject: path to pyproject.toml (default: projectDir + "/pyproject.toml").
  • poetrylock: poetry.lock file path (default: projectDir + "/poetry.lock").
  • overrides: Python overrides to apply (default: [defaultPoetryOverrides]).
  • python: The Python interpreter to use (default: pkgs.python3).

Example

poetry2nix.mkPoetryEnv {
    projectDir = ./.;
}

See ./tests/env/default.nix for a working example.

mkPoetryPackages

Creates an attribute set of the shape { python, poetryPackages, pyProject, poetryLock }. Where python is the interpreter specified, poetryPackages is a list of all generated python packages, pyProject is the parsed pyproject.toml and poetryLock is the parsed poetry.lock file. mkPoetryPackages takes an attribute set with the following attributes (attributes without default are mandatory):

  • projectDir: path to the root of the project.
  • pyproject: path to pyproject.toml (default: projectDir + "/pyproject.toml").
  • poetrylock: poetry.lock file path (default: projectDir + "/poetry.lock").
  • overrides: Python overrides to apply (default: [defaultPoetryOverrides]).
  • python: The Python interpreter to use (default: pkgs.python3).

Example

poetry2nix.mkPoetryPackages {
    projectDir = ./.;
    python = python35;
}

defaultPoetryOverrides

poetry2nix bundles a set of default overrides that fix problems with various Python packages. These overrides are implemented in overrides.nix.

overrides.withDefaults

Returns a list containing the specified overlay and defaultPoetryOverrides.

Example

poetry2nix.mkPoetryEnv {
    projectDir = ./.;
    overrides = poetry2nix.overrides.withDefaults (self: super: { foo = null; });
}

See ./tests/override-support/default.nix for a working example.

overrides.withoutDefaults

Returns a list containing just the specified overlay, ignoring defaultPoetryOverrides.

Example

poetry2nix.mkPoetryEnv {
    projectDir = ./.;
    overrides = poetry2nix.overrides.withoutDefaults (self: super: { foo = null; });
}

Contributing

Contributions to this project are welcome in the form of GitHub PRs. Please consider the following before creating PRs:

  • This project uses nixpkgs-fmt for formatting the Nix code. You can use `nix-shell --run "nixpkgs-fmt ." to format everything.
  • If you are planning to make any considerable changes, you should first present your plans in a GitHub issue so it can be discussed.
  • If you add new features please consider adding tests.

License

poetry2nix is released under the terms of the MIT license.