Preparing a Nix flake for a Python program (Migra, using Poetry)

Thanks @i077. I saw this issue but can’t see how to apply it to my situation. In my pyproject.toml there are no exclude keys and the only thing that looks like a glob or path is README.md.

I made some new observations.

Observation 1: fresh pyproject.toml also doesn’t work

Recreating the pyproject.toml and poetry.lock without any dependencies doesn’t work:

$ nix develop

$ rm pyproject.toml poetry.lock
$ poetry init --no-interaction

This command will guide you through creating your pyproject.toml config.


You can specify a package in the following forms:
  - A single name (requests)
  - A name and a constraint (requests@^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - A url (https://example.com/packages/my-package-0.1.0.tar.gz)

$ poetry lock

  ValueError

  Invalid suffix ''

  at /nix/store/sx1bdyn5hv9wlq2x2jw72qx1vmbzcgdm-python3.8-pathlib-1.0.1/lib/python3.8/site-packages/pathlib.py:785 in with_suffix
       781│         """Return a new path with the file suffix changed (or added, if none)."""
       782│         # XXX if suffix is None, should the current suffix be removed?
       783│         drv, root, parts = self._flavour.parse_parts((suffix,))
       784│         if drv or root or len(parts) != 1:
    →  785│             raise ValueError("Invalid suffix %r" % (suffix))
       786│         suffix = parts[0]
       787│         if not suffix.startswith('.'):
       788│             raise ValueError("Invalid suffix %r" % (suffix))
       789│         name = self.name

If I add the readme field to [tool.poetry] like this:

--- pyproject.toml
+++ pyproject.toml
@@ -3,6 +3,7 @@
 version = "0.1.0"
 description = ""
 authors = ["Tad Lispy <tadeusz@lazurski.pl>"]
+readme = "README.md"
 
 [tool.poetry.dependencies]
 python = "^3.8"

I get the old error back:

$ poetry lock

  TypeError

  can't intern String

  at /nix/store/sx1bdyn5hv9wlq2x2jw72qx1vmbzcgdm-python3.8-pathlib-1.0.1/lib/python3.8/site-packages/pathlib.py:93 in parse_parts
        89│                     if x and x != '.':
        90│                         parsed.append(intern(x))
        91│             else:
        92│                 if rel and rel != '.':
    →   93│                     parsed.append(intern(rel))
        94│             if drv or root:
        95│                 if not drv:
        96│                     # If no drive is present, try to find one in the previous
        97│                     # parts. This makes the result of parsing e.g.

Setting readme = "./README.md" produces the Invalid suffix '' error again.

Observation 2: poetry from nixpkgs can build and run (!) migra

Like this:

$ nix shell nixpkgs#poetry

$ poetry build
Building migra (3.0)
  - Building sdist
  - Built migra-3.0.tar.gz
  - Building wheel
  - Built migra-3.0-py3-none-any.whl

$ poetry run migra
usage: migra [-h] [--unsafe] [--schema SCHEMA] [--exclude_schema EXCLUDE_SCHEMA]
             [--create-extensions-only] [--with-privileges] [--force-utf8]
             dburl_from dburl_target
migra: error: the following arguments are required: dburl_from, dburl_target

Notice that in this case I’m using nix shell with poetry instead of the development shell of the project (i.e. nix shell ... command instead of nix develop).

I really don’t know what to think about it.