Database drivers become optional extras

Đang mở
#1,626 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 6 ngày

@dimitri-yatsenko đang làm issue này rồi.

Từ ngày 17/10/2026.

  • #1628 của @dimitri-yatsenko — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
mysql, postgresql, python

Hướng nghiên cứu

Start by reviewing the packaging metadata for the PostgreSQL and MySQL extras, the test dependency group, and the adapter registry and connection paths. Update adapters so drivers are imported only when connecting, with missing-driver errors naming the correct extra, while preserving conda run requirements. Run the relevant packaging and adapter tests; done means bare installs load no drivers, each extra supplies its driver, test/dev environments include both, and PostgreSQL code catches DataJointError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement

Motivation

DataJoint supports two production database backends, PostgreSQL and MySQL, but the two drivers are packaged differently:

  • pymysql (MySQL) is a core dependency. Every pip install datajoint installs it, including installs that only ever connect to PostgreSQL.
  • psycopg2-binary (PostgreSQL) is the optional datajoint[postgres] extra.

import datajoint also imports pymysql at load time, through the adapter registry, and imports psycopg2 too when it happens to be installed. A process that never connects to a database still loads both drivers.

Treating the backends alike means each driver is installed only when it is needed. It also leaves room for more backends later without adding a hard dependency for each one.

The change

  • Every database driver becomes an optional extra:

    • pip install "datajoint[postgres]" installs psycopg2-binary
    • pip install "datajoint[mysql]" installs pymysql (same >=0.7.2 floor as today)
  • A bare pip install datajoint installs no database driver, and import datajoint loads none.

  • Each adapter imports its driver when a connection is made. When the driver is missing, connecting raises a DataJointError that names the extra, e.g.:

    The MySQL backend requires the pymysql driver, which is not installed. Install it with: pip install "datajoint[mysql]"
    

    The PostgreSQL adapter raises the same kind of error. It used to raise ImportError.

  • The PostgreSQL adapter imports the psycopg2 module, so either the psycopg2 or the psycopg2-binary distribution satisfies it.

  • The test dependency group and the test and dev extras install every driver.

  • conda has no extras, so the conda-forge package keeps listing the drivers as run requirements.

Migration for MySQL users

  • Install the MySQL extra: pip install "datajoint[mysql]". In a requirements file, write datajoint[mysql] in place of datajoint.
  • An upgrade in place keeps a pymysql that is already installed. A fresh environment built from a requirements file that lists only datajoint has no driver, and the first connection says which extra to install.
  • Code that caught ImportError from PostgreSQLAdapter() should catch DataJointError.
Ngôn ngữ chính
Python
Star
198
Fork
103
Merge trung bình
6 ngày 1 giờ
Pull request đã merge (30 ngày)
10

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của datajoint/datajoint-python

Tất cả issue của datajoint/datajoint-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.