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

Use ScopedValue to fix async issue #112

Merged
merged 10 commits into from
Jul 13, 2024
Merged

Use ScopedValue to fix async issue #112

merged 10 commits into from
Jul 13, 2024

Conversation

oxinabox
Copy link
Member

In julia 1.11 we get a proper way to do what ContextVariablesX did with an hack.

This is a rebasing of #91 with that switch over
it should not run into the issues that required #93

julia> f() = "original"
f (generic function with 1 method)

julia> p = @patch f() = "mocked"
Patch{typeof(f)}(f, var"##f_patch#233")

julia> apply(p) do
       @show Mocking.PATCH_ENV[]
       end;
Mocking.PATCH_ENV[] = Mocking.PatchEnv(Dict{Any, Vector{Function}}(f => [var"##f_patch#233"]), false)

@oxinabox oxinabox requested a review from omus February 26, 2024 11:38
src/deprecated.jl Outdated Show resolved Hide resolved
src/deprecated.jl Outdated Show resolved Hide resolved
src/patch.jl Outdated Show resolved Hide resolved
Copy link
Member

@omus omus left a comment

Choose a reason for hiding this comment

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

Thanks. Needs a bit of work but I'm glad we're seeing real support for this.

src/patch.jl Outdated Show resolved Hide resolved
src/patch.jl Outdated Show resolved Hide resolved
@@ -12,3 +12,5 @@ function enable(; force=false)
depwarn("`$m.enable(; force=$force)` is deprecated, use `$m.activate()` instead.", :enable)
activate()
end

@deprecate set_active_env(f, pe) with_active_env(f, pe) false
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a proper deprecation as set_active_env would have it's changes persist beyond the scope of f. I think we should probably just make this a breaking change

Copy link
Member Author

Choose a reason for hiding this comment

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

fair, though this is what the previous change did, modulo also renaming set_active_env.
That function isn't actually exported.
Since the normal way to do it is to use apply(pe) do.
More an internal implementation detail of apply ?

Copy link
Member

Choose a reason for hiding this comment

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

I think I'm okay with stating that set_active_env and get_active_env are internal functions and don't require deprecations. Making this a breaking change would be the safest but I could be convinced to have this be non-breaking.

Copy link
Member Author

Choose a reason for hiding this comment

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

If it breaks something can always revert, tag patch, and rerelease as breaking

Copy link
Member Author

Choose a reason for hiding this comment

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

I will just delete them both and not deprecate

test/async.jl Outdated Show resolved Hide resolved
test/concept.jl Outdated Show resolved Hide resolved
src/patch.jl Outdated Show resolved Hide resolved
Copy link
Member

@omus omus left a comment

Choose a reason for hiding this comment

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

Needs a version bump. I'm happy to pick up this PR if you want.

test/async.jl Outdated Show resolved Hide resolved
@@ -12,3 +12,5 @@ function enable(; force=false)
depwarn("`$m.enable(; force=$force)` is deprecated, use `$m.activate()` instead.", :enable)
activate()
end

@deprecate set_active_env(f, pe) with_active_env(f, pe) false
Copy link
Member

Choose a reason for hiding this comment

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

I think I'm okay with stating that set_active_env and get_active_env are internal functions and don't require deprecations. Making this a breaking change would be the safest but I could be convinced to have this be non-breaking.

test/async.jl Outdated Show resolved Hide resolved
src/patch.jl Outdated Show resolved Hide resolved
src/patch.jl Show resolved Hide resolved
test/async.jl Outdated Show resolved Hide resolved
@omus
Copy link
Member

omus commented Mar 12, 2024

Going to kick start the CI workflow

@omus omus closed this Mar 12, 2024
@omus omus reopened this Mar 12, 2024
@omus omus changed the title uses ScopedValues to fix async issue Use ScopedValue to fix async issue Jul 13, 2024
@omus omus merged commit 0a12d05 into master Jul 13, 2024
4 checks passed
@omus omus deleted the ox/scoped_variables branch July 13, 2024 06:33
@omus
Copy link
Member

omus commented Jul 16, 2024

The change here broke the test case on Julia 1.11+ which was testing for issue #108. I'll roll this change back temporarily and include it in a breaking release.

omus added a commit that referenced this pull request Jul 16, 2024
omus added a commit that referenced this pull request Jul 16, 2024
omus added a commit that referenced this pull request Jul 16, 2024
* Use ContextVariablesX to fix async issue

* Use ScopedValues rather than ContextVariables

* Apply suggestions from code review

Co-authored-by: Curtis Vogt <[email protected]>

* Define missing PATCH_ENV

* Refactor tasks testset into async scope

* Import ScopedValue alongside other imports

* Use VERSION check instead

---------

Co-authored-by: Curtis Vogt <[email protected]>
omus added a commit that referenced this pull request Jul 23, 2024
* Use `ScopedValue` to fix async issue (#112)

* Use ContextVariablesX to fix async issue

* Use ScopedValues rather than ContextVariables

* Define missing PATCH_ENV

* Refactor tasks testset into async scope

* Import ScopedValue alongside other imports

* Use VERSION check instead

---------

Co-authored-by: Curtis Vogt <[email protected]>

* Test against Julia 1.11

* Update async-world-ages tests

---------

Co-authored-by: Frames White <[email protected]>
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.

None yet

2 participants