Class: DPL::Provider::PyPI
Constant Summary
collapse
- DEFAULT_SERVER =
'https://upload.pypi.org/legacy/'
- PYPIRC_FILE =
'~/.pypirc'
Instance Attribute Summary
#context, #options
Class Method Summary
collapse
Instance Method Summary
collapse
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
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_twine ⇒ Object
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_app ⇒ Object
93
94
|
# File 'lib/dpl/provider/pypi.rb', line 93
def check_app
end
|
#check_auth ⇒ Object
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
|
#config ⇒ Object
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
96
97
98
|
# File 'lib/dpl/provider/pypi.rb', line 96
def needs_key?
false
end
|
#push_app ⇒ Object
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_distributions ⇒ Object
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_option ⇒ Object
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_password ⇒ Object
11
12
13
|
# File 'lib/dpl/provider/pypi.rb', line 11
def pypi_password
options[:password] || context.env['PYPI_PASSWORD']
end
|
#pypi_server ⇒ Object
15
16
17
|
# File 'lib/dpl/provider/pypi.rb', line 15
def pypi_server
options[:server] || context.env['PYPI_SERVER'] || DEFAULT_SERVER
end
|
#pypi_user ⇒ Object
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
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_config ⇒ Object
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
|