Skip to content

Commit

Permalink
WIP Allow to use pyproject.toml instead of setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellweg committed Nov 13, 2024
1 parent 444ab6c commit 898080e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- name: "Install python dependencies"
run: |
echo ::group::PYDEPS
pip install towncrier twine wheel httpie docker netaddr boto3 ansible~=10.3.0 mkdocs jq jsonpatch
pip install towncrier twine wheel httpie docker netaddr boto3 'ansible~=10.3.0' mkdocs jq jsonpatch
echo "HTTPIE_CONFIG_DIR=$GITHUB_WORKSPACE/pulp_catdog/.ci/assets/httpie/" >> $GITHUB_ENV
echo ::endgroup::
Expand Down
4 changes: 3 additions & 1 deletion plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -424,17 +424,19 @@ def write_template_section(config, name, plugin_root_dir, verbose=False):
except Exception:
gitref = "unknown"

setup_py = os.path.exists(os.path.join(plugin_root_dir, "setup.py"))
ci_update_branches = [config["plugin_default_branch"]]
latest_release_branch = config["latest_release_branch"]
if latest_release_branch is not None:
if latest_release_branch not in config["supported_release_branches"]:
ci_update_branches.append(latest_release_branch)
ci_update_branches.extend(config["supported_release_branches"])

ci_update_hour = sum((ord(c) for c in config["plugin_app_label"])) % 24

template_vars = {
"section": name,
"gitref": gitref,
"setup_py": setup_py,
"ci_update_branches": ci_update_branches,
"python_version": "3.11",
"ci_update_hour": ci_update_hour,
Expand Down
47 changes: 33 additions & 14 deletions templates/github/.ci/scripts/calc_constraints.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ from packaging.requirements import Requirement
from packaging.version import Version
import yaml

try:
import tomllib
except ImportError:
import tomli as tomllib


CORE_TEMPLATE_URL = "https://raw.githubusercontent.com/pulp/pulpcore/main/template_config.yml"

Expand Down Expand Up @@ -54,11 +59,11 @@ def to_upper_bound(req):
operator = "~="
version = Version(spec.version)
if version.micro != 0:
max_version = f"{version.major}.{version.minor}.{version.micro-1}"
max_version = f"{version.major}.{version.minor}.{version.micro - 1}"
elif version.minor != 0:
max_version = f"{version.major}.{version.minor-1}"
max_version = f"{version.major}.{version.minor - 1}"
elif version.major != 0:
max_version = f"{version.major-1}.0"
max_version = f"{version.major - 1}.0"
else:
return f"# NO BETTER CONSTRAINT: {req}"
return f"{requirement.name}{operator}{max_version}"
Expand Down Expand Up @@ -95,18 +100,32 @@ def main():
parser.add_argument("filename", nargs="*")
args = parser.parse_args()

with fileinput.input(files=args.filename) as req_file:
for line in req_file:
if line.strip().startswith("#"):
# Shortcut comment only lines
print(line.strip())
else:
req, comment = split_comment(line)
if args.upper:
new_req = to_upper_bound(req)
modifier = to_upper_bound if args.upper else to_lower_bound

req_files = [filename for filename in args.filename if not filename.endswith("pyproject.toml")]
pyp_files = [filename for filename in args.filename if filename.endswith("pyproject.toml")]
if req_files:
with fileinput.input(files=req_files) as req_file:
for line in req_file:
if line.strip().startswith("#"):
# Shortcut comment only lines
print(line.strip())
else:
new_req = to_lower_bound(req)
print(new_req + comment)
req, comment = split_comment(line)
new_req = modifier(req)
print(new_req + comment)
for filename in pyp_files:
with open(filename, "rb") as fp:
pyproject = tomllib.load(fp)
for req in pyproject["project"]["dependencies"]:
new_req = modifier(req)
print(new_req)
optional_dependencies = pyproject["project"].get("optional-dependencies")
if optional_dependencies:
for opt in optional_dependencies.values():
for req in opt:
new_req = modifier(req)
print(new_req)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions templates/github/.github/workflows/build.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ jobs:
{{ checkout(path=plugin_name) | indent(6) }}
{{ checkout(repository="pulp/pulp-openapi-generator", path="pulp-openapi-generator") | indent(6) }}
{{ setup_python() | indent(6) }}
{{ install_python_deps(["packaging", "twine", "wheel", "mkdocs", "jq"]) | indent(6) }}
{{ install_python_deps(["build", "packaging", "twine", "wheel", "mkdocs", "jq"]) | indent(6) }}
{%- if os_required_packages %}
- name: "Install OS packages"
run: |
sudo apt-get install -y {{ os_required_packages|join(' ') }}
{%- endif %}
- name: "Build package"
run: |
python3 setup.py sdist bdist_wheel --python-tag py3
python3 -m build
twine check dist/*
- name: "Install built packages"
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ fi
COMMIT_MSG=$(git log --format=%B --no-merges -1)
export COMMIT_MSG

{% if setup_py -%}
COMPONENT_VERSION=$(sed -ne "s/\s*version.*=.*['\"]\(.*\)['\"][\s,]*/\1/p" setup.py)
{%- else -%}
COMPONENT_VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
{%- endif %}

mkdir .ci/ansible/vars || true
echo "---" > .ci/ansible/vars/main.yaml
Expand Down Expand Up @@ -61,10 +65,10 @@ then
fi

if [[ "$TEST" = "pulp" ]]; then
python3 .ci/scripts/calc_constraints.py -u requirements.txt > upperbounds_constraints.txt
python3 .ci/scripts/calc_constraints.py -u {% if setup_py -%} requirements.txt {% else -%} pyproject.toml {% endif -%} > upperbounds_constraints.txt
fi
if [[ "$TEST" = "lowerbounds" ]]; then
python3 .ci/scripts/calc_constraints.py requirements.txt > lowerbounds_constraints.txt
python3 .ci/scripts/calc_constraints.py {% if setup_py -%} requirements.txt {% else -%} pyproject.toml {% endif -%} > lowerbounds_constraints.txt
fi

if [ -f $POST_BEFORE_INSTALL ]; then
Expand Down

0 comments on commit 898080e

Please sign in to comment.