Merge lp:~barry/pkgme/envar into lp:pkgme

Proposed by Barry Warsaw
Status: Merged
Merged at revision: 44
Proposed branch: lp:~barry/pkgme/envar
Merge into: lp:pkgme
Diff against target: 74 lines (+28/-7)
3 files modified
README.txt (+8/-0)
pkgme/__init__.py (+7/-5)
pkgme/backend.py (+13/-2)
To merge this branch: bzr merge lp:~barry/pkgme/envar
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+43952@code.launchpad.net

Description of the change

  Several changes to make running pkgme from the virtualenv easier.

  * Move package imports into the function so that the side effect of
    'import pkgme' to get the distutils extension command doesn't try to import
    a lot of unrelated, unnecessary, and potentially unavailable stuff.
  * Add support for $PKGME_EXTERNAL_BACKEND_PATHS environment variable,
    primarily useful so that pkgme can find its built-in backends when run from
    a virtualenv (since the landmark search will fail).
  * Add a bit of documentation to the README.

To post a comment you must log in.
lp:~barry/pkgme/envar updated
39. By Barry Warsaw

Trunk merge

Revision history for this message
James Westby (james-w) wrote :

8 +To run pkgme out of your virtualenv, set the ``$PKGME_EXTERNAL_BACKEND_PATHS``
9 +environment variable to the directory inside the pkgme source tree named
10 +``backends/``. For example::

Is this needed as it currently doesn't install the backends?

62 +if PKGME_EXTERNAL_BACKEND_PATHS is None:
63 + EXTERNAL_BACKEND_PATHS = ["/usr/share/pkgme/backends/"]
64 +else:
65 + EXTERNAL_BACKEND_PATHS = PKGME_EXTERNAL_BACKEND_PATHS.split(os.pathsep)
66 root_dir = os.path.join(
67 os.path.dirname(os.path.abspath(__file__)), os.pardir)
68 if os.path.exists(os.path.join(root_dir, "setup.py")):
69 - EXTERNAL_BACKEND_PATHS.insert(0, os.path.join(root_dir, "pkgme", "backends"))
70 + EXTERNAL_BACKEND_PATHS.insert(
71 + 0, os.path.join(root_dir, "pkgme", "backends"))

If PKGME_EXTERNAL_BACKEND_PATHS overrides /usr/share/pkgme/backends/ should
it also override the ones in the source tree? Is that what "EXTERNAL" is there
for? I'm not sure why you would want to override, but not completely override.
Given that most backends are likely to be in your source tree, the env variable
won't have a lot of effect if you are running from source.

I have no problem adding an env var for this, but I think we should make it
so that it isn't needed when doing development.

Thanks,

James

review: Approve
Revision history for this message
Barry Warsaw (barry) wrote :

On Dec 18, 2010, at 01:29 AM, James Westby wrote:

>Review: Approve
>8 +To run pkgme out of your virtualenv, set the ``$PKGME_EXTERNAL_BACKEND_PATHS``
>9 +environment variable to the directory inside the pkgme source tree named
>10 +``backends/``. For example::
>
>Is this needed as it currently doesn't install the backends?

Right. I do think the right thing (eventually) to do is to install the
backends via 'python setup.py install'.

>62 +if PKGME_EXTERNAL_BACKEND_PATHS is None:
>63 + EXTERNAL_BACKEND_PATHS = ["/usr/share/pkgme/backends/"]
>64 +else:
>65 + EXTERNAL_BACKEND_PATHS = PKGME_EXTERNAL_BACKEND_PATHS.split(os.pathsep)
>66 root_dir = os.path.join(
>67 os.path.dirname(os.path.abspath(__file__)), os.pardir)
>68 if os.path.exists(os.path.join(root_dir, "setup.py")):
>69 - EXTERNAL_BACKEND_PATHS.insert(0, os.path.join(root_dir, "pkgme", "backends"))
>70 + EXTERNAL_BACKEND_PATHS.insert(
>71 + 0, os.path.join(root_dir, "pkgme", "backends"))
>
>If PKGME_EXTERNAL_BACKEND_PATHS overrides /usr/share/pkgme/backends/ should
>it also override the ones in the source tree? Is that what "EXTERNAL" is there
>for? I'm not sure why you would want to override, but not completely override.
>Given that most backends are likely to be in your source tree, the env variable
>won't have a lot of effect if you are running from source.

I think you're right, it should. But then, the envar should probably be
called $PKGME_BACKEND_PATHS (drop the EXTERNAL).

>I have no problem adding an env var for this, but I think we should make it
>so that it isn't needed when doing development.

My test-fixes branch should take care of that, but I still think this
environment variable will be useful.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.txt'
2--- README.txt 2010-12-15 01:59:12 +0000
3+++ README.txt 2010-12-17 21:24:29 +0000
4@@ -38,6 +38,14 @@
5 % python setup.py install
6 <hack>
7
8+To run pkgme out of your virtualenv, set the ``$PKGME_EXTERNAL_BACKEND_PATHS``
9+environment variable to the directory inside the pkgme source tree named
10+``backends/``. For example::
11+
12+ % export PKGME_EXTERNAL_BACKEND_PATHS=`pwd`/pkgme/backends
13+ % cd my-about-to-be-packaged-code
14+ % pkgme
15+
16 When you're done, just run the ``deactivate`` command and blow away
17 `/arbitrary/path`.
18
19
20=== modified file 'pkgme/__init__.py'
21--- pkgme/__init__.py 2010-11-10 23:20:33 +0000
22+++ pkgme/__init__.py 2010-12-17 21:24:29 +0000
23@@ -26,15 +26,17 @@
24 ]
25
26
27-from pkgme.backend import get_info_for
28-from pkgme.package_files import default_package_file_group
29-from pkgme.write import Writer
30-
31-
32 __version__ = '0.1'
33
34
35 def write_packaging(path):
36+ # Do these imports in the function to reduce the side-effects of importing
37+ # pkgme. This avoids the need for setup.py of the tool being packaged
38+ # from having to find all the imported dependencies when running the
39+ # extension pkgme_info setup.py command.
40+ from pkgme.backend import get_info_for
41+ from pkgme.package_files import default_package_file_group
42+ from pkgme.write import Writer
43 info = get_info_for(path)
44 files = default_package_file_group.get_files(info)
45 Writer().write(files, path)
46
47=== modified file 'pkgme/backend.py'
48--- pkgme/backend.py 2010-12-13 01:34:21 +0000
49+++ pkgme/backend.py 2010-12-17 21:24:29 +0000
50@@ -8,11 +8,22 @@
51 )
52
53
54-EXTERNAL_BACKEND_PATHS = ["/usr/share/pkgme/backends/"]
55+# Where do the backends live? The environment variable overrides the system
56+# built-in location. When run from the source directory (i.e. we can find the
57+# setup.py landmark), we add our own backends directory. XXX This does not
58+# work with virtualenv, because root_dir will end up being inside the
59+# installed egg directory, which won't have the setup.py - or the backends for
60+# that matter.
61+PKGME_EXTERNAL_BACKEND_PATHS = os.environ.get('PKGME_EXTERNAL_BACKEND_PATHS')
62+if PKGME_EXTERNAL_BACKEND_PATHS is None:
63+ EXTERNAL_BACKEND_PATHS = ["/usr/share/pkgme/backends/"]
64+else:
65+ EXTERNAL_BACKEND_PATHS = PKGME_EXTERNAL_BACKEND_PATHS.split(os.pathsep)
66 root_dir = os.path.join(
67 os.path.dirname(os.path.abspath(__file__)), os.pardir)
68 if os.path.exists(os.path.join(root_dir, "setup.py")):
69- EXTERNAL_BACKEND_PATHS.insert(0, os.path.join(root_dir, "pkgme", "backends"))
70+ EXTERNAL_BACKEND_PATHS.insert(
71+ 0, os.path.join(root_dir, "pkgme", "backends"))
72
73
74 def get_info_for(path, loader=None, selector_cls=None):

Subscribers

People subscribed via source and target branches

to all changes: