Bump to latest packse version with "extras" scenarios (#935)

Includes:

- https://github.com/zanieb/packse/pull/83 (replaces some of the
post-processing here)
- https://github.com/zanieb/packse/pull/82
- https://github.com/zanieb/packse/pull/81
This commit is contained in:
Zanie Blue 2024-01-17 13:25:48 -06:00 committed by GitHub
parent 4feef006e9
commit a4204d00c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 807 additions and 298 deletions

File diff suppressed because it is too large Load Diff

View File

@ -55,19 +55,21 @@ fn assert_not_installed(venv: &Path, package: &'static str, temp_dir: &Path) {
/// {{.}} /// {{.}}
{{/description_lines}} {{/description_lines}}
/// ///
/// {{prefix}} /// ```text
/// {{version}}
{{#tree}} {{#tree}}
/// {{.}} /// {{.}}
{{/tree}} {{/tree}}
/// ```
#[test] #[test]
fn {{normalized_name}}() -> Result<()> { fn {{module_name}}() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?; let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?;
let venv = create_venv(&temp_dir, &cache_dir, "python{{environment.python}}"); let venv = create_venv(&temp_dir, &cache_dir, "python{{environment.python}}");
// In addition to the standard filters, remove the scenario prefix // In addition to the standard filters, remove the scenario version
let mut filters = INSTA_FILTERS.to_vec(); let mut filters = INSTA_FILTERS.to_vec();
filters.push((r"{{prefix}}-", "")); filters.push((r"-{{version}}", ""));
insta::with_settings!({ insta::with_settings!({
filters => filters filters => filters
@ -76,7 +78,7 @@ fn {{normalized_name}}() -> Result<()> {
.arg("pip") .arg("pip")
.arg("install") .arg("install")
{{#root.requires}} {{#root.requires}}
.arg("{{prefix}}-{{.}}") .arg("{{requirement}}")
{{/root.requires}} {{/root.requires}}
{{#environment.prereleases}} {{#environment.prereleases}}
.arg("--prerelease=allow") .arg("--prerelease=allow")
@ -95,19 +97,19 @@ fn {{normalized_name}}() -> Result<()> {
// {{.}} // {{.}}
{{/expected.explanation_lines}} {{/expected.explanation_lines}}
{{#expected.satisfiable}} {{#expected.satisfiable}}
{{#expected.packages_list}} {{#expected.packages}}
assert_installed( assert_installed(
&venv, &venv,
"{{prefix_module}}_{{package_module}}", "{{module_name}}",
"{{version}}", "{{version}}",
&temp_dir &temp_dir
); );
{{/expected.packages_list}} {{/expected.packages}}
{{/expected.satisfiable}} {{/expected.satisfiable}}
{{^expected.satisfiable}} {{^expected.satisfiable}}
{{#root.requires_packages}} {{#root.requires}}
assert_not_installed(&venv, "{{prefix_module}}_{{package_module}}", &temp_dir); assert_not_installed(&venv, "{{module_name}}", &temp_dir);
{{/root.requires_packages}} {{/root.requires}}
{{/expected.satisfiable}} {{/expected.satisfiable}}
Ok(()) Ok(())

View File

@ -42,11 +42,10 @@ import shutil
import subprocess import subprocess
import sys import sys
import textwrap import textwrap
import packaging.requirements
from pathlib import Path from pathlib import Path
PACKSE_COMMIT = "a9d2f659117693b89cba8a487200fd01444468af" PACKSE_COMMIT = "b6cb1f6310a40937dc68a59c82460fea58957b70"
TOOL_ROOT = Path(__file__).parent TOOL_ROOT = Path(__file__).parent
TEMPLATE = TOOL_ROOT / "template.mustache" TEMPLATE = TOOL_ROOT / "template.mustache"
PACKSE = TOOL_ROOT / "packse-scenarios" PACKSE = TOOL_ROOT / "packse-scenarios"
@ -147,10 +146,6 @@ data["generated_from"] = f"https://github.com/zanieb/packse/tree/{commit}/scenar
data["generated_with"] = " ".join(sys.argv) data["generated_with"] = " ".join(sys.argv)
# Add normalized names for tests
for scenario in data["scenarios"]:
scenario["normalized_name"] = scenario["name"].replace("-", "_")
# Drop the example scenario # Drop the example scenario
for index, scenario in enumerate(data["scenarios"]): for index, scenario in enumerate(data["scenarios"]):
if scenario["name"] == "example": if scenario["name"] == "example":
@ -170,39 +165,12 @@ for scenario in data["scenarios"]:
else [] else []
) )
# Convert the expected packages into a list for rendering
for scenario in data["scenarios"]:
expected = scenario["expected"]
expected["packages_list"] = []
for key, value in expected["packages"].items():
expected["packages_list"].append(
{
"package": key,
"version": value,
# Include a converted version of the package name to its Python module
"package_module": key.replace("-", "_"),
}
)
# Convert the required packages into a list without versions
for scenario in data["scenarios"]:
requires_packages = scenario["root"]["requires_packages"] = []
for requirement in scenario["root"]["requires"]:
package = packaging.requirements.Requirement(requirement).name
requires_packages.append(
{"package": package, "package_module": package.replace("-", "_")}
)
# Include the Python module name of the prefix
for scenario in data["scenarios"]:
scenario["prefix_module"] = scenario["prefix"].replace("-", "_")
# Render the template # Render the template
print("Rendering template...", file=sys.stderr) print("Rendering template...", file=sys.stderr)
output = chevron_blue.render(template=TEMPLATE.read_text(), data=data, no_escape=True) output = chevron_blue.render(
template=TEMPLATE.read_text(), data=data, no_escape=True, warn=True
)
# Update the test file # Update the test file
print(f"Updating test file at `{TARGET.relative_to(PROJECT_ROOT)}`...", file=sys.stderr) print(f"Updating test file at `{TARGET.relative_to(PROJECT_ROOT)}`...", file=sys.stderr)