Commit a43c3baf by Sébastien Eustace

Improve files to publish detection and improve publish command

parent bf061f93
......@@ -19,6 +19,7 @@
- Improved the `show` command to make it easier to check if packages are properly installed.
- The `script` command has been deprecated, use `run` instead.
- The `publish` command no longer build packages by default. Use `--build` to retrieve the previous behavior.
- Improved support for private repositories.
- Expanded version constraints now keep the original version's precision.
- The lock file hash no longer use the project's name and version.
......
......@@ -9,7 +9,7 @@ class PublishCommand(Command):
{ --r|repository= : The repository to publish the package to. }
{ --u|username= : The username to access the repository. }
{ --p|password= : The password to access the repository. }
{ --no-build : Do not build the package before publishing. }
{ --build : Build the package before publishing. }
"""
help = """The publish command builds and uploads the package to a remote repository.
......@@ -24,13 +24,32 @@ the config command.
def handle(self):
from poetry.masonry.publishing.publisher import Publisher
# Building package first, unless told otherwise
if not self.option('no-build'):
publisher = Publisher(self.poetry, self.output)
# Building package first, if told
if self.option('build'):
if publisher.files:
if not self.confirm(
'There are <info>{}</info> files ready for publishing. '
'Build anyway?'.format(len(publisher.files))
):
self.line_error('<error>Aborted!</error>')
return 1
self.call('build')
files = publisher.files
if not files:
self.line_error(
'<error>No files to publish. '
'Run poetry build first or use the --build option.</error>'
)
return 1
self.line('')
publisher = Publisher(self.poetry, self.output)
publisher.publish(
self.option('repository'),
self.option('username'),
......
......@@ -17,6 +17,10 @@ class Publisher:
self._io = io
self._uploader = Uploader(poetry, io)
@property
def files(self):
return self._uploader.files
def publish(self, repository_name, username, password):
if repository_name:
self._io.writeln(
......
......@@ -2,6 +2,8 @@ import hashlib
import io
import re
from typing import List
import requests
from requests import adapters
......@@ -52,6 +54,23 @@ class Uploader:
return adapters.HTTPAdapter(max_retries=retry)
@property
def files(self): # type: () -> List[str]
dist = self._poetry.file.parent / 'dist'
version = normalize_version(self._package.version.text)
wheels = list(dist.glob(
'{}-{}-*.whl'.format(
re.sub("[^\w\d.]+", "_", self._package.pretty_name, flags=re.UNICODE),
re.sub("[^\w\d.]+", "_", version, flags=re.UNICODE),
)
))
tars = list(dist.glob(
'{}-{}.tar.gz'.format(self._package.pretty_name, version)
))
return sorted(wheels + tars)
def auth(self, username, password):
self._username = username
self._password = password
......@@ -178,28 +197,7 @@ class Uploader:
raise
def _do_upload(self, session, url):
dist = self._poetry.file.parent / 'dist'
version = normalize_version(self._package.version.text)
packages = dist.glob(
'{}-{}*'.format(self._package.name, version)
)
files = (
i for i in packages if (
i.match(
'{}-{}-*.whl'.format(
self._package.name, version
)
)
or
i.match(
'{}-{}.tar.gz'.format(
self._package.name, version
)
)
)
)
for file in files:
for file in self.files:
# TODO: Check existence
resp = self._upload_file(session, url, file)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment