Report problematic file before publishing package to the registry

This commit is contained in:
Ivan Kravets
2022-04-12 12:30:49 +03:00
parent f63b2f79e0
commit 81fdd75aac

View File

@ -13,6 +13,7 @@
# limitations under the License.
import os
import tarfile
import tempfile
from datetime import datetime
@ -111,6 +112,9 @@ def package_publish_cmd( # pylint: disable=too-many-arguments, too-many-locals
data.insert(len(data) - 1, ("System:", ", ".join(manifest.get("system"))))
click.echo(tabulate(data, tablefmt="plain"))
# check files containing non-ascii chars
check_archive_file_names(archive_path)
# look for duplicates
check_package_duplicates(owner, type_, name, version, manifest.get("system"))
@ -141,6 +145,17 @@ def package_publish_cmd( # pylint: disable=too-many-arguments, too-many-locals
click.secho(response.get("message"), fg="green")
def check_archive_file_names(archive_path):
with tarfile.open(archive_path, mode="r:gz") as tf:
for name in tf.getnames():
if not name.isascii():
click.secho(
f"Warning! The `{name}` file contains non-ASCII chars and can "
"lead to the unpacking issues on a user machine",
fg="yellow",
)
def check_package_duplicates(
owner, type, name, version, system
): # pylint: disable=redefined-builtin