-
-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to generate #2492
Improvements to generate #2492
Changes from 5 commits
862512e
e6deb94
4a72ca7
bb82a33
0bb8e58
770985a
c4dbbad
b4eb430
04be61e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
function generate_deprecated(varargs...; kwargs...) | ||
Base.depwarn("Pkg.generate is deprecated. Please use PkgTemplates.jl instead.", Symbol("Pkg.generate")) | ||
return generate(varargs...; kwargs...) | ||
end | ||
|
||
generate(path::String; kwargs...) = generate(Context(), path; kwargs...) | ||
function generate(ctx::Context, path::String; kwargs...) | ||
Context!(ctx; kwargs...) | ||
dir, pkg = dirname(path), basename(path) | ||
function generate(path::String; io::IO=DEFAULT_IO[]) | ||
base = basename(path) | ||
pkg = endswith(lowercase(base), ".jl") ? chop(base, tail=3) : base | ||
Base.isidentifier(pkg) || pkgerror("$(repr(pkg)) is not a valid package name") | ||
isdir(path) && pkgerror("$(abspath(path)) already exists") | ||
printpkgstyle(ctx.io, :Generating, " project $pkg:") | ||
uuid = project(ctx, pkg, dir) | ||
entrypoint(ctx, pkg, dir) | ||
printpkgstyle(io, :Generating, " project $pkg:") | ||
uuid = project(io, pkg, path) | ||
entrypoint(io, pkg, path) | ||
return Dict(pkg => uuid) | ||
end | ||
|
||
function genfile(f::Function, ctx::Context, pkg::String, dir::String, file::String) | ||
path = joinpath(dir, pkg, file) | ||
println(ctx.io, " $(Base.contractuser(path))") | ||
function genfile(f::Function, io::IO, dir::AbstractString, file::AbstractString) | ||
path = joinpath(dir, file) | ||
println(io, " $(Base.contractuser(path))") | ||
mkpath(dirname(path)) | ||
open(f, path, "w") | ||
return | ||
end | ||
|
||
function project(ctx::Context, pkg::String, dir::String) | ||
function project(io::IO, pkg::AbstractString, dir::AbstractString) | ||
mkpath(dir) | ||
|
||
name = email = nothing | ||
gitname = LibGit2.getconfig("user.name", "") | ||
isempty(gitname) || (name = gitname) | ||
|
@@ -51,26 +47,26 @@ function project(ctx::Context, pkg::String, dir::String) | |
authors = ["$name " * (email === nothing ? "" : "<$email>")] | ||
|
||
uuid = UUIDs.uuid4() | ||
genfile(ctx, pkg, dir, "Project.toml") do io | ||
genfile(io, dir, "Project.toml") do file_io | ||
toml = Dict{String,Any}("authors" => authors, | ||
"name" => pkg, | ||
"uuid" => string(uuid), | ||
"version" => "0.1.0", | ||
) | ||
TOML.print(io, toml, sorted=true, by=key -> (Types.project_key_order(key), key)) | ||
TOML.print(file_io, toml, sorted=true, by=key -> (Types.project_key_order(key), key)) | ||
end | ||
return uuid | ||
end | ||
|
||
function entrypoint(ctx::Context, pkg::String, dir) | ||
genfile(ctx, pkg, dir, "src/$pkg.jl") do io | ||
print(io, | ||
function entrypoint(io::IO, pkg::AbstractString, dir) | ||
genfile(io, dir, "src/$pkg.jl") do file_io | ||
print(file_io, | ||
""" | ||
module $pkg | ||
|
||
greet() = print("Hello World!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change this? I like having some function in here that does something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just because of this comment. Personally, I always found There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function should not remove, there is nothing weird. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I reverted it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. boo 😔😔😔😔😔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't satisfy everyone 😄. We can do an emoji vote here to decide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put it in the main issue this is buried |
||
# module contents | ||
|
||
end # module | ||
end | ||
pazner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to not ship this redirection in the docstring, but instead in the documentation. We have no idea whether it is still
PkgTemplates.jl
five years later. If someone is still using Julia 1.7 five years later for unknown reasons, he doesn't get directed to the wrong place then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but keep in mind that currently,
] generate
is deprecated in favor of PkgTemplates.jl with the deprecation warning:Pkg.generate is deprecated. Please use PkgTemplates.jl instead.
Incidentally, I think that makes a good case for having this "core" functionality built-in to Pkg.jl.