Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .ci/container_setup.d/10-install-signing-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pulp --config "${PULP_CLI_CONFIG}" debug has-plugin --name "deb" && HAS_DEB=true
pulp --config "${PULP_CLI_CONFIG}" debug has-plugin --name "ansible" && HAS_ANSIBLE=true || HAS_ANSIBLE=""
if [ "$HAS_DEB" ] || [ "$HAS_ANSIBLE" ]
then
if [ ! -f pytest_pulp_cli/GPG-PRIVATE-KEY-fixture-signing ]
if [ ! -f .ci/GPG-PRIVATE-KEY-fixture-signing ]
then
curl -L https://github.com/pulp/pulp-fixtures/raw/master/common/GPG-PRIVATE-KEY-fixture-signing > pytest_pulp_cli/GPG-PRIVATE-KEY-fixture-signing
curl -L https://github.com/pulp/pulp-fixtures/raw/master/common/GPG-PRIVATE-KEY-fixture-signing > .ci/GPG-PRIVATE-KEY-fixture-signing
fi
echo "Setup the signing services"
if "${CONTAINER_RUNTIME}" exec "pulp-ephemeral" id pulp
Expand All @@ -20,7 +20,7 @@ then
"${CONTAINER_RUNTIME}" exec "pulp-ephemeral" mkdir -p /var/lib/pulp/scripts/
# Setup key on the Pulp container
echo "0C1A894EBB86AFAE218424CADDEF3019C2D4A8CF:6:" | "${CONTAINER_RUNTIME}" exec -i "pulp-ephemeral" su "${PULP_USER}" -c "gpg --import-ownertrust"
"${CONTAINER_RUNTIME}" exec -i "pulp-ephemeral" su "${PULP_USER}" -c "gpg --import" < pytest_pulp_cli/GPG-PRIVATE-KEY-fixture-signing
"${CONTAINER_RUNTIME}" exec -i "pulp-ephemeral" su "${PULP_USER}" -c "gpg --import" < .ci/GPG-PRIVATE-KEY-fixture-signing
if [ "$HAS_DEB" ]
then
echo "Setup deb release signing service"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__pycache__/
build/
tests/cli.toml
pytest_pulp_cli/GPG-PRIVATE-KEY-fixture-signing
GPG-PRIVATE-KEY-fixture-signing
site/
dist/
*.po~
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

LANGUAGES=de
GLUE_PLUGINS=$(notdir $(wildcard pulp-glue/pulp_glue/*))
CLI_PLUGINS=$(notdir $(wildcard pulpcore/cli/*))
GLUE_PLUGINS=$(notdir $(wildcard pulp-glue/src/pulp_glue/*))
CLI_PLUGINS=$(notdir $(wildcard src/pulpcore/cli/*))

.PHONY: info
info:
Expand All @@ -26,7 +26,7 @@ lint:
ruff format --check --diff
ruff check --diff
.ci/scripts/check_click_for_mypy.py
MYPYPATH=pulp-glue mypy
mypy
cd pulp-glue; mypy
@echo "🙊 Code 🙈 LGTM 🙉 !"

Expand Down
5 changes: 2 additions & 3 deletions cookiecutter/apply_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


import os
from pathlib import Path
import tomllib
from pathlib import Path

import click
import yaml
Expand All @@ -38,8 +38,7 @@ def main(bootstrap: bool, force: bool) -> None:
os.chdir(proj_dir)

try:
with open("pyproject.toml", "rb") as fp:
pyproject_toml = tomllib.load(fp)
pyproject_toml = tomllib.loads(Path("pyproject.toml").read_text())
config = pyproject_toml["tool"]["pulp_cli_template"]
except (FileNotFoundError, KeyError):
raise click.ClickException("This does not look like a pulp cli repository.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "{{ cookiecutter.current_version }}"
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pulp_glue.common.i18n import get_translation


translation = get_translation(__package__)
_ = translation.gettext
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import click
from pulp_cli.generic import pulp_group

from pulp_glue.common.i18n import get_translation

# TODO Implement these
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[cli]
base_url = "http://localhost:8080"
username = "admin"
password = "password"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import typing as t
from urllib.parse import urljoin

import pytest

pytest_plugins = "pytest_pulp_cli"


@pytest.fixture
def pulp_cli_vars(pulp_cli_vars: t.MutableMapping[str, str]) -> t.MutableMapping[str, str]:
PULP_FIXTURES_URL = pulp_cli_vars["PULP_FIXTURES_URL"]
result: t.MutableMapping[str, str] = {}
result.update(pulp_cli_vars)
result.update(
{
"{{ cookiecutter.app_label }}_REMOTE_URL": urljoin(PULP_FIXTURES_URL, "/{{ cookiecutter.app_label }}"),
}
)
return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -eu

# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")/config.source"

ENTITIES_NAME="test_{{ cookiecutter.app_label }}_remote"

cleanup() {
pulp {{ cookiecutter.app_label }} remote destroy --name "${ENTITIES_NAME}" || true
}
trap cleanup EXIT

# Fail to create some remotes:
expect_fail pulp {{ cookiecutter.app_label }} remote create --name "foo"

# Create and a remote:
expect_succ pulp {{ cookiecutter.app_label }} remote create --name "foo" --url "foo"
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import typing as t

import click
import pytest
from click.testing import CliRunner
from packaging.version import parse as parse_version
from pulp_cli import __version__ as PULP_CLI_VERSION
from pulp_cli import load_plugins, main

load_plugins()


def traverse_commands(command: click.Command, args: t.List[str]) -> t.Iterator[t.List[str]]:
yield args

if isinstance(command, click.Group):
for name, sub in command.commands.items():
yield from traverse_commands(sub, args + [name])

params = command.params
if params:
if "--type" in params[0].opts:
# iterate over commands with specific context types
assert isinstance(params[0].type, click.Choice)
for context_type in params[0].type.choices:
yield args + ["--type", context_type]

for name, sub in command.commands.items():
yield from traverse_commands(sub, args + ["--type", context_type, name])


@pytest.fixture
def no_api(monkeypatch: pytest.MonkeyPatch) -> None:
@property # type: ignore
def getter(self: t.Any) -> None:
pytest.fail("Invalid access to 'PulpContext.api'.", pytrace=False)

monkeypatch.setattr("pulp_glue.common.context.PulpContext.api", getter)


@pytest.mark.help_page
def test_access_help(no_api: None, subtests: pytest.Subtests) -> None:
"""Test, that all help screens are accessible without touching the api property."""
if parse_version(PULP_CLI_VERSION) < parse_version("0.24"):
pytest.skip("This test is incompatible with older cli versions.")

runner = CliRunner()
for args in traverse_commands(main.commands["{{ cookiecutter.app_label }}"], ["{{ cookiecutter.app_label }}"]):
with subtests.test(msg=" ".join(args)):
result = runner.invoke(main, args + ["--help"], catch_exceptions=False)

if result.exit_code == 2:
assert (
"not available in this context" in result.stdout
or "not available in this context" in result.stderr
)
else:
assert result.exit_code == 0
assert result.stdout.startswith("Usage:") or result.stdout.startswith(
"DeprecationWarning:"
)
1 change: 1 addition & 0 deletions cookiecutter/ci/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"app_label": "noname",
"src_layout": false,
"glue": true,
"docs": false,
"translations": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__pycache__/
build/
tests/cli.toml
pytest_pulp_cli/GPG-PRIVATE-KEY-fixture-signing
GPG-PRIVATE-KEY-fixture-signing
site/
dist/
*.po~
7 changes: 4 additions & 3 deletions cookiecutter/ci/{{ cookiecutter.__project_name }}/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{%- set src_infix = "src/" if cookiecutter.src_layout else "" %}
{%- if cookiecutter.translations %}
LANGUAGES=de
{%- endif %}
{%- if cookiecutter.glue %}
GLUE_PLUGINS=$(notdir $(wildcard pulp-glue{{ cookiecutter.__app_label_suffix }}/pulp_glue/*))
GLUE_PLUGINS=$(notdir $(wildcard pulp-glue{{ cookiecutter.__app_label_suffix }}/{{ src_infix }}pulp_glue/*))
{%- endif %}
CLI_PLUGINS=$(notdir $(wildcard pulpcore/cli/*))
CLI_PLUGINS=$(notdir $(wildcard {{ src_infix }}pulpcore/cli/*))

.PHONY: info
info:
Expand Down Expand Up @@ -37,7 +38,7 @@ lint:
{%- endif %}
.ci/scripts/check_click_for_mypy.py
{%- if cookiecutter.glue %}
MYPYPATH=pulp-glue{{ cookiecutter.__app_label_suffix }} mypy
mypy
cd pulp-glue{{ cookiecutter.__app_label_suffix }}; mypy
{%- else %}
mypy
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[tool.setuptools.packages.find]
# This section is managed by the cookiecutter templates.
where = ["."]
where = ["{% if cookiecutter.src_layout %}src{% else %}.{% endif %}"]
include = ["pulp_glue.*"]
namespaces = true

Expand All @@ -25,7 +25,8 @@ extend-select = ["I"]
strict = true
warn_unused_ignores = false
show_error_codes = true
files = "pulp_glue/**/*.py, tests/**/*.py"
files = "{% if cookiecutter.src_layout %}src{% else %}pulp_glue{% endif %}/**/*.py, tests/**/*.py"
mypy_path = ["{% if cookiecutter.src_layout %}src{% else %}.{% endif %}"]
namespace_packages = true
explicit_package_bases = true

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{#
This file is not templated for itself, but it is used to update sections in pyproject.toml.
#}
{%- set src_infix = "src/" if cookiecutter.src_layout else "" %}

[tool.setuptools.packages.find]
# This section is managed by the cookiecutter templates.
where = ["."]
where = ["{% if cookiecutter.src_layout %}src{% else %}.{% endif %}"]
include = ["pulpcore.cli.*"{% if cookiecutter.app_label == "" %}, "pulp_cli", "pytest_pulp_cli"{% endif %}]
namespaces = true

Expand All @@ -16,6 +17,7 @@ namespaces = true
# This section is co-managed by the cookiecutter templates.
# Changes to existing keys should be preserved.
app_label = {{ cookiecutter.app_label | toml_value }}
src_layout = {{ cookiecutter.src_layout | toml_value }}
repository = {{ cookiecutter.repository | toml_value }}
glue = {{ cookiecutter.glue | toml_value }}
docs = {{ cookiecutter.docs | toml_value }}
Expand Down Expand Up @@ -47,22 +49,22 @@ values = [

[[tool.bumpversion.files]]
# This section is managed by the cookiecutter templates.
filename = "./pulp_cli/__init__.py"
filename = "./{{ src_infix }}pulp_cli/__init__.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""
{%- endif %}
{%- if cookiecutter.glue %}

[[tool.bumpversion.files]]
# This section is managed by the cookiecutter templates.
filename = "./pulp-glue{{ cookiecutter.__app_label_suffix }}/pulp_glue/{{ cookiecutter.main_package }}/__init__.py"
filename = "./pulp-glue{{ cookiecutter.__app_label_suffix }}/{{ src_infix }}pulp_glue/{{ cookiecutter.main_package }}/__init__.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""
{%- endif %}

[[tool.bumpversion.files]]
# This section is managed by the cookiecutter templates.
filename = "./pulpcore/cli/{{ cookiecutter.main_package }}/__init__.py"
filename = "./{{ src_infix }}pulpcore/cli/{{ cookiecutter.main_package }}/__init__.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""
{%- if cookiecutter.glue %}
Expand Down Expand Up @@ -156,19 +158,6 @@ directory = "misc"
name = "Misc"
showcontent = true

[tool.black]
# This section is managed by the cookiecutter templates.
line-length = 100
{%- if cookiecutter.app_label == "" %}
exclude = "cookiecutter"
{%- endif %}

[tool.isort]
# This section is managed by the cookiecutter templates.
profile = "black"
line_length = 100
extend_skip = ["pulp-glue{{ cookiecutter.__app_label_suffix }}"{% if cookiecutter.app_label == "" %}, "cookiecutter"{% endif %}]

[tool.ruff]
# This section is managed by the cookiecutter templates.
line-length = 100
Expand All @@ -188,7 +177,8 @@ section-order = ["future", "standard-library", "third-party", "second-party", "f
strict = true
warn_unused_ignores = false
show_error_codes = true
files = "pulpcore/**/*.py, tests/*.py{% if cookiecutter.app_label == "" %}, pulp_cli/**/*.py, pytest_pulp_cli/**/*.py{% endif %}"
files = "{% if cookiecutter.src_layout %}src{% else %}pulpcore{% endif %}/**/*.py, tests/*.py{% if cookiecutter.app_label == "" and not cookiecutter.src_layout %}, pulp_cli/**/*.py, pytest_pulp_cli/**/*.py{% endif %}"
mypy_path = ["{% if cookiecutter.src_layout %}src{% else %}.{% endif %}"{% if cookiecutter.glue %}, "pulp-glue{{ cookiecutter.__app_label_suffix }}{% if cookiecutter.src_layout %}/src{% endif %}"{% endif %}]
namespace_packages = true
explicit_package_bases = true

Expand Down
Loading
Loading