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

To certain functions, add the fancy_exponents kwarg, which allows the user to toggle the "fancy exponents" setting in a thread-safe way #445

Closed
wants to merge 1 commit into from

Conversation

DilumAluthge
Copy link
Contributor

@DilumAluthge DilumAluthge commented May 19, 2021

This pull request adds the fancy_exponents::Bool kwarg to several methods of the following functions:

  • show
  • showval
  • showrep
  • superscript

We use the fancy Unicode exponents if and only if fancy_exponents is true.

The fancy_exponents::Bool kwarg is optional. The default value is determined as follows:

  1. If the user explicitly provides the fancy_exponents kwarg, we use that value.
  2. Otherwise, if the user has set the UNITFUL_FANCY_EXPONENTS environment, and the lowercased value parses to a Bool, we use that value.
  3. Otherwise, if the user has set the UNITFUL_FANCY_EXPONENTS environment variable, but the lowercased value does not parse to a Bool, we default to false.
  4. Otherwise, we default to true on macOS and false otherwise.

Therefore, if the user does not provide the fancy_exponents kwarg, this PR preserves the existing behavior.

Motivation

Currently, the only way to control the behavior of the fancy Unicode exponents is by the UNITFUL_FANCY_EXPONENTS environment variable. Unfortunately, as far as I understand, there is no thread-safe way to modify the environment while calling a Julia function. (The withenv function is not thread-safe. The addenv function is thread-safe, but as far as I can tell, it only lets you run a Cmd.)

The fancy_exponents kwarg allows the user to turn fancy Unicode exponents on/off in a thread-safe way.

…he user to toggle the "fancy exponents" setting in a thread-safe way
@codecov-commenter
Copy link

codecov-commenter commented May 19, 2021

Codecov Report

Merging #445 (94330bd) into master (cc3adef) will decrease coverage by 0.03%.
The diff coverage is 87.50%.

❗ Current head 94330bd differs from pull request most recent head be954f1. Consider uploading reports for the commit be954f1 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #445      +/-   ##
==========================================
- Coverage   83.84%   83.80%   -0.04%     
==========================================
  Files          16       16              
  Lines        1337     1334       -3     
==========================================
- Hits         1121     1118       -3     
  Misses        216      216              
Impacted Files Coverage Δ
src/logarithm.jl 69.42% <0.00%> (-0.13%) ⬇️
src/display.jl 96.34% <95.45%> (+0.13%) ⬆️
src/user.jl 94.07% <0.00%> (-0.19%) ⬇️

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 cc3adef...be954f1. Read the comment docs.

@giordano
Copy link
Collaborator

I can't say I'm a fan of using environment variables for this. Why not using IO context instead?

@DilumAluthge
Copy link
Contributor Author

Sure, that would work. I just didn't want to break the existing behavior of the package.

@DilumAluthge
Copy link
Contributor Author

DilumAluthge commented May 20, 2021

I.e. the package already uses the environment variable, so removing it would be a breaking change.

@giordano
Copy link
Collaborator

giordano commented May 20, 2021

How using IO context would be different from using an environment variable? You don't break anything, you don't even add any extra arguments

@DilumAluthge
Copy link
Contributor Author

Ah I think I see what you mean.

@DilumAluthge
Copy link
Contributor Author

Well just to clarify, we'd use IO contexts instead of the kwarg. The UNITFUL_FANCY_EXPONENTS environment still has to stay as a fallback.

@giordano
Copy link
Collaborator

Yes, the extra argument is redundant since you can pass extra stuff already from the IO. I use IO context in Measurements.jl, see for example https://github.com/JuliaPhysics/Measurements.jl/blob/master/src/show.jl#L42 and the tests

@DilumAluthge
Copy link
Contributor Author

Yes, the extra argument is redundant since you can pass extra stuff already from the IO. I use IO context in Measurements.jl, see for example https://github.com/JuliaPhysics/Measurements.jl/blob/master/src/show.jl#L42 and the tests

It's so much cleaner! I like it.

Closing this PR in favor of #446, which uses the IO context property.

@DilumAluthge DilumAluthge deleted the dpa/disable_fancy_exponents_without_env branch May 20, 2021 03:11
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.

3 participants