Class: DPL::Provider::PyPI

Inherits:
DPL::Provider show all
Defined in:
lib/dpl/provider/pypi.rb

Constant Summary collapse

DEFAULT_SERVER =
'https://pypi.python.org/pypi'
PYPIRC_FILE =
'~/.pypirc'

Instance Attribute Summary

Attributes inherited from DPL::Provider

#context, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DPL::Provider

apt_get, #cleanup, #commit_msg, context, #create_key, #default_text_charset, #default_text_charset?, #deploy, #detect_encoding?, #encoding_for, #error, experimental, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup, #user_agent, #warn

Constructor Details

#initialize(*args) ⇒ PyPI

Returns a new instance of PyPI.



39
40
41
42
# File 'lib/dpl/provider/pypi.rb', line 39

def initialize(*args)
  super(*args)
  self.class.pip 'wheel' if pypi_distributions.to_s.include? 'bdist_wheel'
end

Class Method Details

.install_setuptoolsObject



30
31
32
33
# File 'lib/dpl/provider/pypi.rb', line 30

def self.install_setuptools
  shell 'wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python'
  shell 'rm -f setuptools-*.zip'
end

.install_twineObject



35
36
37
# File 'lib/dpl/provider/pypi.rb', line 35

def self.install_twine
  shell("pip install twine", retry: true) if `which twine`.chop.empty?
end

Instance Method Details

#check_appObject



88
89
# File 'lib/dpl/provider/pypi.rb', line 88

def check_app
end

#check_authObject



81
82
83
84
85
86
# File 'lib/dpl/provider/pypi.rb', line 81

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

#configObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dpl/provider/pypi.rb', line 47

def config
  {
    :header => '[distutils]',
    :servers_line => 'index-servers = pypi',
    :servers => {
      'pypi' => [
                   "repository: #{pypi_server}",
                   "username: #{pypi_user}",
                   "password: #{pypi_password}",
                ]
    }
  }
end

#needs_key?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/dpl/provider/pypi.rb', line 91

def needs_key?
  false
end

#push_appObject



95
96
97
98
99
100
# File 'lib/dpl/provider/pypi.rb', line 95

def push_app
  context.shell "python setup.py #{pypi_distributions}"
  context.shell "twine upload -r pypi dist/*"
  context.shell "rm -rf dist/*"
  context.shell "python setup.py upload_docs #{pypi_docs_dir_option} -r #{pypi_server}"
end

#pypi_distributionsObject



19
20
21
# File 'lib/dpl/provider/pypi.rb', line 19

def pypi_distributions
  options[:distributions] || context.env['PYPI_DISTRIBUTIONS'] || 'sdist'
end

#pypi_docs_dir_optionObject



23
24
25
26
27
28
# 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_passwordObject



11
12
13
# File 'lib/dpl/provider/pypi.rb', line 11

def pypi_password
  options[:password] || context.env['PYPI_PASSWORD']
end

#pypi_serverObject



15
16
17
# File 'lib/dpl/provider/pypi.rb', line 15

def pypi_server
  options[:server] || context.env['PYPI_SERVER'] || DEFAULT_SERVER
end

#pypi_userObject



7
8
9
# File 'lib/dpl/provider/pypi.rb', line 7

def pypi_user
  option(:username, :user) || context.env['PYPI_USER'] || context.env['PYPI_USERNAME']
end

#write_configObject



72
73
74
75
76
77
78
79
# File 'lib/dpl/provider/pypi.rb', line 72

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) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/dpl/provider/pypi.rb', line 61

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