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

Allow packages to easily retrieve their version #1501

Closed
wants to merge 4 commits into from
Closed

Conversation

omus
Copy link
Member

@omus omus commented Nov 13, 2019

Allows for packages to codify their own deprecations for future revisions. I example of deprecating the return type of a function:

if @__VERSION__() < v"1.4"
    """
        f() -> String
    """
    function f(; classic_return::Bool=true)
        if classic_return
            Base.depwarn("`f` will return `nothing` in version 1.4")
            return ""
        else
            return nothing
        end
    end
elseif v"1.4" <= @__VERSION__ < v"1.5"
    """
        f() -> Nothing
    """
    function f(; classic_return=nothing)
        if classic_return !== nothing
            Base.depwarn("`f` will no drop support for the `class_return` keyword in version 1.5")
        end
        return nothing
    end
else
    """
        f() -> Nothing
    """
    f() = nothing
end

@KristofferC
Copy link
Member

KristofferC commented Nov 13, 2019

I think this should just look at the Project file of the package itself, not of the project/manifest of the active environment which seems like a very roundabout way of getting to the place where the version actually was defined.

So something like (using JuliaLang/julia#33128) and with error checking

project_data = Pkg.TOML.parsefile(joinpath(pkgdir(@__MODULE__), "Project.toml"))
return VersionNumber(project_data["version"])

This seems to encourage having a bunch of dead code around though.

@codecov
Copy link

codecov bot commented Nov 13, 2019

Codecov Report

Merging #1501 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1501      +/-   ##
==========================================
+ Coverage   87.27%   87.29%   +0.02%     
==========================================
  Files          25       25              
  Lines        5383     5393      +10     
==========================================
+ Hits         4698     4708      +10     
  Misses        685      685
Impacted Files Coverage Δ
src/Pkg.jl 90.9% <ø> (+0.9%) ⬆️
src/API.jl 94.69% <100%> (+0.05%) ⬆️
src/utils.jl 83.33% <100%> (+4.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 50f9c6c...4ac07f9. Read the comment docs.

@omus
Copy link
Member Author

omus commented Nov 13, 2019

I think this should just look at the Project file of the package itself, not of the project/manifest of the active environment which seems like a very roundabout way of getting to the place where the version actually was defined.

How can we locate the path of the package when in sub-module? I'm under the impression you meant pathof when you said pkgdir?

@omus
Copy link
Member Author

omus commented Nov 13, 2019

This seems to encourage having a bunch of dead code around though.

I agree this will leave dead code around for a while. This however is better then forgetting to remove a deprecation when you do a version bump

@fredrikekre
Copy link
Member

JuliaLang/julia#33128

@KristofferC
Copy link
Member

This should only be used at top level so the result ends up in the precompile file and so that no runtime parsing of the project file is needed.

src/API.jl Outdated Show resolved Hide resolved
@omus omus changed the title WIP: Allow packages to easily retrieve their version Allow packages to easily retrieve their version Nov 18, 2019
@omus
Copy link
Member Author

omus commented Nov 18, 2019

Code should be ready to go

@StefanKarpinski
Copy link
Member

While this is better, it seems like if we're going to officially support this, we should it right and record the tree hash and version number at the time something was loaded, rather than this, which can become out of sync after loading.

pkg_dir = pkgdir(__module__)

if pkg_dir !== nothing
project_data = TOML.parsefile(Types.projectfile_path(pkg_dir))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it makes sense to re-compile when the version in Project.toml is changed?

Suggested change
project_data = TOML.parsefile(Types.projectfile_path(pkg_dir))
toml_path = Types.projectfile_path(pkg_dir)
include_dependency(toml_path)
project_data = TOML.parsefile(toml_path)

mattBrzezinski pushed a commit to JuliaCloud/AWSBatch.jl that referenced this pull request Dec 7, 2020
@IanButterworth
Copy link
Member

I believe Base.pkgversion (new in 1.9) provides the same functionality https://docs.julialang.org/en/v1.9.0-rc3/base/base/#Base.pkgversion-Tuple{Module}

Please feel free to reopen if not, just a tidyup close

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.

7 participants