class DPL::Provider::PyPI

Constants

DEFAULT_SERVER
PYPIRC_FILE

Public Class Methods

install_setuptools() click to toggle source
# File lib/dpl/provider/pypi.rb, line 35
def self.install_setuptools
  shell 'wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python'
  shell 'rm -f setuptools-*.zip'
end
install_twine() click to toggle source
# File lib/dpl/provider/pypi.rb, line 40
def self.install_twine
  shell("pip install twine", retry: true) if `which twine`.chop.empty?
end
new(*args) click to toggle source
Calls superclass method DPL::Provider::new
# File lib/dpl/provider/pypi.rb, line 44
def initialize(*args)
  super(*args)
  self.class.pip 'wheel' if pypi_distributions.to_s.include? 'bdist_wheel'
end

Public Instance Methods

check_app() click to toggle source
# File lib/dpl/provider/pypi.rb, line 93
def check_app
end
check_auth() click to toggle source
# File lib/dpl/provider/pypi.rb, line 86
def check_auth
  error "missing PyPI username" unless pypi_user
  error "missing PyPI password" unless pypi_password
  write_config
  log "Authenticated as #{pypi_user}"
end
config() click to toggle source
# File lib/dpl/provider/pypi.rb, line 52
def config
  {
    :header => '[distutils]',
    :servers_line => 'index-servers = pypi',
    :servers => {
      'pypi' => [
                   "repository: #{pypi_server}",
                   "username: #{pypi_user}",
                   "password: #{pypi_password}",
                ]
    }
  }
end
needs_key?() click to toggle source
# File lib/dpl/provider/pypi.rb, line 96
def needs_key?
  false
end
push_app() click to toggle source
# File lib/dpl/provider/pypi.rb, line 100
def push_app
  context.shell "python setup.py #{pypi_distributions}"
  context.shell "twine upload -r pypi dist/*"
  context.shell "rm -rf dist/*"
  unless skip_upload_docs?
    log "Uploading documentation (skip with \"skip_upload_docs: true\")"
    context.shell "python setup.py upload_docs #{pypi_docs_dir_option} -r #{pypi_server}"
  end
end
pypi_distributions() click to toggle source
# File lib/dpl/provider/pypi.rb, line 19
def pypi_distributions
  options[:distributions] || context.env['PYPI_DISTRIBUTIONS'] || 'sdist'
end
pypi_docs_dir_option() click to toggle source
# File lib/dpl/provider/pypi.rb, line 23
def pypi_docs_dir_option
  docs_dir = options[:docs_dir] || context.env['PYPI_DOCS_DIR'] || ''
  if !docs_dir.empty?
    '--upload-dir ' + docs_dir
  end
end
pypi_password() click to toggle source
# File lib/dpl/provider/pypi.rb, line 11
def pypi_password
  options[:password] || context.env['PYPI_PASSWORD']
end
pypi_server() click to toggle source
# File lib/dpl/provider/pypi.rb, line 15
def pypi_server
  options[:server] || context.env['PYPI_SERVER'] || DEFAULT_SERVER
end
pypi_user() click to toggle source
# File lib/dpl/provider/pypi.rb, line 7
def pypi_user
  option(:username, :user) || context.env['PYPI_USER'] || context.env['PYPI_USERNAME']
end
skip_upload_docs?() click to toggle source
# File lib/dpl/provider/pypi.rb, line 30
def skip_upload_docs?
  ! options.has_key?(:skip_upload_docs) ||
    (options.has_key?(:skip_upload_docs) && options[:skip_upload_docs])
end
write_config() click to toggle source
# File lib/dpl/provider/pypi.rb, line 77
def write_config
  File.open(File.expand_path(PYPIRC_FILE), 'w') do |f|
    config.each do |key, val|
      f.puts(val) if val.is_a? String or val.is_a? Array
    end
    write_servers(f)
  end
end
write_servers(f) click to toggle source
# File lib/dpl/provider/pypi.rb, line 66
def write_servers(f)
  config[:servers].each do |key, val|
    f.puts " " * 4 + key
  end

  config[:servers].each do |key, val|
    f.puts "[#{key}]"
    f.puts val
  end
end