alan-turing-institute / data-safe-haven

https://data-safe-haven.readthedocs.io
BSD 3-Clause "New" or "Revised" License
61 stars 15 forks source link

Switch to psycopg[binary] #2217

Closed jemrobinson closed 1 month ago

jemrobinson commented 1 month ago

:white_check_mark: Checklist

:vertical_traffic_light: Depends on

n/a

:arrow_heading_up: Summary

From the installation page psycopg[binary] packages its own version of libpq. This avoids a requirement that the end user has libpq installed.

Note that this would mean that we drop support for platforms that aren't supported by psycopg[binary] which include Apple Mac M1.

:closed_umbrella: Related issues

Attempting to run dsh commands using psycopg without libpq installed gives errors like the following:

Traceback (most recent call last):
  File "/Users/jrobinson/.local/bin/dsh", line 5, in <module>
    from data_safe_haven.commands.cli import main
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/data_safe_haven/commands/__init__.py", line 1, in <module>
    from .cli import application
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/data_safe_haven/commands/cli.py", line 10, in <module>
    from .config import config_command_group
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/data_safe_haven/commands/config.py", line 9, in <module>
    from data_safe_haven.config import ContextManager, DSHPulumiConfig, SHMConfig, SREConfig
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/data_safe_haven/config/__init__.py", line 1, in <module>
    from .context import Context
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/data_safe_haven/config/context.py", line 12, in <module>
    from data_safe_haven.external import AzureSdk
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/data_safe_haven/external/__init__.py", line 5, in <module>
    from .interface.azure_postgresql_database import AzurePostgreSQLDatabase
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/data_safe_haven/external/interface/azure_postgresql_database.py", line 7, in <module>
    import psycopg
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/psycopg/__init__.py", line 9, in <module>
    from . import pq  # noqa: F401 import early to stabilize side effects
    ^^^^^^^^^^^^^^^^
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/psycopg/pq/__init__.py", line 118, in <module>
    import_from_libpq()
  File "/Users/jrobinson/.local/pipx/venvs/data-safe-haven/lib/python3.12/site-packages/psycopg/pq/__init__.py", line 110, in import_from_libpq
    raise ImportError(
ImportError: no pq wrapper available.
Attempts made:
- couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
- couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
- couldn't import psycopg 'python' implementation: libpq library not found

:microscope: Tests

Tested locally

github-actions[bot] commented 1 month ago

Coverage report

This PR does not seem to contain any modification to coverable code.

craddm commented 1 month ago

Was going to add that this does actually improve things in Windows 10 at least, as I had to install psycopg[binary] (hadn't had chance to report yet) to be able to run dsh commands.

jemrobinson commented 1 month ago

@craddm : Are you happy to merge this then?

craddm commented 1 month ago

Fine by me (works fine for my setup)

jemrobinson commented 1 month ago

Merged (works on my machine) :rofl: