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

[WIP] Initial implementation multi user session #493

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions graphistry/PlotterBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ def reset_caches(self):
cache_coercion_helper.cache_clear()


def __init__(self, *args: Any, **kwargs: Any) -> None:
def __init__(self, PyGraphistry_set=None, *args: Any, **kwargs: Any) -> None:
super(PlotterBase, self).__init__()

# Bindings
self.__PyGraphistry = PyGraphistry_set
self._edges : Any = None
self._nodes : Any = None
self._source : Optional[str] = None
Expand Down Expand Up @@ -1373,8 +1374,7 @@ def plot(
.plot(es)

"""
from .pygraphistry import PyGraphistry
logger.debug("1. @PloatterBase plot: PyGraphistry.org_name(): {}".format(PyGraphistry.org_name()))
logger.debug("1. @PloatterBase plot: PyGraphistry.org_name(): {}".format(self.__PyGraphistry.org_name()))

if graph is None:
if self._edges is None:
Expand All @@ -1389,22 +1389,22 @@ def plot(
self._check_mandatory_bindings(not isinstance(n, type(None)))

# from .pygraphistry import PyGraphistry
api_version = PyGraphistry.api_version()
logger.debug("2. @PloatterBase plot: PyGraphistry.org_name(): {}".format(PyGraphistry.org_name()))
api_version = self.__PyGraphistry.api_version()
logger.debug("2. @PloatterBase plot: PyGraphistry.org_name(): {}".format(self.__PyGraphistry.org_name()))
if api_version == 1:
dataset = self._plot_dispatch(g, n, name, description, 'json', self._style, memoize)
if skip_upload:
return dataset
info = PyGraphistry._etl1(dataset)
info = self.__PyGraphistry._etl1(dataset)
elif api_version == 3:
logger.debug("3. @PloatterBase plot: PyGraphistry.org_name(): {}".format(PyGraphistry.org_name()))
PyGraphistry.refresh()
logger.debug("4. @PloatterBase plot: PyGraphistry.org_name(): {}".format(PyGraphistry.org_name()))
logger.debug("3. @PloatterBase plot: PyGraphistry.org_name(): {}".format(self.__PyGraphistry.org_name()))
self.__PyGraphistry.refresh()
logger.debug("4. @PloatterBase plot: PyGraphistry.org_name(): {}".format(self.__PyGraphistry.org_name()))

dataset = self._plot_dispatch(g, n, name, description, 'arrow', self._style, memoize)
if skip_upload:
return dataset
dataset.token = PyGraphistry.api_token()
dataset.token = self.__PyGraphistry.api_token()
dataset.post(as_files=as_files, memoize=memoize)
dataset.maybe_post_share_link(self)
info = {
Expand All @@ -1413,9 +1413,9 @@ def plot(
'viztoken': str(uuid.uuid4())
}

viz_url = PyGraphistry._viz_url(info, self._url_params)
cfg_client_protocol_hostname = PyGraphistry._config['client_protocol_hostname']
full_url = ('%s:%s' % (PyGraphistry._config['protocol'], viz_url)) if cfg_client_protocol_hostname is None else viz_url
viz_url = self.__PyGraphistry._viz_url(info, self._url_params)
cfg_client_protocol_hostname = self.__PyGraphistry._config['client_protocol_hostname']
full_url = ('%s:%s' % (self.__PyGraphistry._config['protocol'], viz_url)) if cfg_client_protocol_hostname is None else viz_url

if (render is False) or ((render is None) and not self._render):
return full_url
Expand Down Expand Up @@ -1941,8 +1941,6 @@ def _make_dataset(self, edges, nodes, name, description, mode, metadata=None, me
# Main helper for creating ETL1 payload
def _make_json_dataset(self, edges, nodes, name):

from .pygraphistry import PyGraphistry

def flatten_categorical(df):
# Avoid cat_col.where(...)-related exceptions
df2 = df.copy()
Expand All @@ -1956,7 +1954,7 @@ def flatten_categorical(df):

bindings = {'idField': self._node or PlotterBase._defaultNodeId,
'destinationField': self._destination, 'sourceField': self._source}
dataset = {'name': PyGraphistry._config['dataset_prefix'] + name,
dataset = {'name': self.__PyGraphistry._config['dataset_prefix'] + name,
'bindings': bindings, 'type': 'edgelist', 'graph': edict}

if nlist is not None:
Expand All @@ -1967,20 +1965,20 @@ def flatten_categorical(df):

def _make_arrow_dataset(self, edges: pa.Table, nodes: pa.Table, name: str, description: str, metadata) -> ArrowUploader:

from .pygraphistry import PyGraphistry
au : ArrowUploader = ArrowUploader(
server_base_path=PyGraphistry.protocol() + '://' + PyGraphistry.server(),
PyGraphistry_set = self.__PyGraphistry,
server_base_path=self.__PyGraphistry.protocol() + '://' + self.__PyGraphistry.server(),
edges=edges, nodes=nodes,
name=name, description=description,
metadata={
'usertag': PyGraphistry._tag,
'key': PyGraphistry.api_key(),
'usertag': self.__PyGraphistry._tag,
'key': self.__PyGraphistry.api_key(),
'agent': 'pygraphistry',
'apiversion' : '3',
'agentversion': sys.modules['graphistry'].__version__, # type: ignore
**(metadata or {})
},
certificate_validation=PyGraphistry.certificate_validation())
certificate_validation=self.__PyGraphistry.certificate_validation())

au.edge_encodings = au.g_to_edge_encodings(self)
au.node_encodings = au.g_to_node_encodings(self)
Expand Down Expand Up @@ -2041,10 +2039,8 @@ def infer_labels(self):

def cypher(self, query, params={}):

from .pygraphistry import PyGraphistry

res = copy.copy(self)
driver = self._bolt_driver or PyGraphistry._config['bolt_driver']
driver = self._bolt_driver or self.__PyGraphistry._config['bolt_driver']
if driver is None:
raise ValueError("BOLT connection information not provided. Must first call graphistry.register(bolt=...) or g.bolt(...).")
with driver.session() as session:
Expand Down
5 changes: 4 additions & 1 deletion graphistry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

from graphistry.pygraphistry import ( # noqa: E402, F401
_user_sessions,
current_session,
instance,
client_protocol_hostname,
protocol,
server,
Expand Down Expand Up @@ -44,7 +47,7 @@
nodexl,
ArrowUploader,
ArrowFileUploader,
PyGraphistry,
PyGraphistry as init,
from_igraph,
from_cugraph
)
Expand Down
31 changes: 14 additions & 17 deletions graphistry/arrow_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def certificate_validation(self, certificate_validation):


def __init__(self,
PyGraphistry_set = None,
server_base_path='http://nginx', view_base_path='http://localhost',
name = None,
description = None,
Expand All @@ -176,15 +177,15 @@ def __init__(self,
self.__metadata = metadata
self.__certificate_validation = certificate_validation
self.__org_name = org_name if org_name else None
self.__PyGraphistry = PyGraphistry_set

if org_name:
self.__org_name = org_name
else:
# check current org_name
from .pygraphistry import PyGraphistry
if 'org_name' in PyGraphistry._config:
logger.debug("@ArrowUploader.__init__: There is an org_name : {}".format(PyGraphistry._config['org_name']))
self.__org_name = PyGraphistry._config['org_name']
if self.__PyGraphistry and 'org_name' in self.__PyGraphistry._config:
logger.debug("@ArrowUploader.__init__: There is an org_name : {}".format(self.__PyGraphistry._config['org_name']))
self.__org_name = self.__PyGraphistry._config['org_name']
else:
self.__org_name = None

Expand Down Expand Up @@ -222,7 +223,6 @@ def pkey_login(self, personal_key_id, personal_key_secret, org_name=None):
return self._handle_login_response(out, org_name)

def _handle_login_response(self, out, org_name):
from .pygraphistry import PyGraphistry
json_response = None
try:
json_response = out.json()
Expand Down Expand Up @@ -250,13 +250,13 @@ def _handle_login_response(self, out, org_name):
raise Exception("You are not authorized or not a member of {}".format(org_name))

if logged_in_org_name is None and org_name is None:
if 'org_name' in PyGraphistry._config:
del PyGraphistry._config['org_name']
if self.__PyGraphistry and 'org_name' in self.__PyGraphistry._config:
del self.__PyGraphistry._config['org_name']
else:
if org_name in PyGraphistry._config:
logger.debug("@ArrowUploder, handle login reponse, org_name: {}".format(PyGraphistry._config['org_name']))
PyGraphistry._config['org_name'] = logged_in_org_name
# PyGraphistry.org_name(logged_in_org_name)
if self.__PyGraphistry and org_name in self.__PyGraphistry._config:
logger.debug("@ArrowUploder, handle login reponse, org_name: {}".format(self.__PyGraphistry._config['org_name']))
self.__PyGraphistry._config['org_name'] = logged_in_org_name
# self.__PyGraphistry.org_name(logged_in_org_name)
except Exception:
logger.error('Error: %s', out, exc_info=True)
raise
Expand Down Expand Up @@ -548,9 +548,7 @@ def cascade_privacy_settings(
- global
- hard-coded
"""

from .pygraphistry import PyGraphistry
global_privacy = PyGraphistry._config['privacy']
global_privacy = self.__PyGraphistry._config['privacy'] if self.__PyGraphistry else None
if global_privacy is not None:
if mode is None:
mode = global_privacy['mode']
Expand Down Expand Up @@ -691,9 +689,8 @@ def maybe_post_share_link(self, g) -> bool:
Skip if never called .privacy()
Return True/False based on whether called
"""
from .pygraphistry import PyGraphistry
logger.debug('Privacy: global (%s), local (%s)', PyGraphistry._config['privacy'] or 'None', g._privacy or 'None')
if PyGraphistry._config['privacy'] is not None or g._privacy is not None:
logger.debug('Privacy: global (%s), local (%s)', self.__PyGraphistry._config['privacy'] or 'None', g._privacy or 'None')
if (self.__PyGraphistry and self.__PyGraphistry._config['privacy'] is not None) or g._privacy is not None:
self.post_share_link(self.dataset_id, 'dataset', g._privacy)
return True

Expand Down
4 changes: 2 additions & 2 deletions graphistry/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
class Plotter( # type: ignore
*mixins # type: ignore
): # type: ignore
def __init__(self, *args, **kwargs):
PlotterBase.__init__(self, *args, **kwargs)
def __init__(self, PyGraphistry_set, *args, **kwargs):
PlotterBase.__init__(self, PyGraphistry_set, *args, **kwargs)
ComputeMixin.__init__(self, *args, **kwargs)
LayoutsMixin.__init__(self, *args, **kwargs)
ConditionalMixin.__init__(self, *args, **kwargs)
Expand Down
Loading
Loading