diff --git a/.flake8 b/.flake8 index 1ad81e7..6d62fbf 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,19 @@ [flake8] -max-line-length = 88 -ignore = E501, E203, W503 +min_python_version = 3.6.0 +max-line-length = 120 +ban-relative-imports = true +# flake8-use-fstring: https://github.com/MichaelKim0407/flake8-use-fstring#--percent-greedy-and---format-greedy +format-greedy = 0 +inline-quotes = double +enable-extensions = TC, TC1 +type-checking-exempt-modules = typing, typing-extensions +eradicate-whitelist-extend = ^-.*; +extend-ignore = + # E203: Whitespace before ':' (pycqa/pycodestyle#373) + E203, + # SIM106: Handle error-cases first + SIM106, + # ANN101: Missing type annotation for self in method + ANN101, + # ANN102: Missing type annotation for cls in classmethod + ANN102, diff --git a/.github/workflows/installer.yml b/.github/workflows/installer.yml deleted file mode 100644 index e9a6baa..0000000 --- a/.github/workflows/installer.yml +++ /dev/null @@ -1,137 +0,0 @@ -name: Test install-poetry.py - -on: - push: - paths: - - 'install-poetry.py' - - '.github/workflows/installer.yml' - branches: - - main - pull_request: - paths: - - 'install-poetry.py' - - '.github/workflows/installer.yml' - branches: - - '**' - -concurrency: - group: installer-${{ github.head_ref || github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -jobs: - default: - name: ${{ matrix.os }} / ${{ matrix.python-version }} / install-poetry.py ${{ matrix.args }} - runs-on: ${{ matrix.image }} - strategy: - matrix: - os: [Ubuntu, macOS, Windows] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"] - args: - - "" - - "--preview" - - "--git https://github.com/python-poetry/poetry.git" - - "--version 1.1.15" - - "--version 1.2.0" - include: - - os: Ubuntu - image: ubuntu-22.04 - - os: Windows - image: windows-2022 - - os: macOS - image: macos-12 - defaults: - run: - shell: bash - steps: - - uses: actions/checkout@v3 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - - name: Update PATH - if: ${{ matrix.os != 'Windows' }} - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - - - name: Update PATH for Windows - if: ${{ matrix.os == 'Windows' }} - run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH - - - name: Install Poetry - run: python install-poetry.py -y - - - name: Upload Failure Log - uses: actions/upload-artifact@v2 - if: failure() - with: - name: poetry-installer-error.log - path: poetry-installer-error-*.log - - - name: Verify Installation - run: | - set -e - poetry new foobar - cd foobar - poetry config virtualenvs.in-project true - poetry env use python - [ "$(poetry run python --version)" == "$(python --version)" ] \ - || { echo >&2 "ERROR: Virtual environment Python version do not match system version." && exit 1; } - - - name: Uninstall Poetry - run: | - python install-poetry.py -y --uninstall - { type poetry 2>/dev/null >&2 && exit 1; } || exit 0 - - # debian/ubuntu needs special testing due to various issues around python packaging - # and configuration - integration-ubuntu: - name: Integration Test / Ubuntu / ${{ matrix.tag }} - runs-on: ubuntu-latest - container: docker.io/ubuntu:${{ matrix.tag }} - strategy: - matrix: - tag: - - focal - - jammy - defaults: - run: - shell: bash - steps: - - uses: actions/checkout@v3 - - - name: Install Packages - run: | - apt-get -y update - apt-get -y install python3 ca-certificates - apt-get -y install --reinstall python3-distutils - - - name: Update PATH - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - - - name: Install Poetry - env: - DEB_PYTHON_INSTALL_LAYOUT: "deb" - run: python3 install-poetry.py -y - - - name: Upload Failure Log - uses: actions/upload-artifact@v2 - if: failure() - with: - name: poetry-installer-error.log - path: poetry-installer-error-*.log - - - name: Verify Installation - run: | - set -e - poetry new foobar - cd foobar - poetry config virtualenvs.in-project true - poetry env use python3 - [ "$(poetry run python --version)" == "$(python3 --version)" ] \ - || { echo >&2 "ERROR: Virtual environment Python version do not match system version." && exit 1; } - - - name: Uninstall Poetry - run: | - python3 install-poetry.py -y --uninstall - { type poetry 2>/dev/null >&2 && exit 1; } || exit 0 diff --git a/.github/workflows/support-matrix.yml b/.github/workflows/support-matrix.yml new file mode 100644 index 0000000..d3c7659 --- /dev/null +++ b/.github/workflows/support-matrix.yml @@ -0,0 +1,98 @@ +name: Support Matrix + +on: + push: + paths: + - 'install-poetry.py' + - '.github/workflows/support-matrix.yml' + branches: + - main + pull_request: + paths: + - 'install-poetry.py' + - '.github/workflows/support-matrix.yml' + branches: + - '**' + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + feature-matrix: + name: ${{ matrix.python-version }} / install-poetry.py ${{ matrix.args }} + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"] + experimental: [false] + args: + - "" + - "--version 1.1.15" + - "--version 1.2.0" + - "--preview" + - "--git https://github.com/python-poetry/poetry.git" + - "--path ./poetry" + include: + - args: "--version 1.1.15" + python-version: "3.6" + experimental: false + - python-version: "3.11-dev" + experimental: true + steps: + - uses: actions/checkout@v3 + + - uses: actions/checkout@v3 + with: + repository: python-poetry/poetry + path: poetry + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Poetry + run: | + python install-poetry.py -y ${{ matrix.args }} + echo "$HOME/.local/bin" >> $GITHUB_PATH + poetry --version + + - name: Upload Failure Log + uses: actions/upload-artifact@v2 + if: failure() + with: + name: poetry-installer-error.log + path: poetry-installer-error-*.log + + - name: Test new project + run: | + poetry new test_project + cd test_project + + poetry env use python3 + if [ "$(poetry run python --version)" != "$(python3 --version)" ]; then + echo "ERROR: Virtual environment Python version does not match expected system version" >&2 + exit 1 + fi + + poetry debug info + + - name: Test existing project + if: ${{ !contains(matrix.args, '--version 1.1') }} # Poetry makes use of Poetry 1.2+ features + working-directory: poetry + run: | + poetry install + poetry build + poetry run poetry --version + poetry run poetry debug info + + - name: Uninstall Poetry + run: | + python install-poetry.py -y --uninstall + if command -v "poetry" >/dev/null; then + which poetry + echo "ERROR: Failed to uninstall Poetry?" >&2 + exit 1 + fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 296a12c..ddb51b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,34 +1,72 @@ +ci: + autofix_prs: false + repos: - - repo: https://github.com/psf/black - rev: 22.8.0 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 hooks: - - id: black + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-merge-conflict + - id: check-case-conflict + - id: check-json + - id: check-toml + - id: check-yaml + - id: pretty-format-json + args: [--autofix, --no-ensure-ascii, --no-sort-keys] + - id: check-ast + - id: debug-statements + - id: check-docstring-first - - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.9.0 hooks: - - id: flake8 - additional_dependencies: + - id: python-check-mock-methods + - id: python-use-type-annotations + - id: python-check-blanket-noqa + + - repo: https://github.com/asottile/yesqa + rev: v1.4.0 + hooks: + - id: yesqa + additional_dependencies: &flake8_deps + # - flake8-annotations==2.9.0 + - flake8-broken-line==0.5.0 - flake8-bugbear==22.7.1 + - flake8-comprehensions==3.10.0 + - flake8-eradicate==1.3.0 + - flake8-quotes==3.3.1 + - flake8-simplify==0.19.3 + - flake8-tidy-imports==4.8.0 + - flake8-type-checking==2.1.2 + - flake8-typing-imports==1.12.0 + - flake8-use-fstring==1.4 + - pep8-naming==0.13.1 - - repo: https://github.com/PyCQA/isort + - repo: https://github.com/asottile/pyupgrade + rev: v2.37.3 + hooks: + - id: pyupgrade + args: [--py36-plus] + + - repo: https://github.com/hadialqattan/pycln + rev: v2.1.1 + hooks: + - id: pycln + args: [--all] + + - repo: https://github.com/pycqa/isort rev: 5.10.1 hooks: - id: isort - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + - repo: https://github.com/psf/black + rev: 22.6.0 hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: debug-statements - - id: pretty-format-json - args: - - --autofix - - id: check-json + - id: black - - repo: https://github.com/asottile/pyupgrade - rev: v2.34.0 + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 hooks: - - id: pyupgrade - args: [--py36-plus] + - id: flake8 + additional_dependencies: *flake8_deps diff --git a/install-poetry.py b/install-poetry.py index 74dd7d4..36b25c9 100644 --- a/install-poetry.py +++ b/install-poetry.py @@ -4,9 +4,9 @@ It will perform the following steps: * Create a new virtual environment using the built-in venv module, or the virtualenv zipapp if venv is unavailable. - This will be created at a platform-specific path (or `$POETRY_HOME` if `$POETRY_HOME` is set: + This will be created at a platform-specific path (or `$POETRY_HOME` if set): - `~/Library/Application Support/pypoetry` on macOS - - `$XDG_DATA_HOME/pypoetry` on Linux/Unix (`$XDG_DATA_HOME` is `~/.local/share` if unset) + - `$XDG_DATA_HOME/pypoetry` on Linux/Unix (`XDG_DATA_HOME` is `~/.local/share` by default) - `%APPDATA%\pypoetry` on Windows * Update pip inside the virtual environment to avoid bugs in older versions. * Install the latest (or a given) version of Poetry inside this virtual environment using pip. @@ -90,7 +90,7 @@ def style(fg, bg, options): for option in options: codes.append(OPTIONS[option]) - return "\033[{}m".format(";".join(map(str, codes))) + return f"\033[{';'.join(map(str, codes))}m" STYLES = { @@ -107,8 +107,8 @@ def is_decorated(): if WINDOWS: return ( os.getenv("ANSICON") is not None - or "ON" == os.getenv("ConEmuANSI") - or "xterm" == os.getenv("Term") + or os.getenv("ConEmuANSI") == "ON" + or os.getenv("Term") == "xterm" ) if not hasattr(sys.stdout, "fileno"): @@ -532,8 +532,9 @@ def _is_self_upgrade_supported(x): self._write( colorize( "warning", - f"You are installing {version}. When using the current installer, this version does not support " - f"updating using the 'self update' command. Please use 1.1.7 or later.", + f"You are installing {version}. When using the current installer," + " this version does not support updating using the 'self update'" + " command. Please use 1.1.7 or later.", ) ) if not self._accept_all: @@ -558,9 +559,7 @@ def install(self, version): Installs Poetry in $POETRY_HOME. """ self._write( - "Installing {} ({})".format( - colorize("info", "Poetry"), colorize("info", version) - ) + f"Installing {colorize('info', 'Poetry')} ({colorize('info', version)})" ) with self.make_env(version) as env: @@ -573,9 +572,7 @@ def install(self, version): def uninstall(self) -> int: if not self.data_dir.exists(): - self._write( - "{} is not currently installed.".format(colorize("info", "Poetry")) - ) + self._write(f"{colorize('info', 'Poetry')} is not currently installed.") return 1 @@ -585,12 +582,10 @@ def uninstall(self) -> int: if version: self._write( - "Removing {} ({})".format( - colorize("info", "Poetry"), colorize("b", version) - ) + f"Removing {colorize('info', 'Poetry')} ({colorize('b', version)})" ) else: - self._write("Removing {}".format(colorize("info", "Poetry"))) + self._write(f"Removing {colorize('info', 'Poetry')}") shutil.rmtree(str(self.data_dir)) for script in ["poetry", "poetry.bat", "poetry.exe"]: @@ -601,11 +596,8 @@ def uninstall(self) -> int: def _install_comment(self, version: str, message: str): self._overwrite( - "Installing {} ({}): {}".format( - colorize("info", "Poetry"), - colorize("b", version), - colorize("comment", message), - ) + f"Installing {colorize('info', 'Poetry')} ({colorize('b', version)}):" + f" {colorize('comment', message)}" ) @contextmanager @@ -708,11 +700,12 @@ def display_post_message_windows(self, version: str) -> None: def get_windows_path_var(self) -> Optional[str]: import winreg - with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root: - with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key: - path, _ = winreg.QueryValueEx(key, "PATH") + with winreg.ConnectRegistry( + None, winreg.HKEY_CURRENT_USER + ) as root, winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key: + path, _ = winreg.QueryValueEx(key, "PATH") - return path + return path def display_post_message_fish(self, version: str) -> None: fish_user_paths = subprocess.check_output( diff --git a/pyproject.toml b/pyproject.toml index 35ef6c3..15e8dcf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,12 @@ [tool.isort] +py_version = 36 profile = "black" force_single_line = true -atomic = true -lines_after_imports = 2 +combine_as_imports = true lines_between_types = 1 -filter_files = true +lines_after_imports = 2 [tool.black] -line-length = 88 -include = '\.pyi?$' +target-version = ['py36'] +preview = true