English 中文(简体)
Conflicting Python Packages How can it be Resolved?
原标题:

So we went to implement something today, and discovered that there already is several applications relying on the old implementation of our inhouse python library. Called cis_py. Now all applications for our implementation currently sit in a folder called, bin. This is where cis_py currently resides.

Now we went to deploy one of our big python applications, which uses the new version of our inhouse library. We cannot simply overwrite the existing versions of it. Since this will cause all of the existing applications to break.

Basically i cannot update the existing applications, nor can i rewrite the new application. Now i was thinking of trying the following:

ciscis_py<python library files>

Then do a search and replace on the existing application and change the following:

cis_py.<some python file>

To

cis.cis_py.<some python file>

Unfortunately this results in several of the __init__.py files in the library breaking, due to the use of this:

from cis_py import rga
from cis_py import util

Today is implementation day, and it must go live today, since in a few hours we start receiving data automatically.

How and what can i possibly do? Everything must reside in a single folder called bin. Due to the automatic processing system. Is there some way i can possibly trick python?

最佳回答

Try import sys; sys.path.insert(0, "cis") as the very start of your main Python file.

问题回答

It looks like Alex Martelli s solution solved the emergency for you. Here s another solution, one I think better for the long term.

In source files, replace the line

import cis_py

with the line

import cis.cis_py as cis_py

That way, when later code says from cis_py import foo, it will work.

This is less "magical", because each source file will include this changed import line, so someone studying a source file will understand the true source of the cis_py module (without needing to also study the main Python source file).

Step one is to start telling people about this issue. Talk to your co-workers and boss and inform them of the problem you discovered, since it is possible that the go-live will have to be called off or postponed while a solution is worked on. Changes will have to be made somewhere, and it would be good (and may be required) to perform additional testing to verify those changes don t break anything.

Without knowing much about how your system is being run, one guess is that maybe you can run the new version under a modified environment that directs it at the new version of the library?

Add a version to the name: cis_py2. You may have to make changes in the class, but nothing that can t be done with a quick script (don t run this without testing it first):

sed  s/cis_py/cis_py2/g  `find -name  .py$ `

This assumes that cis_py is only the module name and nothing else has the name.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签