Skip to content

Commit

Permalink
Merge pull request #288 from jezdez/pypi-twine
Browse files Browse the repository at this point in the history
Use twine for PyPI uploads.
  • Loading branch information
BanzaiMan committed Aug 5, 2015
2 parents 94d2ac1 + 8b091fa commit f094b48
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 6 additions & 3 deletions lib/dpl/provider/pypi.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module DPL
class Provider
class PyPI < Provider
DEFAULT_SERVER = 'http://pypi.python.org/pypi'
DEFAULT_SERVER = 'https://pypi.python.org/pypi'
PYPIRC_FILE = '~/.pypirc'

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

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

Expand Down Expand Up @@ -64,7 +65,9 @@ def needs_key?

def push_app
context.shell "python setup.py register -r #{options[:server] || 'pypi'}"
context.shell "python setup.py #{options[:distributions] || 'sdist'} upload -r #{options[:server] || 'pypi'}"
context.shell "python setup.py #{options[:distributions] || 'sdist'}"
context.shell "twine upload -r #{options[:server] || 'pypi'} dist/*"
context.shell "rm -rf dist/*"
if options[:docs_dir]
docs_dir_option = '--upload-dir ' + options[:docs_dir]
else
Expand Down
19 changes: 14 additions & 5 deletions spec/provider/pypi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

describe "#initialize" do
example "with :distributions option containing 'bdist_wheel'" do
expect(described_class).to receive(:pip).with("twine")
expect(described_class).to receive(:pip).with("wheel")
described_class.new(DummyContext.new, :user => 'foo', :password => 'bar', :distributions => 'bdist_wheel sdist')
end
Expand All @@ -30,31 +31,39 @@
describe "#push_app" do
example do
expect(provider.context).to receive(:shell).with("python setup.py register -r pypi")
expect(provider.context).to receive(:shell).with("python setup.py sdist upload -r pypi")
expect(provider.context).to receive(:shell).with("python setup.py sdist")
expect(provider.context).to receive(:shell).with("twine upload -r pypi dist/*")
expect(provider.context).to receive(:shell).with("rm -rf dist/*")
expect(provider.context).to receive(:shell).with("python setup.py upload_docs -r pypi")
provider.push_app
end

example "with :distributions option" do
provider.options.update(:distributions => 'sdist bdist')
expect(provider.context).to receive(:shell).with("python setup.py register -r pypi")
expect(provider.context).to receive(:shell).with("python setup.py sdist bdist upload -r pypi")
expect(provider.context).to receive(:shell).with("python setup.py sdist bdist")
expect(provider.context).to receive(:shell).with("twine upload -r pypi dist/*")
expect(provider.context).to receive(:shell).with("rm -rf dist/*")
expect(provider.context).to receive(:shell).with("python setup.py upload_docs -r pypi")
provider.push_app
end

example "with :server option" do
provider.options.update(:server => 'http://blah.com')
expect(provider.context).to receive(:shell).with("python setup.py register -r http://blah.com")
expect(provider.context).to receive(:shell).with("python setup.py sdist upload -r http://blah.com")
expect(provider.context).to receive(:shell).with("python setup.py sdist")
expect(provider.context).to receive(:shell).with("twine upload -r http://blah.com dist/*")
expect(provider.context).to receive(:shell).with("rm -rf dist/*")
expect(provider.context).to receive(:shell).with("python setup.py upload_docs -r http://blah.com")
provider.push_app
end

example "with :docs_dir option" do
provider.options.update(:docs_dir => 'some/dir')
expect(provider.context).to receive(:shell).with("python setup.py register -r pypi")
expect(provider.context).to receive(:shell).with("python setup.py sdist upload -r pypi")
expect(provider.context).to receive(:shell).with("python setup.py sdist")
expect(provider.context).to receive(:shell).with("twine upload -r pypi dist/*")
expect(provider.context).to receive(:shell).with("rm -rf dist/*")
expect(provider.context).to receive(:shell).with("python setup.py upload_docs --upload-dir some/dir -r pypi")
provider.push_app
end
Expand All @@ -65,7 +74,7 @@
f = double(:f)
expect(f).to receive(:puts).with(" pypi")
expect(f).to receive(:puts).with("[pypi]")
expect(f).to receive(:puts).with(["repository: http://pypi.python.org/pypi",
expect(f).to receive(:puts).with(["repository: https://pypi.python.org/pypi",
"username: foo",
"password: bar"
])
Expand Down

0 comments on commit f094b48

Please sign in to comment.