From 686541185c98a220c169e58eec942f8c8e7223cf Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Thu, 11 Nov 2021 02:51:04 -0700 Subject: [PATCH] Clean up old scripts/build tools Remove the old sonnet script, as well as the obsolete make-nix-release.sh and Makefile. The last one is maybe more borderline, but it's ill-maintained and has no consumers as best I can tell. --- Makefile | 63 ----------- make-nix-release.sh | 24 ---- poetry/utils/env.py | 4 - sonnet | 270 -------------------------------------------- 4 files changed, 361 deletions(-) delete mode 100644 Makefile delete mode 100755 make-nix-release.sh delete mode 100755 sonnet diff --git a/Makefile b/Makefile deleted file mode 100644 index 4633517e587..00000000000 --- a/Makefile +++ /dev/null @@ -1,63 +0,0 @@ -# This file is part of Poetry -# https://github.com/python-poetry/poetry - -# Licensed under the MIT license: -# http://www.opensource.org/licenses/MIT-license -# Copyright (c) 2018 Sébastien Eustace - -POETRY_RELEASE := $$(sed -n -E "s/__version__ = '(.+)'/\1/p" poetry/__version__.py) - -# lists all available targets -list: - @sh -c "$(MAKE) -p no_targets__ | \ - awk -F':' '/^[a-zA-Z0-9][^\$$#\/\\t=]*:([^=]|$$)/ {\ - split(\$$1,A,/ /);for(i in A)print A[i]\ - }' | grep -v '__\$$' | grep -v 'make\[1\]' | grep -v 'Makefile' | sort" -# required for list -no_targets__: - -clean: - @rm -rf build dist .eggs *.egg-info - @rm -rf .benchmarks .coverage coverage.xml htmlcov report.xml .tox - @find . -type d -name '.mypy_cache' -exec rm -rf {} + - @find . -type d -name '__pycache__' -exec rm -rf {} + - @find . -type d -name '*pytest_cache*' -exec rm -rf {} + - @find . -type f -name "*.py[co]" -exec rm -rf {} + - -format: clean - @poetry run black poetry/ tests/ - -# install all dependencies -setup: setup-python - -# test your application (tests in the tests/ directory) -test: - @poetry run pytest --cov=poetry --cov-config .coveragerc tests/ -sq - -release: build linux_release osx_release - -build: - @poetry build - @python sonnet make release - -publish: - @poetry publish - -wheel: - @poetry build -v - -linux_release: - docker pull quay.io/pypa/manylinux2010_x86_64 - docker run --rm -i -v `pwd`:/io \ - -e PYTHON=/opt/python/cp38-cp38/bin/python \ - -e PYTHON27=/opt/python/cp27-cp27m/bin/python \ - -e PYTHON35=/opt/python/cp35-cp35m/bin/python \ - -e PYTHON36=/opt/python/cp36-cp36m/bin/python \ - -e PYTHON37=/opt/python/cp37-cp37m/bin/python \ - -e PYTHON38=/opt/python/cp38-cp38/bin/python \ - -e PYTHON39=/opt/python/cp39-cp39/bin/python \ - quay.io/pypa/manylinux2010_x86_64 sh -c "cd /io && ./make-nix-release.sh" - -# run tests against all supported python versions -tox: - @tox diff --git a/make-nix-release.sh b/make-nix-release.sh deleted file mode 100755 index b3828db2c38..00000000000 --- a/make-nix-release.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -set -ex - -RUNTIMES[0]="${PYTHON27:+-P "2.7:$PYTHON27"}" -RUNTIMES[1]="${PYTHON35:+-P "3.5:$PYTHON35"}" -RUNTIMES[2]="${PYTHON36:+-P "3.6:$PYTHON36"}" -RUNTIMES[3]="${PYTHON37:+-P "3.7:$PYTHON37"}" -RUNTIMES[4]="${PYTHON38:+-P "3.8:$PYTHON38"}" - -test -n "$PYTHON" || PYTHON="python3" - -if [ "$OSTYPE" == "linux-gnu" ]; then - $PYTHON get-poetry.py -y --preview - POETRY="$PYTHON $HOME/.poetry/bin/poetry" - RUNTIMES[5]="${PYTHON39:+-P "3.9:$PYTHON39"}" -else - $PYTHON -m pip install poetry -U --pre - POETRY="$PYTHON -m poetry" -fi - -$POETRY config virtualenvs.in-project true -$POETRY install --no-dev -$POETRY run python sonnet make release ${RUNTIMES[@]} diff --git a/poetry/utils/env.py b/poetry/utils/env.py index e014c781688..eed00f9e24b 100644 --- a/poetry/utils/env.py +++ b/poetry/utils/env.py @@ -1415,10 +1415,6 @@ def _bin(self, bin: str) -> str: # This is especially true when installing Python with # the official installer, where python.exe will be at # the root of the env path. - # This is an edge case and should not be encountered - # in normal uses but this happens in the sonnet script - # that creates a fake virtual environment pointing to - # a base Python install. if self._is_windows: if not bin.endswith(".exe"): bin_path = self._bin_dir / (bin + ".exe") diff --git a/sonnet b/sonnet deleted file mode 100755 index aa91f132232..00000000000 --- a/sonnet +++ /dev/null @@ -1,270 +0,0 @@ -#!/usr/bin/env python -import hashlib -import os -import shutil -import subprocess -import sys -import tarfile - -from gzip import GzipFile -from pathlib import Path -from typing import Optional - -from cleo.application import Application as BaseApplication -from cleo.commands.command import Command -from cleo.formatters.style import Style -from cleo.helpers import option -from cleo.io.inputs.input import Input -from cleo.io.io import IO -from cleo.io.outputs.output import Output - - -class Application(BaseApplication): - def create_io( - self, - input: Optional[Input] = None, - output: Optional[Output] = None, - error_output: Optional[Output] = None, - ) -> IO: - io = super(Application, self).create_io(input, output, error_output) - - io.output.formatter.set_style("debug", Style("default", options=["dark"])) - io.error_output.formatter.set_style("debug", Style("default", options=["dark"])) - - return io - - -WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt") - - -class MakeReleaseCommand(Command): - """ - Makes a self-contained package of Poetry. - """ - - name = "make release" - - options = [option("--python", "-P", flag=False, multiple=True)] - - PYTHON = { - "3.6": "python3.6", - "3.7": "python3.7", - "3.8": "python3.8", - "3.9": "python3.9", - } - - def handle(self): - pythons = self.PYTHON - if self.option("python"): - pythons = {} - for python in self.option("python"): - parts = python.split(":", 1) - if len(parts) == 1: - python = self.PYTHON[parts[0]] - version = parts[0] - else: - version, python = parts - pythons[version] = python - - self.check_system(pythons) - - from poetry.__version__ import __version__ - from poetry.core.vcs import get_vcs - from poetry.factory import Factory - from poetry.puzzle import Solver - from poetry.repositories.pool import Pool - from poetry.repositories.repository import Repository - from poetry.utils.env import EnvManager - from poetry.utils.env import VirtualEnv - from poetry.utils.helpers import temporary_directory - - project = Factory().create_poetry(Path.cwd()) - package = project.package - del package.dev_requires[:] - - # We only use the lock file to resolve the dependencies - pool = Pool() - pool.add_repository(project.locker.locked_repository(with_dev_reqs=True)) - - vcs = get_vcs(Path(__file__).parent) - if vcs: - vcs_excluded = [str(f) for f in vcs.get_ignored_files()] - else: - vcs_excluded = [] - - created_files = [] - with temporary_directory() as tmp_dir: - # Copy poetry to tmp dir - poetry_dir = os.path.join(tmp_dir, "poetry") - shutil.copytree( - os.path.join(os.path.dirname(__file__), "poetry"), - poetry_dir, - ignore=lambda dir_, names: set(vcs_excluded).intersection( - set([os.path.join(dir_, name) for name in names]) - ), - ) - created_files += [ - p.relative_to(Path(tmp_dir)) - for p in Path(poetry_dir).glob("**/*") - if p.is_file() - and p.suffix != ".pyc" - and str(p.relative_to(Path(tmp_dir))) not in vcs_excluded - ] - for version, python in sorted(pythons.items()): - self.line( - "Preparing files for Python {}".format( - version - ) - ) - - with temporary_directory() as tmp_venv_dir: - venv_dir = Path(tmp_venv_dir) / ".venv" - EnvManager.build_venv(venv_dir.as_posix(), executable=python) - - env = VirtualEnv(venv_dir, venv_dir) - solver = Solver(package, pool, Repository(), Repository(), self.io) - with solver.use_environment(env): - ops = solver.solve() - for op in ops: - if not env.is_valid_for_marker(op.package.marker): - op.skip("Not needed for the current environment") - - vendor_dir = Path( - self.vendorize_for_python( - env, - [op.package for op in ops if not op.skipped], - poetry_dir, - version, - ) - ) - created_files += [ - p.relative_to(Path(tmp_dir)) - for p in vendor_dir.glob("**/*") - if p.is_file() - and p.suffix != ".pyc" - and str(p.relative_to(Path(tmp_dir))) not in vcs_excluded - ] - - self.line("") - - self.line("Packaging files") - with temporary_directory() as tmp_dir2: - base_name = "poetry-{}-{}".format(__version__, sys.platform) - name = "{}.tar.gz".format(base_name) - gz = GzipFile(os.path.join(tmp_dir2, name), mode="wb") - try: - with tarfile.TarFile( - os.path.join(tmp_dir2, name), - mode="w", - fileobj=gz, - format=tarfile.PAX_FORMAT, - ) as tar: - for root, _dirs, files in os.walk(tmp_dir): - for f in files: - if f.endswith(".pyc"): - continue - - path = os.path.join(os.path.realpath(root), f) - - relpath = os.path.relpath( - path, os.path.realpath(tmp_dir) - ) - - if relpath in vcs_excluded: - continue - - tar_info = tar.gettarinfo(str(path), arcname=relpath) - - if tar_info.isreg(): - with open(path, "rb") as f: - tar.addfile(tar_info, f) - else: - tar.addfile(tar_info) # Symlinks & ? - finally: - gz.close() - - self.line("Checking release file") - missing_files = [] - with tarfile.open(os.path.join(tmp_dir2, name), "r") as tar: - names = tar.getnames() - - for created_file in created_files: - if created_file.as_posix() not in names: - missing_files.append(created_file.as_posix()) - - if missing_files: - self.line("Some files are missing:") - for missing_file in missing_files: - self.line(" - {}".format(missing_file)) - - return 1 - - releases_dir = os.path.join(os.path.dirname(__file__), "releases") - if not os.path.exists(releases_dir): - os.mkdir(releases_dir) - - shutil.copyfile( - os.path.join(tmp_dir2, name), os.path.join(releases_dir, name) - ) - - # Compute hash - sha = hashlib.sha256() - with open(os.path.join(releases_dir, name), "rb") as f: - while True: - buffer = f.read(8192) - if not buffer: - break - - sha.update(buffer) - - with open( - os.path.join(releases_dir, "{}.sha256sum".format(base_name)), "w" - ) as f: - f.write(sha.hexdigest()) - - self.line("Built {}".format(name)) - - def check_system(self, pythons): - for version, python in sorted(pythons.items()): - try: - subprocess.check_output( - [python, "-V"], stderr=subprocess.STDOUT, shell=WINDOWS - ) - - subprocess.check_output([python, "-m", "pip", "install", "pip", "-U"]) - except subprocess.CalledProcessError: - raise RuntimeError("Python {} is not available".format(version)) - - def vendorize_for_python(self, env, packages, dest, python_version): - vendor_dir = os.path.join(dest, "_vendor", "py{}".format(python_version)) - - bar = self.progress_bar(max=len(packages)) - bar.set_format("%message% %current%/%max%") - bar.set_message( - "Vendorizing dependencies for Python {}".format( - python_version - ) - ) - bar.start() - for package in packages: - env.run_pip( - "install", - "{}=={}".format(package.name, package.version), - "--no-deps", - "--target", - vendor_dir, - ) - bar.advance() - - bar.finish() - - self.line("") - - return vendor_dir - - -app = Application("sonnet") -app.add(MakeReleaseCommand()) - -if __name__ == "__main__": - app.run()