Update import statement to be isort compliant#68
Update import statement to be isort compliant#68tennlee wants to merge 4 commits intoACCESS-Community-Hub:developfrom
Conversation
|
not to do with this PR (directly), but what this |
|
Is there anything in particular I should be looking at from a reviewer stand point? There are a lot of things changed so I'm having trouble deciphering which ones are solving circular import issues and which ones are just isort doing its formatting. |
|
Let me reflect a little, and I'll add some specific questions here and you can respond to those. |
|
I might be able to do some fancy footwork to separate out the automated formatting from the fixing... |
c742b1d to
6dae2ff
Compare
|
Okay, this commit isolates the actual fixing --> here . It may still be hard to follow and tackle more than one concern, but it at least separates out the reformatting commit. |
|
@tennlee thanks for that - what you have done looks fine to me and makes sense. |
| import pyearthtools.data.logger # Initialise data logger | ||
|
|
||
| try: | ||
| DEFAULT_EXTENSION = pyearthtools.utils.config.get("data.patterns.default_extension") |
There was a problem hiding this comment.
I know this was the existing code, but this can probably directly be called where its used (or using a helper function so that it is bound to the function during runtime rather than executed on import)
e.g.
# global default
DEFAULT_EXTENSION = ".nc"
def some_fn(..., ext=None):
if ext is None:
# if ext is not explicitly specified, try get from config, otherwise default to global
xxx.config.get("xxx.default_extension", DEFAULT_EXTENSION)
... # usual execution flowThere was a problem hiding this comment.
ditto everywhere else this happens in this PR (ideally the entire codebase eventually - but out of scope for this PR)
There was a problem hiding this comment.
Yes, that's a good idea. I think I will leave it be for this PR, but I'll convert this comment into a new issue. Thanks!
|
I just had a few minor comments. Otherwise I think its fine as long as no functionality is broken. The following are just general observations and follow ups - not necessarily to do with evaluating this PR in particular. As an aside probably from a place of ignorance since I'm not familiar with "exports" (i.e. publicly "visible" imports) on It is quite apparent that the separating factor in terms of what should exist in
As a final thought, circular imports are likely due to a sub-optimal structural design of the codebase - and while the work in this PR does a good step in fixing it, the monolithic nature of the import statements in the various modules isn't necessarily helpful in preventing this scenario from occurring again. If a public API needs to be re-used internally, the first question that comes to my mind is why isn't there an internal representation of this functionality instead? (after all a public API is just a candy wrapper. The goods - actual functional logic - can still be internal to the wrapper.) The answer actually is that there IS internal representation - just that the nesting and repetition in naming the module imports make it less obvious. Trivial as it may seem, a leading underscore actually is a striking visible separation that allows someone looking at an internal module to decipher whether it is using something internal or (incorrectly) using the public representation. As a follow up I think it would be prudent to restrict any internal only functions to recommended naming conventions, mentioned above as well as taking into consideration the following FAQ: https://docs.python.org/3/faq/programming.html#what-are-the-best-practices-for-using-import-in-a-module |
Fix resultant circular import issues
6dae2ff to
149cba9
Compare
|
I'm going to re-do this as some smaller more modular pull requests, but duplicating the approach. |
Fix resultant circular import issues
I ran isort and black
Instead of importing from the API as defined in init.py, I imported things directly out of the fully-qualified namespace for the path they were actually declared in
I'm not sure if this was the best approach but it worked fine