Skip to content

Issue #351 tofu-custom#353

Merged
lasofivec merged 16 commits intodevelfrom
Issue351_CustomShortcuts
Feb 21, 2020
Merged

Issue #351 tofu-custom#353
lasofivec merged 16 commits intodevelfrom
Issue351_CustomShortcuts

Conversation

@Didou09
Copy link
Copy Markdown
Member

@Didou09 Didou09 commented Feb 21, 2020

Motivations:

The default shortcuts used by tf.imas2tofu.MultiIDSLoader may vary frequently due to regular updates to the IMAS data dictionnnary.
Users should be able to update the shortcuts themselves without having to wait for an official to tofu.

Currently, the shortcuts are stored in a (large) hard-coded dictionnary in a dedicated module.
An elegant solution would be to mimic ipython's way of customizing preferences:

create a script tofu-custom that can copy a local version of that module in the user's home, in a dedicated hidden directory: ~/.tofu/
copy in this directory the module with an explicit name _imas2tofu_shortcuts.py or something similar.
Make sure that when tofu imports the dict from the module, it looks first into this local version and then into the general install, to make sure the user's version has precedence over the general version

Main changes:

  • A new script tofu/scripts/tofucustom.py has been created, and an associated bash command tofu-custom implemented in the setup.py.
  • When the user runs it, it automatically creates a hidden local directory ~/.tofu/ in the user's home, and copies files containing default tofu parameters in it (at this point there is only one file _imas2tofu_def.py, but more may come in the future). The user is free to edit these files.
  • The corresponding tofu sub-package tofu.imas2tofu first checks whether the user has local default parameters before loading the general tofu parameters.

N.B.: the names of the files is _modulename_def.py

Issues:

Fixes, in devel, Issue #351

@pep8speaks
Copy link
Copy Markdown

pep8speaks commented Feb 21, 2020

Hello @Didou09! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-02-21 09:43:09 UTC

@Didou09 Didou09 changed the title #Issue351 tofu-custom Issue #351 tofu-custom Feb 21, 2020
@codecov-io
Copy link
Copy Markdown

codecov-io commented Feb 21, 2020

Codecov Report

Merging #353 into devel will decrease coverage by 0.32%.
The diff coverage is 5.13%.

Impacted file tree graph

@@            Coverage Diff             @@
##            devel     #353      +/-   ##
==========================================
- Coverage   39.64%   39.32%   -0.33%     
==========================================
  Files          81       84       +3     
  Lines       24363    24584     +221     
==========================================
+ Hits         9659     9667       +8     
- Misses      14704    14917     +213
Impacted Files Coverage Δ
tofu/_physics.py 25% <ø> (ø)
tofu/utils.py 47.15% <0%> (-0.96%) ⬇️
tofu/scripts/tofucustom.py 0% <0%> (ø)
tofu/imas2tofu/_mat2ids2calc.py 0% <0%> (ø)
tofu/imas2tofu/__init__.py 30.5% <0%> (-1.08%) ⬇️
tofu/scripts/tofucalc.py 0% <0%> (ø) ⬆️
tofu/version.py 100% <100%> (ø) ⬆️
tofu/data/_core_new.py 13.62% <100%> (ø) ⬆️
tofu/data/_core.py 38.97% <100%> (ø) ⬆️
tofu/imas2tofu/_def.py 100% <100%> (ø)
... and 4 more

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 dd17eb2...f5b4781. Read the comment docs.

Comment thread setup.py
url="https://github.com/ToFuProject/tofu",
# Author details
author="Didier VEZINET",
author="Didier VEZINET and Laura MENDOZA",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:)

from tofu.imas2tofu._mat2ids2calc import *
except Exception:
from ._core import *
from ._mat2ids2calc import *
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is there a reason why you do an "import *" ? is it just because the file is small?
I'm still approving the PR :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's because the file is small and also because it contains a very specific use-case that may get generalized later, in which case we'll be happy to have it in a separate module that we can import (becasue it would then get bigger)

Thanks !

@lasofivec lasofivec merged commit 8d61f48 into devel Feb 21, 2020
@Didou09 Didou09 deleted the Issue351_CustomShortcuts branch February 21, 2020 11:53
@Didou09 Didou09 mentioned this pull request Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants