Edgewall Software
Modify

Opened 6 years ago

Closed 6 years ago

Last modified 12 months ago

#12989 closed enhancement (fixed)

Make psycopg2-binary satisfy installation requirements

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.2.3
Component: database backend Version:
Severity: normal Keywords: postgres
Cc: Branch:
Release Notes:

The psycopg2-binary package satisfies requirements for using the PostgreSQL database backend.

API Changes:
Internal Changes:

Description

I've been getting this warning:

/Users/rjollos/Documents/Workspace/trac-dev/pve/lib/python2.7/site-packages/psycopg2/__init__.py:144:
UserWarning: The psycopg2 wheel package will be renamed from release 2.8;
in order to keep installing from binary please use "pip install psycopg2-binary" instead.
For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.

On installing psycopg2-binary, the module postgres_backend module is skipped because the installation requirement isn't satisfied.

I think we went down a similar path when supporting the MySQL library dependencies and couldn't find a way to write the equivalent of psycopg2 or psycopg-binary as the installation requirement.

$pip list --format=columns | grep psycopg2
psycopg2        2.7.4
psycopg2-binary 2.7.4

I haven't researched potential solutions yet.

Attachments (0)

Change History (11)

comment:1 by Ryan J Ollos, 6 years ago

Milestone: 1.0.171.0.18

comment:2 by Jun Omae, 6 years ago

After the patch (PoC):

  1. DistributionNotFound is raised if psycopg2 module is not available.
    18:05:07 Trac[loader] DEBUG: Loading plugin "trac.db.postgres" from "/dev/shm/venv/lib/python2.7/site-packages"
    18:05:07 Trac[loader] DEBUG: Skipping "trac.db.postgres = trac.db.postgres_backend": DistributionNotFound: The 'psycopg2>=2.0 or psycopg2-binary>=2.0' distribution was not found and is required by Trac
    
  2. pip install Trac[psycopg2] leads installing Trac and psycopg2.
  3. pip install Trac[psycopg2-binary] leads installing Trac and psycopg2-binary.
  • setup.py

    diff --git a/setup.py b/setup.py
    index 5f6f2d7b1..27b179373 100755
    a b setup(  
    9999        'babel': ['Babel>=0.9.5'],
    100100        'mysql': ['MySQL-python >= 1.2.2'],
    101101        'postgresql': ['psycopg2 >= 2.0'],
     102        'psycopg2': ['psycopg2 >= 2.0'],
     103        'psycopg2-binary': ['psycopg2-binary'],
    102104        'pygments': ['Pygments>=0.6'],
    103105        'rest': ['docutils>=0.3.9'],
    104106        'textile': ['textile>=2.0'],
    setup(  
    115117        trac.admin.web_ui = trac.admin.web_ui
    116118        trac.attachment = trac.attachment
    117119        trac.db.mysql = trac.db.mysql_backend[mysql]
    118         trac.db.postgres = trac.db.postgres_backend[postgresql]
     120        trac.db.postgres = trac.db.postgres_backend
    119121        trac.db.sqlite = trac.db.sqlite_backend
    120122        trac.mimeview.patch = trac.mimeview.patch
    121123        trac.mimeview.pygments = trac.mimeview.pygments[pygments]
  • trac/db/postgres_backend.py

    diff --git a/trac/db/postgres_backend.py b/trac/db/postgres_backend.py
    index 3b34ffd94..b63866319 100644
    a b  
    1414#
    1515# Author: Christopher Lenz <cmlenz@gmx.de>
    1616
     17from pkg_resources import DistributionNotFound
    1718import os
    1819import re
    1920
    try:  
    3738    from psycopg2.extensions import register_type, UNICODE, \
    3839                                    register_adapter, AsIs, QuotedString
    3940except ImportError:
    40     has_psycopg = False
    41     psycopg2_version = None
     41    raise DistributionNotFound('psycopg2>=2.0 or psycopg2-binary', ['Trac'])
    4242else:
    4343    has_psycopg = True
    4444    register_type(UNICODE)

comment:3 by Ryan J Ollos, 6 years ago

Milestone: 1.0.181.2.3

I'm reviewing your patch and see now that the issue only affects 1.2-stable (#12096).

Version 0, edited 6 years ago by Ryan J Ollos (next)

comment:4 by Ryan J Ollos, 6 years ago

Changes look good to me. I added a little cleanup on this branch: log:rjollos.git:t12989_psycopg2_binary.

I've never considered specifying extras while installing Trac. That's a good feature.

comment:5 by Ryan J Ollos, 6 years ago

Owner: set to Ryan J Ollos
Status: newassigned

comment:6 by Ryan J Ollos, 6 years ago

Release Notes: modified (diff)

Committed to 1.2-stable in r16572, but reverted in [16573:16574]. Sorry, I was careless with the commits.

Last edited 6 years ago by Ryan J Ollos (previous) (diff)

comment:7 by Ryan J Ollos, 6 years ago

[5826f28ee/rjollos.git] would import the necessary backend, depending on the dburi. Needs to be exercised a bit more for different test execution scenarios. On trunk we can use importlib rather than __import__.

comment:8 by Ryan J Ollos, 6 years ago

When psycopg2 or psycopg2-binary is not installed, running the tests results in:

$ make db=postgres test

Python: /Users/rjollos/.pyenv/shims/python

...

  File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/db/postgres_backend.py", line 41, in <module>
    raise DistributionNotFound('psycopg2>=2.0 or psycopg2-binary', ['Trac'])
pkg_resources.DistributionNotFound: The 'psycopg2>=2.0 or psycopg2-binary' distribution was not found and is required by Trac

Previously the tests would just continue running with lots of failures.

$ make db=postgres test

Python: /Users/rjollos/.pyenv/shims/python

...

writing manifest file 'Trac.egg-info/SOURCES.txt'
python  ./trac/test.py --skip-functional-tests
EEEEEEEEEEEEEEEEEEEE.........................EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE.........................^Z
[4]+  Stopped                 make db=postgres test

I think the new behavior is better.

comment:9 by Ryan J Ollos, 6 years ago

Proposed changes in [9310a0e83/rjollos.git].

The self.error messages were removed because I don't see a way the statements will ever be reached following the changes in #12096.

comment:10 by Ryan J Ollos, 6 years ago

Resolution: fixed
Status: assignedclosed

Committed to 1.2-stable in r16597, r16598, merged to trunk in r16599.

comment:11 by Ryan J Ollos, 6 years ago

Additional change in r16600.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.