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

pythonPackages.sqlalchemy: Add Postgres support #64284

Closed
wants to merge 1 commit into from

Conversation

ruuda
Copy link
Contributor

@ruuda ruuda commented Jul 4, 2019

This adds a propagated dependency on Psycopg2, which is needed for Postgres support in SQLAlchemy. The dependency can be turned off with a flag. (Although I don't know if it is customary to do this for Python packages, please tell me if there is a better way to do this.)

Motivation for this change

Psycopg2 in SQLAlchemy is needed to use Alembic with Postgres, as SQLAlchemy is a dependency of Alembic.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
    I did verify that alemic can run against Postgres after this change, but I did not test any other binaries.
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

This adds a propagated dependency on Psycopg2, which is needed for
Postgres support in SQLAlchemy. The dependency can be turned off with
a flag.

Psycopg2 in SQLAlchemy is in turn needed to use Alembic with Postgres.
@ruuda ruuda requested a review from FRidh as a code owner July 4, 2019 08:09
@FRidh
Copy link
Member

FRidh commented Jul 4, 2019

Optional dependencies in libraries don't make sense. If you want additional support, you can simply add that package to your environment.

@ruuda
Copy link
Contributor Author

ruuda commented Jul 4, 2019

Thanks for taking a look! I tried that at first, but the following does not work:

{ pkgs }:
  pkgs.buildEnv {
    name = "env-with-alembic";
    paths = [
      pkgs.python36
      pkgs.python36Packages.alembic
      pkgs.python36Packages.psycopg2
    ];
  }

If I enter that environment with nix run, or if I run

nix run -f channel:nixos-unstable pkgs.python36Packages.alembic pkgs.python36Packages.psycopg2

then I get

  File "/nix/store/c6hlkdfgax83053hfcq90h787ljkph7n-python3.6-SQLAlchemy-1.2.14/lib/python3.6/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 584, in dbapi
    import psycopg2
ModuleNotFoundError: No module named 'psycopg2'

when running Alembic, whereas with the change in this PR, I can run it just fine.

What would be the proper way to make the psycopg2 backend available then?

@FRidh
Copy link
Member

FRidh commented Jul 4, 2019

Please check the python.withPackages function in the Nixpkgs manual.

@ruuda
Copy link
Contributor Author

ruuda commented Jul 4, 2019

Ah, of course, thanks! Apologies for the noise.

@ruuda ruuda deleted the sqlalchemy-psycopg branch July 4, 2019 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants