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

Partial refactor of code base #170

Merged
merged 10 commits into from
Feb 27, 2018
Merged

Partial refactor of code base #170

merged 10 commits into from
Feb 27, 2018

Conversation

MrMeemus
Copy link
Contributor

Changes made:

Argument handling

  • Moved from click to argparse. Still retaining click for it's echo via pager API.
  • All objects are accessed via the namespace object generated by argparser.
  • Arg parse can handle defaults better, no longer requiring explicit checks to set another option.
    Example: If no server is passed in, we automatically target master. This reduced checks and centralizes all options into a single file.

Tests

  • Tests have been updated to handle options via a namespace object. This allows each test method to express what options to toggle along with retaining default values.
  • All mssql client and option creations are centralized and no longer need explicitly set values on all calls unless a non default option is necessary. This is evident in test_mssqlcliclient.py and test_rowlimit.py

Miscellaneous

  • Methods were renamed for readability.
  • Added additional layers of abstraction for readability.
  • Messages logged are trimmed since some did not provide additional value.
  • Updated mssqlcliclient to support a shallow clone method.
  • Mssqlcliclient has private methods added to abstract away the connection and query execution API.
  • sqltoolsclient API are expressed in a class variable so as to avoid any hardcoded JSON RPC calls.
  • lower case all action for build.py for robustness.

build.py Outdated
targets[action]()
current_action = action.lower()
if current_action in targets:
targets[current_action]()
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 we should validate all actions and fail before we execute any action. #Closed

MSSQL_CLI_RC = u'MSSQL_CLI_RC'


def initialize():
Copy link
Member

Choose a reason for hiding this comment

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

We have two public methods that do the same thing: initialize and get_parser. Can we have a single method: create_parser? #Closed

return args_parser


def get_parser():
Copy link
Member

Choose a reason for hiding this comment

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

get_parser implies we are returning an existing instance. Since were creating a new one each call, I'd prefer we name this create_parser or build_parser. #Closed

err=True, fg='yellow')
logger.info(u'Unable to reset connection to server {0}; database {1}'.format(
mssqlcli_client.server_name,
mssqlcli_client.database))
exit(1)
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 this logic can be moved into a reset instance method. #Closed

@@ -335,19 +342,19 @@ def reset_connection_and_clients(sql_tools_client, *mssqlcliclients):
try:
sql_tools_client.shutdown()
new_tools_client = SqlToolsClient()
Copy link
Member

Choose a reason for hiding this comment

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

A client should not reinitialize the sqltoolsservice process. Can we move this a reset method in the sqltoolsclient client? #Closed

return owner_uri, error_messages

def execute_multi_statement(self, query):
# Try to run first as special command
Copy link
Member

Choose a reason for hiding this comment

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

From and API standpoint, it would be nice if we had a single public method to execute on or more statements: execute_query. So execute_single_statement would become private. Any downside to this? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, no downsides other then background queries will run through additional code path but it wouldn't be harmful.


In reply to: 170340117 [](ancestors = 170340117)

@pensivebrian
Copy link
Member

pensivebrian commented Feb 23, 2018

class MssqlCli(object):

What do you think about moving MssqlCli into it's own file? #WontFix


Refers to: mssqlcli/main.py:102 in 4eb4555. [](commit_id = 4eb4555, deletion_comment = False)

@pensivebrian
Copy link
Member

pensivebrian commented Feb 23, 2018

"""

I think this operation should be moved to the MssqlCli object. #Closed


Refers to: mssqlcli/mssqlcliclient.py:338 in 4eb4555. [](commit_id = 4eb4555, deletion_comment = False)

@MrMeemus
Copy link
Contributor Author

MrMeemus commented Feb 23, 2018

@pensivebrian , YES I WANT TO MOVE MSSQLCLI INTO ITS OWN FILE :) , I can do this on the side in a separate PR as I'm prioritizing the packaging work now.

Copy link
Member

@pensivebrian pensivebrian left a comment

Choose a reason for hiding this comment

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

🕐

Also, what are the code coverage numbers with this change?

@MrMeemus
Copy link
Contributor Author

67% code coverage

mssqlcli/main.py Outdated

click.secho('Reconnected!\nTry the command again.', fg='green')
except Exception as e:
click.secho(str(e), err=True, fg='red')

def reset_connection(self):
"""
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just call this reset? #Closed

Copy link
Member

Choose a reason for hiding this comment

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

If you change this, please update the method name in the logging below.


In reply to: 170392798 [](ancestors = 170392798)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It sounds more intuitive to have reset_connection because that is explicitly resetting, what do you think?

Having just reset can imply a lot of options to be reset for MssqlCli.


In reply to: 170392798 [](ancestors = 170392798)

mssqlcli/main.py Outdated
self.mssqlcliclient_main.sql_tools_client = self.sqltoolsclient
self.mssqlcliclient_main.is_connected = False
self.mssqlcliclient_main.owner_uri = generate_owner_uri()

Copy link
Member

Choose a reason for hiding this comment

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

I feel like we should clone the existing mssqlclient such that we know we're in a clean state. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, I like that idea. Will add it next.


In reply to: 170394199 [](ancestors = 170394199)

@pensivebrian
Copy link
Member

pensivebrian commented Feb 23, 2018

:shipit: Awesome! I really like how this cleaned things up.

@abhisheksinha89
Copy link
Contributor

abhisheksinha89 commented Feb 23, 2018

Can we file a GitHub issue to completely remove click once we are done with refactoring? #Resolved

@MrMeemus
Copy link
Contributor Author

MrMeemus commented Feb 24, 2018

@abhisheksinha89 #171
#Resolved

Copy link
Contributor

@abhisheksinha89 abhisheksinha89 left a comment

Choose a reason for hiding this comment

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

:shipit:

@MrMeemus MrMeemus merged commit f060d9b into master Feb 27, 2018
@MrMeemus MrMeemus deleted the ron/code_cleanup branch February 27, 2018 18:07
hejack0207 pushed a commit to hejack0207/osql-cli that referenced this pull request Apr 27, 2018
* Initial refactor from click to arg parser.

* Refactoring mssqlcli client and renaming methods.

* Refactoring mssqlcliclient.

* Updating tests.

* Updating import statement order.

* Adding missing param and fixing pgsql ref.

* Making build.py argument handling robust.

* Addressing CR comments.

* Renamed method for resetting connection and updated to use clone method.

* Updating log message in reset.
hejack0207 pushed a commit to hejack0207/osql-cli that referenced this pull request Apr 27, 2018
* Initial refactor from click to arg parser.

* Refactoring mssqlcli client and renaming methods.

* Refactoring mssqlcliclient.

* Updating tests.

* Updating import statement order.

* Adding missing param and fixing pgsql ref.

* Making build.py argument handling robust.

* Addressing CR comments.

* Renamed method for resetting connection and updated to use clone method.

* Updating log message in reset.
hejack0207 pushed a commit to hejack0207/osql-cli that referenced this pull request Apr 27, 2018
* Initial refactor from click to arg parser.

* Refactoring mssqlcli client and renaming methods.

* Refactoring mssqlcliclient.

* Updating tests.

* Updating import statement order.

* Adding missing param and fixing pgsql ref.

* Making build.py argument handling robust.

* Addressing CR comments.

* Renamed method for resetting connection and updated to use clone method.

* Updating log message in reset.
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

3 participants