Class: DPL::Provider::PyPI
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::PyPI
- Defined in:
- lib/dpl/provider/pypi.rb
Constant Summary collapse
- DEFAULT_SERVER =
false
- PYPIRC_FILE =
'~/.pypirc'
Instance Method Summary collapse
- #check_app ⇒ Object
- #check_auth ⇒ Object
- #config ⇒ Object
- #install_deploy_dependencies ⇒ Object
- #needs_key? ⇒ Boolean
- #push_app ⇒ Object
- #pypi_distributions ⇒ Object
- #pypi_docs_dir_option ⇒ Object
- #pypi_password ⇒ Object
- #pypi_server ⇒ Object
- #pypi_setuptools_arg ⇒ Object
- #pypi_skip_existing_option ⇒ Object
- #pypi_twine_arg ⇒ Object
- #pypi_user ⇒ Object
- #pypi_wheel_arg ⇒ Object
- #skip_upload_docs? ⇒ Boolean
- #write_config ⇒ Object
- #write_servers(f) ⇒ Object
Instance Method Details
#check_app ⇒ Object
122 123 |
# File 'lib/dpl/provider/pypi.rb', line 122 def check_app end |
#check_auth ⇒ Object
115 116 117 118 119 120 |
# File 'lib/dpl/provider/pypi.rb', line 115 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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/dpl/provider/pypi.rb', line 78 def config servers = { 'pypi' => [ "username: #{pypi_user}", "password: #{pypi_password}", ] } if pypi_server servers['pypi'].insert(0, "repository: #{pypi_server}") end { :header => '[distutils]', :servers_line => 'index-servers = pypi', :servers => servers } end |
#install_deploy_dependencies ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/dpl/provider/pypi.rb', line 68 def install_deploy_dependencies # --user likely fails inside virtualenvs but is needed outside to avoid needing sudo. # `--upgrade-strategy eager` prevents the old resolver from keeping an outdated dependency if it's preinstalled unless context.shell "if [ -z ${VIRTUAL_ENV+x} ]; then export PIP_USER=yes; fi && " \ "wget -nv -O - https://bootstrap.pypa.io/get-pip.py | python - --no-setuptools --no-wheel && " \ "pip install --upgrade --upgrade-strategy eager #{pypi_setuptools_arg} #{pypi_twine_arg} #{pypi_wheel_arg}" error "Couldn't install pip, setuptools, twine or wheel." end end |
#needs_key? ⇒ Boolean
125 126 127 |
# File 'lib/dpl/provider/pypi.rb', line 125 def needs_key? false end |
#push_app ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/dpl/provider/pypi.rb', line 129 def push_app context.shell "python setup.py #{pypi_distributions}" unless context.shell "twine upload#{pypi_skip_existing_option} -r pypi dist/*" error 'PyPI upload failed.' end 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 [: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 = [: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 [:password] || context.env['PYPI_PASSWORD'] end |
#pypi_server ⇒ Object
15 16 17 |
# File 'lib/dpl/provider/pypi.rb', line 15 def pypi_server [:server] || context.env['PYPI_SERVER'] || DEFAULT_SERVER end |
#pypi_setuptools_arg ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/dpl/provider/pypi.rb', line 41 def pypi_setuptools_arg setuptools_version = [:setuptools_version] || context.env['SETUPTOOLS_VERSION'] || '' if setuptools_version[/\A\d+(?:\.\d+)*\z/] 'setuptools==' + setuptools_version else 'setuptools' end end |
#pypi_skip_existing_option ⇒ Object
35 36 37 38 39 |
# File 'lib/dpl/provider/pypi.rb', line 35 def pypi_skip_existing_option if .fetch(:skip_existing, false) ' --skip-existing' end end |
#pypi_twine_arg ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/dpl/provider/pypi.rb', line 50 def pypi_twine_arg twine_version = [:twine_version] || context.env['TWINE_VERSION'] || '' if twine_version[/\A\d+(?:\.\d+)*\z/] 'twine==' + twine_version else 'twine' end 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 |
#pypi_wheel_arg ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/dpl/provider/pypi.rb', line 59 def pypi_wheel_arg wheel_version = [:wheel_version] || context.env['WHEEL_VERSION'] || '' if wheel_version[/\A\d+(?:\.\d+)*\z/] 'wheel==' + wheel_version else 'wheel' end end |
#skip_upload_docs? ⇒ Boolean
30 31 32 33 |
# File 'lib/dpl/provider/pypi.rb', line 30 def skip_upload_docs? ! .has_key?(:skip_upload_docs) || (.has_key?(:skip_upload_docs) && [:skip_upload_docs]) end |
#write_config ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/dpl/provider/pypi.rb', line 106 def write_config File.open(File.(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
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dpl/provider/pypi.rb', line 95 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 |