Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created December 22, 2017 07:49
Show Gist options
  • Save m-x-k/4a6acaea415e6ff112c5980996147fc4 to your computer and use it in GitHub Desktop.
Save m-x-k/4a6acaea415e6ff112c5980996147fc4 to your computer and use it in GitHub Desktop.
PIP artifactory configuration
import os
import argparse
# Constants
PIP_HOST = "artifactory.my.domain.com"
PIP_URL = "http://%s/artifactory/api/pypi" % PIP_HOST
def setup_pypric(args):
fullpath = "%s/.pypirc" % args.userhome
pypirc = """
[distutils]
index-servers = artifactory
[artifactory]
repository: %s/repo-python
username:%s
password:%s
""" % (PIP_URL, args.pipusername, args.pippassword)
write_file(fullpath, pypirc)
def setup_pydistutils(args):
fullpath = "%s/.pydistutils.cfg" % args.userhome
pydistutils = """
[easy_install]
index_url = %s/repo-pypi-virtual/simple
""" % PIP_URL
write_file(fullpath, pydistutils)
def setup_pip_conf(args):
fullpath = "%s/.pip/pip.conf" % args.userhome
pip = """
[global]
index-url = %s/repo-pypi-virtual/simple
trusted-host = %s
""" % (PIP_URL, PIP_HOST)
write_file(fullpath, pip)
def write_file(filename, text):
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
with open(filename, "w") as f:
f.write(text)
def setup(args):
setup_pypric(args)
setup_pydistutils(args)
setup_pip_conf(args)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Configures pip to use artifactory')
parser.add_argument('--userhome', help='home folder for pip config files')
parser.add_argument('--pipusername', help='pip username for artifactory')
parser.add_argument('--pippassword', help='pip password for artifactory')
setup(parser.parse_args())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment