Skip to content

Create script run-me to change JSOTemplate to the new name of the package#15

Open
abelsiqueira wants to merge 2 commits intomainfrom
script-to-fix-everything
Open

Create script run-me to change JSOTemplate to the new name of the package#15
abelsiqueira wants to merge 2 commits intomainfrom
script-to-fix-everything

Conversation

@abelsiqueira
Copy link
Member

@dpo, this should work on mac too, but can you test?

@abelsiqueira abelsiqueira requested a review from dpo November 1, 2021 21:24
@dpo
Copy link
Member

dpo commented Nov 2, 2021

Don't Github templates support placeholders?

@abelsiqueira
Copy link
Member Author

I haven't found it on the docs.

@dpo
Copy link
Member

dpo commented Nov 6, 2021

sed on macOS is the same as on FreeBSD, so there are differences with Linux. The script doesn't work as is:

$ julia16 run-me.jl
Thanks for using JSOTemplate. What's your intended package name?:
BizarrelyNamedPackage.jl
This script will help using JSOTemplate by performing the following steps:
- Change JSOTemplate to BizarrelyNamedPackage.jl wherever it is found
- Change the UUID of the package
- Change file src/JSOTemplate.jl to src/BizarrelyNamedPackage.jl.jl
- Remove this script
- Create a commit with the change

sed: 1: ".JuliaFormatter.toml": invalid command code .
ERROR: LoadError: failed process: Process(`sed -i s/JSOTemplate/BizarrelyNamedPackage.jl/g .JuliaFormatter.toml .cirrus.yml .gitignore CITATION.cff LICENSE.md Project.toml README.md run-me.jl docs/Project.toml docs/make.jl src/JSOTemplate.jl test/runtests.jl .github/workflows/CI.yml .github/workflows/CompatHelper.yml .github/workflows/TagBot.yml .github/workflows/format_pr.yml .github/workflows/register.yml docs/src/index.md docs/src/reference.md docs/src/assets/logo.png docs/src/assets/style.css`, ProcessExited(1)) [1]

Stacktrace:
 [1] pipeline_error
   @ ./process.jl:525 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base ./process.jl:440
 [3] run(::Cmd)
   @ Base ./process.jl:438
 [4] top-level scope
   @ ~/dev/JSO/JSOTemplate.jl/run-me.jl:28

For one, we should detect a trailing .jl in the package name.

It seems on macOS giving an extension to sed -i is mandatory even if the extension is empty.

There's also an error when processing binary files, such as logo.png.

This worked for me:

diff --git a/run-me.jl b/run-me.jl
index 3b57c17..ed2e181 100644
--- a/run-me.jl
+++ b/run-me.jl
@@ -16,16 +16,13 @@ This script will help using JSOTemplate by performing the following steps:
 """)
 
 
-files = readdir()
-deleteat!(files, findfirst(files .== ".git"))
-while !all(isfile.(files))
-  idx = findall(.!isfile.(files))
-  for dir in files[idx]
-    append!(files, readdir(dir, join=true))
-  end
-  deleteat!(files, idx)
+files = split(readchomp(`git ls-tree -r main --name-only`), "\n")
+for file ∈ files
+  file_type = readchomp(`file $file`)
+  match(r"text", file_type) == nothing && continue  # skip binary files
+  run(`sed -i "" "s/JSOTemplate/$pkgname/g" "$file"`)
 end
-run(`sed -i "s/JSOTemplate/$pkgname/g" $files`)
 println(green("✓ All occurrences of JSOTemplate should have been changed to $pkgname"))
 
 lines = readlines("Project.toml")
@@ -38,7 +35,7 @@ for line in lines
 end
 new_uuid = string(uuid4())
 files = ["Project.toml", "test/Project.toml", "docs/Project.toml"] |> x -> filter(isfile, x)
-run(`sed -i "s/$uuid/$new_uuid/g" $files`)
+run(`sed -i "" "s/$uuid/$new_uuid/g" $files`)
 println(green("✓ UUID has been updated in $files"))
 
 mv("src/JSOTemplate.jl", "src/$pkgname.jl")
@@ -49,4 +46,4 @@ println(green("✓ run-me.jl was removed"))
 
 run(`git add src/$pkgname.jl`)
 run(`git commit -am ":robot: [run-me.jl] Change JSOTemplate to $pkgname"`)
-println(green("✓ commit was created"))
\ No newline at end of file
+println(green("✓ commit was created"))

BTW, just for fun:

julia>  macro green_str(s)
           "\033[0;32m" * s * "\033[0m"
       end

julia> green"BLA"
"\e[0;32mBLA\e[0m"

julia> println(green"BLA")  # shows in green
BLA
``

Copy link
Member

@dpo dpo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments in the thread.

@abelsiqueira
Copy link
Member Author

Now it fails on Linux :/
Probably changing sed to pure-Julia readlines + replace is better, although slower.
However, I think I can change this to automatically run on a GitHub action that auto-deletes itself, based on this python template: https://github.com/NLeSC/python-template

@dpo
Copy link
Member

dpo commented Feb 16, 2022

Probably changing sed to pure-Julia readlines + replace is better, although slower.

Yes.

@abelsiqueira abelsiqueira mentioned this pull request Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants