def get_repository_config(server_name): # we get a pypi repository alias but we need the url+username+password from pypirc # distutils does the translation, but we have to fool it a little from distutils.config import PyPIRCCommand from distutils.dist import Distribution pypirc = PyPIRCCommand(Distribution()) pypirc.repository = server_name return pypirc._read_pypirc()
def get_pypirc_credentials(index_server): """Acquire credentials from the user's pypirc file""" try: from distutils.dist import Distribution from distutils.config import PyPIRCCommand except ImportError: return get_pypirc_py24() p = PyPIRCCommand(Distribution()) p.repository = index_server return p._read_pypirc()
def _get_pypirc_command(self): """ Get the distutils command for interacting with PyPI configurations. :return: the command. """ from distutils.core import Distribution from distutils.config import PyPIRCCommand d = Distribution() return PyPIRCCommand(d)
def test_readpypirc(monkeypatch, tmpdir): from devpi.upload.setuppy import _prepare_distutils from distutils.config import PyPIRCCommand monkeypatch.setattr(sys, "argv", ["xxx", str(tmpdir), "http://something", "user", "password", "register", "1"]) _prepare_distutils() cmd = types.InstanceType(PyPIRCCommand) current = PyPIRCCommand._read_pypirc(cmd) assert current["server"] == "devpi" assert current["repository"] == "http://something" assert current["username"] == "user" assert current["password"] == "password" assert current["realm"] == "devpi" assert sys.argv == ["setup.py", "register", "1"]