eric6/PipInterface/Pip.py

changeset 8090
c53117374255
parent 8085
f6db8b3ecea9
child 8143
2c730d5fd177
equal deleted inserted replaced
8089:e43bf8d7baf9 8090:c53117374255
36 class Pip(QObject): 36 class Pip(QObject):
37 """ 37 """
38 Class implementing the pip GUI logic. 38 Class implementing the pip GUI logic.
39 """ 39 """
40 DefaultPyPiUrl = "https://pypi.org" 40 DefaultPyPiUrl = "https://pypi.org"
41 DefaultIndexUrlXml = DefaultPyPiUrl + "/pypi" 41 DefaultIndexUrlPypi = DefaultPyPiUrl + "/pypi"
42 DefaultIndexUrlPip = DefaultPyPiUrl + "/simple" 42 DefaultIndexUrlSimple = DefaultPyPiUrl + "/simple"
43 DefaultIndexUrlSearch = DefaultPyPiUrl + "/search/"
43 44
44 def __init__(self, parent=None): 45 def __init__(self, parent=None):
45 """ 46 """
46 Constructor 47 Constructor
47 48
502 @rtype str 503 @rtype str
503 """ 504 """
504 if Preferences.getPip("PipSearchIndex"): 505 if Preferences.getPip("PipSearchIndex"):
505 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple" 506 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
506 else: 507 else:
507 indexUrl = Pip.DefaultIndexUrlPip 508 indexUrl = Pip.DefaultIndexUrlSimple
508 509
509 return indexUrl 510 return indexUrl
510 511
511 def getIndexUrlXml(self): 512 def getIndexUrlPypi(self):
512 """ 513 """
513 Public method to get the index URL for XML RPC calls. 514 Public method to get the index URL for PyPI API calls.
514 515
515 @return index URL for XML RPC calls 516 @return index URL for XML RPC calls
516 @rtype str 517 @rtype str
517 """ 518 """
518 if Preferences.getPip("PipSearchIndex"): 519 if Preferences.getPip("PipSearchIndex"):
519 indexUrl = Preferences.getPip("PipSearchIndex") + "/pypi" 520 indexUrl = Preferences.getPip("PipSearchIndex") + "/pypi"
520 else: 521 else:
521 indexUrl = Pip.DefaultIndexUrlXml 522 indexUrl = Pip.DefaultIndexUrlPypi
523
524 return indexUrl
525
526 def getIndexUrlSearch(self):
527 """
528 Public method to get the index URL for PyPI API calls.
529
530 @return index URL for XML RPC calls
531 @rtype str
532 """
533 if Preferences.getPip("PipSearchIndex"):
534 indexUrl = Preferences.getPip("PipSearchIndex") + "/search/"
535 else:
536 indexUrl = Pip.DefaultIndexUrlSearch
522 537
523 return indexUrl 538 return indexUrl
524 539
525 def getInstalledPackages(self, envName, localPackages=True, 540 def getInstalledPackages(self, envName, localPackages=True,
526 notRequired=False, usersite=False): 541 notRequired=False, usersite=False):
554 args.append("--local") 569 args.append("--local")
555 if notRequired: 570 if notRequired:
556 args.append("--not-required") 571 args.append("--not-required")
557 if usersite: 572 if usersite:
558 args.append("--user") 573 args.append("--user")
574
575 if Preferences.getPip("PipSearchIndex"):
576 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
577 args += ["--index-url", indexUrl]
559 578
560 proc = QProcess() 579 proc = QProcess()
561 proc.start(interpreter, args) 580 proc.start(interpreter, args)
562 if proc.waitForStarted(15000): 581 if proc.waitForStarted(15000):
563 if proc.waitForFinished(30000): 582 if proc.waitForFinished(30000):
612 args.append("--local") 631 args.append("--local")
613 if notRequired: 632 if notRequired:
614 args.append("--not-required") 633 args.append("--not-required")
615 if usersite: 634 if usersite:
616 args.append("--user") 635 args.append("--user")
636
637 if Preferences.getPip("PipSearchIndex"):
638 indexUrl = Preferences.getPip("PipSearchIndex") + "/simple"
639 args += ["--index-url", indexUrl]
617 640
618 proc = QProcess() 641 proc = QProcess()
619 proc.start(interpreter, args) 642 proc.start(interpreter, args)
620 if proc.waitForStarted(15000): 643 if proc.waitForStarted(15000):
621 if proc.waitForFinished(30000): 644 if proc.waitForFinished(30000):
649 @rtype dict 672 @rtype dict
650 """ 673 """
651 result = {} 674 result = {}
652 675
653 if name and version: 676 if name and version:
654 url = "https://pypi.org/pypi/{0}/{1}/json".format(name, version) 677 url = "{0}/{1}/{2}/json".format(
678 self.getIndexUrlPypi(), name, version)
655 request = QNetworkRequest(QUrl(url)) 679 request = QNetworkRequest(QUrl(url))
656 reply = self.__networkManager.get(request) 680 reply = self.__networkManager.get(request)
657 while not reply.isFinished(): 681 while not reply.isFinished():
658 QCoreApplication.processEvents() 682 QCoreApplication.processEvents()
659 683

eric ide

mercurial