-
Notifications
You must be signed in to change notification settings - Fork 4
First pass at teasing apart generateconfs into separate functions. #82
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
Conversation
ab98e34
to
6680e39
Compare
Previous work lead to the observation that in the many LoC that make up generateconfs there are in fact distinct phases: the creation of a finalised values that are to be written and the injection of those values into various templates (and the output of instructions). The earlier work also established coverage in the form of a test of the generated files and, with this in-hand, it became feasible to refactor this safely and without fear of breakge. Opt to do this. Apply the notion of distinct phases to the code itself: break generateconfs() into a series of distinct functions. Be minimal in doing thus leaving a large amount of potential for e.g. improved naming and further alignment on the table - but the result is a rather compact diff that nevertheless makes makes it possible to get at the data structures flowing through the process thus enablng further work. Note that this exercise causes path handling to begin to consolidate which allows distiguishing configuration values from the options that govern where outputs will be written.
7f6f448
to
9400618
Compare
@@ -42,7 +42,7 @@ | |||
|
|||
# NOTE: __file__ is /MIG_BASE/mig/install/generateconfs.py and we need MIG_BASE | |||
|
|||
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) | |||
sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), "../.."))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd would prefer to avoid this construct if it's really a matter of handling __file__
possibly being a relative path. In that case I'd much prefer to call abspath
(or realpath
) on file first thing. It's only if we e.g. cross symlinks that realpath should be needed...
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
My brief tests indicate that it will work no matter how __file__
is executed and across python versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - for the record this was changed because I was unable to directly execute the script with the previous formulation.
That said, really this dovetails with PYTHONPATH
and once that is honoured everywhere these all go away. That't not to say it shouldn't be right in-tree, but for the sake of record this is understood as being legacy anyway and there will be a mass removal of straggling stuff like this once it is safe to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, and yes that sounds like PYTHONPATH and/or abspath might be missing in certain variations of the expansion. If we can just add the abspath(__file__)
in those situations I'm quite confident we won't introduce other side effects until we can drop the workaround completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks generally good. I'll go ahead and see if it also merges cleanly. Needs careful post-merge verification on dev/test sites when complete.
Manually merged through svn with minor modifications. |
Previous work lead to the observation that in the many LoC that make up generateconfs there are in fact distinct phases: the creation of a finalised values that are to be written and the injection of those values into various templates (and the output of instructions).
The earlier work also established coverage in the form of a test of the generated files and, with this in-hand, it became feasible to refactor this safely and without fear of breakge.
Opt to do this. Apply the notion of distinct phases to the code itself: break generateconfs() into a series of distinct functions. Be minimal in doing thus leaving a large amount of potential for e.g. improved naming and further alignment on the table - but the result is a rather compact diff that nevertheless makes makes it possible to get at the data structures flowing through the process thus enablng further work.
Note that this exercise causes path handling to begin to consolidate which allows distiguishing configuration values from options that govern where outputs will be written.