Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'value,': 0.03; '"""': 0.05; 'modify': 0.05; '%s"': 0.07; 'exit': 0.07; 'subject:code': 0.07; 'tests,': 0.07; 'type,': 0.07; '"""create': 0.09; 'domains,': 0.09; 'def': 0.10; 'to:name:python-list': 0.15; "api's": 0.16; 'perforce': 0.16; 'subject:between': 0.16; 'subject:projects': 0.16; 'temp': 0.16; 'copied': 0.17; 'pieces': 0.17; 'projects,': 0.17; 'switched': 0.17; 'code.': 0.20; 'project,': 0.24; 'wondering': 0.26; '(we': 0.27; 'experiences': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this?': 0.28; 'skip:_ 10': 0.29; 'class': 0.29; "i'm": 0.29; 'on,': 0.30; 'sense': 0.31; 'code': 0.31; 'could': 0.32; 'problem': 0.33; 'anyone': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'project': 0.34; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'really': 0.36; 'ability': 0.36; 'except': 0.36; 'but': 0.36; 'useful': 0.36; "i'll": 0.36; 'should': 0.36; 'moment': 0.37; 'received:209': 0.37; 'skip:l 20': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'link': 0.60; 'remove': 0.61; 'real': 0.61; 'share': 0.61; 'first': 0.61; 'back': 0.62; 'situation': 0.62; 'between': 0.63; 'different': 0.63; 'world': 0.63; 'burden': 0.65; 'potentially': 0.66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=l3bG70fZVYkQC/L/fS+fAMepkR/tgHQ6bBDvRBTdqmw=; b=WHExmL13jP1rnEGFLKlJk2PJhd64h1PPlDnZWnyFg/u1Osp0+nhTdH+2AZcA/CEWT9 2Fx20MjoTC+3lgpJyAGWRHNE1DKegCr8TadaofZ0YIYUegCi4KLNMjAd2W4swyJMyCv1 +O23N0K18c75Sd8LAylmDRA9WFqK2WtL8thmHG8SVFaYHD9e8NjzK0067iHM8FgYJIRC vx1vCZkin3opEzDcMP7f+L3eqMeOSuOlHOJtJyA/xg2+rzdrJZqFpL23c/Foa7nzI1a1 V3Ve4kxDsPqDPAh6F9NX66Xr+f8AxqW7PMXSJUkwQRdD8Y8IeS+r0ixHYABgEzFu4/8U srtA== MIME-Version: 1.0 Date: Mon, 13 Aug 2012 17:53:32 +0100 Subject: Sharing code between different projects? From: andrea crotti To: python-list Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344876821 news.xs4all.nl 6939 [2001:888:2000:d::a6]:47400 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26999 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?