Skip to content

Commit

Permalink
feat: introduce rhai for preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 6, 2024
1 parent d97fa75 commit 4536870
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
5 changes: 5 additions & 0 deletions template/py/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[template]
cargo_generate_version = ">=0.10.0"

[hooks]
pre = [
"fix-project-name.rhai",
]

[placeholders.gh_uname]
type = "string"
prompt = "GitHub username (or organization)?"
Expand Down
6 changes: 3 additions & 3 deletions template/py/compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: Compose specification

service:
{{project-name}}:
{{project-name | replace: '-', '_'}}:
build: .

networks:
{{project-name}}-net:
name: {{project-name}}-net
{{project-name | replace: '-', '_'}}-net:
name: {{project-name | replace: '-', '_'}}-net
ipam:
config:
- subnet: 172.16.238.0/24
26 changes: 26 additions & 0 deletions template/py/fix-project-name.rhai
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// get the project name
let project_name = variable::get("project-name");

// remove leading and trailing whitespace
project_name = project_name.trim();

// replace spaces with dashes
project_name = project_name.replace(" ", "-");
project_name = project_name.replace("_", "-");

// remove leading and trailing dashes and underscores
while project_name.starts_with("-") || project_name.starts_with("_") {
project_name = project_name.sub(1, project_name.len());
}
while project_name.ends_with("-") || project_name.ends_with("_") {
project_name = project_name.sub(0, project_name.len() - 1);
}

// check if the project name is empty
if project_name.len() == 0 {
print("Error: Project name cannot be empty or consist solely of invalid characters.");
throw "Invalid project name";
}

// set the project name
variable::set("project-name", project_name);
8 changes: 4 additions & 4 deletions template/py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ minversion = "6.0"
addopts = [
"-ra", # show all captured stdout/stderr
"-q", # quiet
"--cov={{project-name}}", # report coverage of {{project-name}}
"--cov={{project-name | replace: '-', '_'}}", # report coverage of {{project-name | replace: '-', '_'}}
"--cov-report=term-missing", # show missing coverage
"--cov-report=html", # generate html coverage report
"--cov-report=lcov", # generate lcov coverage report
Expand All @@ -53,16 +53,16 @@ markers = [
]

[tool.coverage.run]
source_pkgs = ["{{project-name}}", "tests"]
source_pkgs = ["{{project-name | replace: '-', '_'}}", "tests"]
branch = true
parallel = true
omit = [
"*/.venv/*"
]

[tool.coverage.paths]
{{project-name}} = ["src/{{project-name}}"]
tests = ["tests"]
{{project-name | replace: '-', '_'}} = ["src/{{project-name | replace: '-', '_'}}", "*/{{project-name}}/src/{{project-name | replace: '-', '_'}}"]
tests = ["tests", "*/{{project-name}}/tests"]

[tool.coverage.report]
exclude_lines = [
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 4536870

Please sign in to comment.