Skip to content
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

Creating a custom SciML template in PkgTemplates #363

Closed
00krishna opened this issue Aug 31, 2022 · 2 comments
Closed

Creating a custom SciML template in PkgTemplates #363

00krishna opened this issue Aug 31, 2022 · 2 comments

Comments

@00krishna
Copy link

Hello. I was just wondering if users can define new PkgTemplates? I create a lot of SciML packages, and there are a few customizations in most SciML templates. Most notably, there is a specific structure for defining the types, and documentation, etc.

So I thought it might be nice to simply package all of this in PkgTemplates. Hence I was wondering if it is okay to define a custom template in the package, like even creating a PR, etc.

@iamed2
Copy link
Member

iamed2 commented Aug 31, 2022

@00krishna What Invenia does, and what I think is the right thing to do, is we have an internal package called InveniaTemplates.jl which depends on PkgTemplates.jl and contains all our org-specific customization.

Our public template code looks like this (the rest is private as it integrates with our private services):

# Single-call interface
for func in (:invenia_public_template, :research_public_template)
    @eval function $func(pkgname; kwargs...)
        $func(; kwargs...)(pkgname)
        @info("""
            Created $pkgname 🚀

            You can complete the setup of Documentation by adding a Documenter Key. See:
            https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#Authentication:-SSH-Deploy-Keys
            """)
    end
end

function invenia_public_template(; dir=nothing, julia=v"1")
    gha = GitHubActionsWithNotifications(;
        channel="nightly-dev",
        token="DEV_SLACK_BOT_TOKEN",
        linux=true,
        osx=true,
        windows=true,
        x64=true,
        x86=true,
        extra_versions=["1.0", "1"],
    )
    return _public_template(; dir=dir, julia=julia, gha=gha)
end

function research_public_template(; dir=nothing, julia=v"1")
    gha = GitHubActionsWithNotifications(;
        channel="nightly-rse",
        token="RSE_SLACK_BOT_TOKEN",
        x64=true,
        x86=false,
        extra_versions=["1"],
    )
    return _public_template(; dir=dir, julia=julia, gha=gha)
end

function _public_template(; dir=nothing, julia=v"1", gha::GitHubActionsWithNotifications)
    # Avoid duplicating the logic from PkgTemplates; only customise `dir` if set.
    dir_arg = dir === nothing ? () : (dir=dir,)
    return Template(;
        user="invenia",
        dir_arg...,
        julia=julia,
        authors="Invenia Technical Computing Corporation",
        plugins=[
            ProjectFile(v"1.0.0-DEV"),
            License(; name="MIT"),
            Git(; ignore=[".DS_Store"]),
            Codecov(),
            TagBot(),
            CompatHelper(),
            Documenter{GitHubActions}(;
                logo=invenia_logo(), makedocs_kwargs=MAKEDOCS_KWARGS
            ),
            BlueStyleBadge(),
            ColPracBadge(),
            GitHubActions(;
                file=default("github/workflows/JuliaNightly.yml"),
                destination="JuliaNightly.yml",
            ),
            gha,
        ],
    )
end

To create a new public package, Invenia folks just run:

using InveniaTemplates
invenia_public_template("NewPkg.jl")  # github.com/invenia/NewPkg.jl

@00krishna
Copy link
Author

@iamed2 Ahh okay. Thanks so much. Yeah, this makes sense. So I would just develop a new package and then add PkgTemplates.jl as a dependency. And then I could create my own custom templates. That makes sense. Yeah, I can take a look at doing something similar. Thanks so much for answering my question.

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

No branches or pull requests

2 participants