Skip to content

Commit

Permalink
releng - fix poetry pkg script, add test (cloud-custodian#7843)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisshi authored Oct 5, 2022
1 parent 49f5a3f commit 5fcdab9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ jobs:
- name: Bootstrap poetry
shell: bash
run: |
curl -sL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py \
| python - -y --version $POETRY_VERSION
curl -sSL https://install.python-poetry.org | python3 - --version $POETRY_VERSION -y
- name: Set up cache
uses: actions/cache@v2
Expand Down Expand Up @@ -148,8 +147,7 @@ jobs:
- name: Bootstrap poetry
shell: bash
run: |
curl -sL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py \
| python - -y --version $POETRY_VERSION
curl -sSL https://install.python-poetry.org | python3 - --version $POETRY_VERSION -y
- name: Set up cache
uses: actions/cache@v2
Expand Down
8 changes: 6 additions & 2 deletions tools/dev/poetrypkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ def resolve_source_deps(poetry, package, reqs, frozen=False):


def locked_deps(package, poetry, exclude=(), remove=()):
from poetry_plugin_export.walker import get_project_dependency_packages

reqs = []
deps = poetry.locker.get_project_dependency_packages(
deps = get_project_dependency_packages(
locker=poetry._locker,
project_requires=package.all_requires,
dev=False, extras=[])
project_python_marker=package.python_marker,
extras=[])

project_deps = {r.name: r for r in poetry.package.requires}
for dep_pkg in deps:
Expand Down
61 changes: 61 additions & 0 deletions tools/dev/tests/test_poetrypkg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import subprocess
import sys

import pytest

from pathlib import Path

from click.testing import CliRunner

cli = Path(__file__).parent.parent / "poetrypkg.py"
with open(cli, encoding='utf-8') as f:
exec(f.read())


@pytest.mark.skipif(sys.version_info <= (3, 8), reason="Developer Python minimum is 3.8")
@pytest.mark.skipif(sys.platform == 'win32', reason="No Windows support")
def test_generate_frozen_deps():
"""
Ensures that the gen-frozendeps command works and creates a git diff
"""

def _assert_pkg_ok(pkg):
base = Path(__file__).parent.parent.parent.parent / pkg

with open(base / "setup.py") as f:
original = f.read()

result = runner.invoke(cli, ['gen-frozensetup', '-p', base])
assert result.exit_code == 0
gitdiff = subprocess.check_output(
f"git diff {base}/setup.py".split(' '),
stderr=subprocess.STDOUT,
)
# not the most exact check, but at the end of generating the frozen
# deps the git diff should have changed
assert gitdiff

# clean up the setup.py file for a clean diff
with open(base / "setup.py", "w") as f:
f.write(original)

PKG_SET = (
'.',
'tools/c7n_gcp',
'tools/c7n_kube',
'tools/c7n_openstack',
'tools/c7n_mailer',
'tools/c7n_logexporter',
'tools/c7n_policystream',
'tools/c7n_trailcreator',
'tools/c7n_org',
'tools/c7n_sphinxext',
'tools/c7n_terraform',
'tools/c7n_awscc',
'tools/c7n_tencentcloud',
'tools/c7n_azure',
)
runner = CliRunner()

for pkg in PKG_SET:
_assert_pkg_ok(pkg)

0 comments on commit 5fcdab9

Please sign in to comment.