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, #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.



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

def initialize(*args)
  super(*args)
  self.class.pip 'wheel' if options[:distributions].to_s.include? 'bdist_wheel'
end

Class Method Details

.install_setuptoolsObject



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

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

.install_twineObject



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

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

Instance Method Details

#check_appObject



63
64
# File 'lib/dpl/provider/pypi.rb', line 63

def check_app
end

#check_authObject



58
59
60
61
# File 'lib/dpl/provider/pypi.rb', line 58

def check_auth
  write_config
  log "Authenticated as #{option(:user)}"
end

#configObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dpl/provider/pypi.rb', line 24

def config
  {
    :header => '[distutils]',
    :servers_line => 'index-servers = pypi',
    :servers => {
      'pypi' => [
                   "repository: #{options[:server] || DEFAULT_SERVER}",
                   "username: #{option(:user)}",
                   "password: #{option(:password)}",
                ]
    }
  }
end

#needs_key?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/dpl/provider/pypi.rb', line 66

def needs_key?
  false
end

#push_appObject



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

def push_app
  context.shell "python setup.py #{options[:distributions] || 'sdist'}"
  context.shell "twine upload -r pypi dist/*"
  context.shell "rm -rf dist/*"
  if options[:docs_dir]
    docs_dir_option = '--upload-dir ' + options[:docs_dir]
  else
    docs_dir_option = ''
  end
  context.shell "python setup.py upload_docs #{docs_dir_option} -r #{options[:server] || 'pypi'}"
end

#write_configObject



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

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



38
39
40
41
42
43
44
45
46
47
# File 'lib/dpl/provider/pypi.rb', line 38

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