Class: DPL::Provider::PyPI

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

Constant Summary collapse

DEFAULT_SERVER =
'https://upload.pypi.org/legacy/'
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, deprecated, #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.



44
45
46
47
# 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

Class Method Details

.install_setuptoolsObject



35
36
37
38
# 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_twineObject



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

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

Instance Method Details

#check_appObject



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

def check_app
end

#check_authObject



86
87
88
89
90
91
# 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

#configObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# 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?Boolean

Returns:

  • (Boolean)


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

def needs_key?
  false
end

#push_appObject



100
101
102
103
104
105
106
107
108
# 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_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

#skip_upload_docs?Boolean

Returns:

  • (Boolean)


30
31
32
33
# 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_configObject



77
78
79
80
81
82
83
84
# 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) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# 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