Re: Sharing code between different projects?

Discussion in 'Python' started by Jean-Michel Pichavant, Aug 14, 2012.

  1. andrea crotti wrote:
    > I am in the situation where I am working on different projects that
    > might potentially share a lot of code.
    >
    > I started to work on project A, then switched completely to project B
    > and in the transiction I copied over a lot of code with the
    > corresponding tests, and I started to modify it.
    >
    > Now it's time to work again on project A, but I don't want to copy
    > things over again.
    >
    > I would like to design a simple and nice way to share between projects,
    > where the things I want to share are simple but useful things as for
    > example:
    >
    > class TempDirectory:
    > """Create a temporary directory and cd to it on enter, cd back to
    > the original position and remove it on exit
    > """
    > def __init__(self):
    > self.oldcwd = getcwd()
    > self.temp_dir = mkdtemp()
    >
    > def __enter__(self):
    > logger.debug("create and move to temp directory %s" % self.temp_dir)
    > return self.temp_dir
    >
    > def __exit__(self, type, value, traceback):
    > # I first have to move out
    > chdir(self.oldcwd)
    > logger.debug("removing the temporary directory and go back to
    > the original position %s" % self.temp_dir)
    > rmtree(self.temp_dir)
    >
    >
    > The problem is that there are functions/classes from many domains, so it
    > would not make much sense to create a real project, and the only name I
    > could give might be "utils or utilities"..
    >
    > In plus the moment the code is shared I must take care of versioning and
    > how to link different pieces together (we use perforce by the way).
    >
    > If then someone else except me will want to use these functions then of
    > course I'll have to be extra careful, designing really good API's and so
    > on, so I'm wondering where I should set the trade-off between ability to
    > share and burden to maintain..
    >
    > Anyone has suggestions/real world experiences about this?
    >

    I can think of logilab-common (http://www.logilab.org/848/)

    Having a company-wide python module properly distributed is one to
    achieve your goal. Without distributing your module to the public,
    there's a way to have a pypi-like server runnning on your private network :

    http://pypi.python.org/pypi/pypiserver/

    JM

    Note : looks like pypi.python.org is having some trouble, the above link is broken. Search for recent announcement about pypiserver.
     
    Jean-Michel Pichavant, Aug 14, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andrea crotti

    Sharing code between different projects?

    andrea crotti, Aug 13, 2012, in forum: Python
    Replies:
    1
    Views:
    123
    Steven D'Aprano
    Aug 14, 2012
  2. Chris Angelico
    Replies:
    0
    Views:
    164
    Chris Angelico
    Aug 13, 2012
  3. andrea crotti
    Replies:
    2
    Views:
    142
    Miki Tebeka
    Aug 15, 2012
  4. Cameron Simpson

    Re: Sharing code between different projects?

    Cameron Simpson, Aug 14, 2012, in forum: Python
    Replies:
    0
    Views:
    187
    Cameron Simpson
    Aug 14, 2012
  5. andrea crotti
    Replies:
    0
    Views:
    138
    andrea crotti
    Aug 15, 2012
Loading...

Share This Page