Skip to content

Commit

Permalink
Generate bindings from app label
Browse files Browse the repository at this point in the history
Starting with pulpcore 3.43 the package in the status api represents the
proper python package for pulp_file (now being pulpcore). Therefore we
can no longer depend on this to infer the name for the bindings package.

[noissue]
  • Loading branch information
mdellweg committed Jan 15, 2024
1 parent 83f0607 commit e18b1d1
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 34 deletions.
8 changes: 6 additions & 2 deletions templates/docs/docs/Makefile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ DIAGRAM_BUILD_DIR = _diagrams
PULP_URL ?= http://localhost:24817
PULP_API_ROOT ?= /pulp/


# Internal variables.
PULP_V3_API_JSON_URL := ${PULP_URL}${PULP_API_ROOT}api/v3/docs/api.json
PAPEROPT_a4 = -D latex_paper_size=a4
Expand Down Expand Up @@ -69,7 +68,12 @@ endif

$(BUILDDIR)/html/api.json:
mkdir -p $(BUILDDIR)/html
curl --fail -o $(BUILDDIR)/html/api.json "$(PULP_V3_API_JSON_URL)?plugin={{ plugin_name | snake }}&include_html=1"
if pulp debug has-plugin --name core --specifier ">=3.44.0.dev"; \
then \
curl --fail -o $(BUILDDIR)/html/api.json "$(PULP_V3_API_JSON_URL)?component={{ plugins | map(attribute="app_label") | join(",") }}&include_html=1"; \
else \
curl --fail -o $(BUILDDIR)/html/api.json "$(PULP_V3_API_JSON_URL)?plugin={{ plugin_name | snake }}&include_html=1"; \
fi

html: $(BUILDDIR)/html/api.json
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ cd "$(dirname "$(realpath -e "$0")")"/../../..

source .github/workflows/scripts/utils.sh

export PULP_URL="${PULP_URL:-{{ pulp_scheme }}://pulp}"
PULP_URL="${PULP_URL:-{{ pulp_scheme }}://pulp}"
export PULP_URL
PULP_API_ROOT="${PULP_API_ROOT:-/pulp/}"
export PULP_API_ROOT

REPORTED_STATUS="$(pulp status)"
REPORTED_VERSION="$(echo "$REPORTED_STATUS" | jq --arg plugin "{{ plugin_app_label }}" -r '.versions[] | select(.component == $plugin) | .version')"
Expand All @@ -18,7 +21,15 @@ VERSION="$(echo "$REPORTED_VERSION" | python -c 'from packaging.version import V
pushd ../pulp-openapi-generator
{%- for plugin in plugins %}
rm -rf {{ plugin.name | snake }}-client
./generate.sh {{ plugin.name | snake }} python "$VERSION"

if pulp debug has-plugin --name "core" --specifier ">=3.44.0.dev"
then
curl --fail-with-body -k -o api.json "${PULP_URL}${PULP_API_ROOT}api/v3/docs/api.json?bindings&component={{ plugin.app_label }}"
USE_LOCAL_API_JSON=1 ./generate.sh {{ plugin.name | snake }} python "$VERSION"
else
./generate.sh {{ plugin.name | snake }} python "$VERSION"
fi

pushd {{ plugin.name | snake }}-client
python setup.py sdist bdist_wheel --python-tag py3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ cd "$(dirname "$(realpath -e "$0")")"/../../..

source .github/workflows/scripts/utils.sh

export PULP_URL="${PULP_URL:-{{ pulp_scheme }}://pulp}"

PULP_URL="${PULP_URL:-{{ pulp_scheme }}://pulp}"
export PULP_URL
PULP_API_ROOT="${PULP_API_ROOT:-/pulp/}"
export PULP_API_ROOT

REPORTED_STATUS="$(pulp status)"
REPORTED_VERSION="$(echo "$REPORTED_STATUS" | jq --arg plugin "{{ plugin_app_label }}" -r '.versions[] | select(.component == $plugin) | .version')"
Expand All @@ -19,7 +21,15 @@ VERSION="$(echo "$REPORTED_VERSION" | python -c 'from packaging.version import V
pushd ../pulp-openapi-generator
{%- for plugin in plugins %}
rm -rf {{ plugin.name | snake }}-client
./generate.sh {{ plugin.name | snake }} ruby "$VERSION"

if pulp debug has-plugin --name "core" --specifier ">=3.44.0.dev"
then
curl --fail-with-body -k -o api.json "${PULP_URL}${PULP_API_ROOT}api/v3/docs/api.json?bindings&component={{ plugin.app_label }}"
USE_LOCAL_API_JSON=1 ./generate.sh {{ plugin.name | snake }} ruby "$VERSION"
else
./generate.sh {{ plugin.name | snake }} ruby "$VERSION"
fi

pushd {{ plugin.name | snake }}-client
gem build {{ plugin.name | snake }}_client
gem install --both "./{{ plugin.name | snake }}_client-$VERSION.gem"
Expand Down
94 changes: 67 additions & 27 deletions templates/github/.github/workflows/scripts/script.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,76 @@ password password
# Some commands like ansible-galaxy specifically require 600
cmd_prefix bash -c "chmod 600 ~pulp/.netrc"

# Infer the client name from the package name by replacing "-" with "_".
# Use the component to infer the package name on older versions of pulpcore.

if [ "$(echo "$REPORTED_STATUS" | jq -r '.domain_enabled')" = "true" ]
# Generate and install binding
pushd ../pulp-openapi-generator
if pulp debug has-plugin --name "core" --specifier ">=3.44.0.dev"
then
# Workaround: Domains are not supported by the published bindings.
# Generate new bindings for all packages.
pushd ../pulp-openapi-generator
for item in $(echo "$REPORTED_STATUS" | jq -r '.versions[]|(.package // ("pulp_" + .component)|sub("pulp_core"; "pulpcore"))|sub("-"; "_")')
do
./generate.sh "${item}" python
cmd_prefix pip3 install "/root/pulp-openapi-generator/${item}-client"
sudo rm -rf "./${item}-client"
done
popd
# Use app_label to generate api.json and package to produce the proper package name.

if [ "$(jq -r '.domain_enabled' <<<"$REPORTED_STATUS")" = "true" ]
then
# Workaround: Domains are not supported by the published bindings.
# Generate new bindings for all packages.
for item in $(jq -r '.versions[] | tojson' <<<"$REPORTED_STATUS")
do
echo $item
COMPONENT="$(jq -r '.component' <<<"$item")"
VERSION="$(jq -r '.version' <<<"$item")"
MODULE="$(jq -r '.module' <<<"$item")"
PACKAGE="${MODULE%%.*}"
curl --fail-with-body -k -o api.json "${PULP_URL}${PULP_API_ROOT}api/v3/docs/api.json?bindings&component=$COMPONENT"
USE_LOCAL_API_JSON=1 ./generate.sh "${PACKAGE}" python "${VERSION}"
cmd_prefix pip3 install "/root/pulp-openapi-generator/${PACKAGE}-client"
sudo rm -rf "./${PACKAGE}-client"
done
else
# Sadly: Different pulpcore-versions aren't either...
for item in $(jq -r '.versions[]
{%- for plugin in plugins -%}
| select(.component!="{{ plugin.app_label }}")
{%- endfor -%}
| tojson' <<<"$REPORTED_STATUS")
do
echo $item
COMPONENT="$(jq -r '.component' <<<"$item")"
VERSION="$(jq -r '.version' <<<"$item")"
MODULE="$(jq -r '.module' <<<"$item")"
PACKAGE="${MODULE%%.*}"
curl --fail-with-body -k -o api.json "${PULP_URL}${PULP_API_ROOT}api/v3/docs/api.json?bindings&component=$COMPONENT"
USE_LOCAL_API_JSON=1 ./generate.sh "${PACKAGE}" python "${VERSION}"
cmd_prefix pip3 install "/root/pulp-openapi-generator/${PACKAGE}-client"
sudo rm -rf "./${PACKAGE}-client"
done
fi
else
# Sadly: Different pulpcore-versions aren't either...
pushd ../pulp-openapi-generator
for item in $(echo "$REPORTED_STATUS" | jq -r '.versions[]
{%- for plugin in plugins -%}
|select(.component!="{{ plugin.app_label }}")
{%- endfor -%}
|(.package // ("pulp_" + .component)|sub("pulp_core"; "pulpcore"))|sub("-"; "_")')
do
./generate.sh "${item}" python
cmd_prefix pip3 install "/root/pulp-openapi-generator/${item}-client"
sudo rm -rf "./${item}-client"
done
popd
# Infer the client name from the package name by replacing "-" with "_".
# Use the component to infer the package name on older versions of pulpcore.

if [ "$(echo "$REPORTED_STATUS" | jq -r '.domain_enabled')" = "true" ]
then
# Workaround: Domains are not supported by the published bindings.
# Generate new bindings for all packages.
for item in $(echo "$REPORTED_STATUS" | jq -r '.versions[]|(.package // ("pulp_" + .component)|sub("pulp_core"; "pulpcore"))|sub("-"; "_")')
do
./generate.sh "${item}" python
cmd_prefix pip3 install "/root/pulp-openapi-generator/${item}-client"
sudo rm -rf "./${item}-client"
done
else
# Sadly: Different pulpcore-versions aren't either...
for item in $(echo "$REPORTED_STATUS" | jq -r '.versions[]
{%- for plugin in plugins -%}
|select(.component!="{{ plugin.app_label }}")
{%- endfor -%}
|(.package // ("pulp_" + .component)|sub("pulp_core"; "pulpcore"))|sub("-"; "_")')
do
./generate.sh "${item}" python
cmd_prefix pip3 install "/root/pulp-openapi-generator/${item}-client"
sudo rm -rf "./${item}-client"
done
fi
fi
popd

# At this point, this is a safeguard only, so let's not make too much fuzz about the old status format.
echo "$REPORTED_STATUS" | jq -r '.versions[]|select(.package)|(.package|sub("_"; "-")) + "-client==" + .version' > bindings_requirements.txt
Expand Down

0 comments on commit e18b1d1

Please sign in to comment.