diff --git a/README.rst b/README.rst index 255a1ff26a..36a273f0e0 100644 --- a/README.rst +++ b/README.rst @@ -198,9 +198,14 @@ Development `__. 2. Run ``python setup.py install`` to install the Python client. -If you are planning to contribute, please make sure that it fits the -guidelines described in -`PEP8 `__. +If you are planning to contribute: + +1. Run ``pip install -r requirements-dev.txt`` to install development + dependencies. +2. Use `black `__ to reformat the code + by running the ``black .`` command. +3. Make sure that tests are passing by following the steps described + in the next section. Testing ^^^^^^^ diff --git a/docs/conf.py b/docs/conf.py index 5fddb38274..1222ef59c6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,7 +18,7 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('..')) +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -29,17 +29,17 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', - 'sphinx.ext.autosectionlabel', + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.napoleon", + "sphinx.ext.viewcode", + "sphinx.ext.autosectionlabel", ] autodoc_default_options = { - 'members': None, - 'undoc-members': None, - 'show-inheritance': None, + "members": None, + "undoc-members": None, + "show-inheritance": None, } # Autosummary on @@ -49,35 +49,35 @@ autosectionlabel_prefix_document = True # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. # source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Hazelcast Python Client' -copyright = u'2020, Hazelcast Inc.' -author = u'Hazelcast Inc. Developers' +project = u"Hazelcast Python Client" +copyright = u"2020, Hazelcast Inc." +author = u"Hazelcast Inc. Developers" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '4.0.0' +version = "4.0.0" # The full version, including alpha/beta/rc tags. -release = '4.0.0b1' +release = "4.0.0b1" -autodoc_member_order = 'bysource' -autoclass_content = 'both' +autodoc_member_order = "bysource" +autoclass_content = "both" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -95,7 +95,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -113,7 +113,7 @@ # show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. # modindex_common_prefix = [] @@ -128,7 +128,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = "default" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -222,20 +222,17 @@ # html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. -htmlhelp_basename = 'hazelcast-python-clientdoc' +htmlhelp_basename = "hazelcast-python-clientdoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # 'preamble': '', - # Latex figure (float) alignment # 'figure_align': 'htbp', } @@ -244,8 +241,13 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'hazelcast-python-client.tex', u'Hazelcast Python Client Documentation', - author, 'manual'), + ( + master_doc, + "hazelcast-python-client.tex", + u"Hazelcast Python Client Documentation", + author, + "manual", + ), ] # The name of an image file (relative to this directory) to place at the top of @@ -274,8 +276,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'hazelcast-python-client', u'Hazelcast Python Client Documentation', - [author], 1) + (master_doc, "hazelcast-python-client", u"Hazelcast Python Client Documentation", [author], 1) ] # If true, show URL addresses after external links. @@ -288,9 +289,15 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'hazelcast-python-client', u'Hazelcast Python Client Documentation', - author, 'hazelcast-python-client', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "hazelcast-python-client", + u"Hazelcast Python Client Documentation", + author, + "hazelcast-python-client", + "One line description of project.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. @@ -305,12 +312,10 @@ # If true, do not generate a @detailmenu in the "Top" node's menu. # texinfo_no_detailmenu = False -on_rtd = os.environ.get('READTHEDOCS') == 'True' +on_rtd = os.environ.get("READTHEDOCS") == "True" if not on_rtd: # If we are building locally, import the RTD theme # and use it - - import sphinx_rtd_theme - extensions.append('sphinx_rtd_theme') - html_theme = 'sphinx_rtd_theme' + extensions.append("sphinx_rtd_theme") + html_theme = "sphinx_rtd_theme" diff --git a/docs/development_and_testing.rst b/docs/development_and_testing.rst index 2f62fddf38..f50cf27604 100644 --- a/docs/development_and_testing.rst +++ b/docs/development_and_testing.rst @@ -15,9 +15,14 @@ its source: (https://github.com/hazelcast/hazelcast-python-client.git). 2. Run ``python setup.py install`` to install the Python client. -If you are planning to contribute, please make sure that it fits the -guidelines described in -`PEP8 `__. +If you are planning to contribute: + +1. Run ``pip install -r requirements-dev.txt`` to install development + dependencies. +2. Use `black `__ to reformat the code + by running the ``black .`` command. +3. Make sure that tests are passing by following the steps described + in the :ref:`development_and_testing:testing` section. Testing ------- diff --git a/examples/cloud-discovery/hazelcast_cloud_discovery_example.py b/examples/cloud-discovery/hazelcast_cloud_discovery_example.py index b1e87ddd8b..de7eca0460 100644 --- a/examples/cloud-discovery/hazelcast_cloud_discovery_example.py +++ b/examples/cloud-discovery/hazelcast_cloud_discovery_example.py @@ -11,7 +11,7 @@ ssl_cafile="/path/to/ca.pem", ssl_certfile="/path/to/cert.pem", ssl_keyfile="/path/to/key.pem", - ssl_password="YOUR_KEY_STORE_PASSWORD" + ssl_password="YOUR_KEY_STORE_PASSWORD", ) my_map = client.get_map("map-on-the-cloud").blocking() diff --git a/examples/flake-id-generator/flake_id_generator_example.py b/examples/flake-id-generator/flake_id_generator_example.py index 84e61b2b17..2952b3118f 100644 --- a/examples/flake-id-generator/flake_id_generator_example.py +++ b/examples/flake-id-generator/flake_id_generator_example.py @@ -1,11 +1,13 @@ import hazelcast -client = hazelcast.HazelcastClient(flake_id_generators={ - "id-generator": { - "prefetch_count": 50, - "prefetch_validity": 30, +client = hazelcast.HazelcastClient( + flake_id_generators={ + "id-generator": { + "prefetch_count": 50, + "prefetch_validity": 30, + } } -}) +) generator = client.get_flake_id_generator("id-generator").blocking() diff --git a/examples/hazelcast-json-value/hazelcast_json_value_example.py b/examples/hazelcast-json-value/hazelcast_json_value_example.py index 744c8a88db..3f7500d79a 100644 --- a/examples/hazelcast-json-value/hazelcast_json_value_example.py +++ b/examples/hazelcast-json-value/hazelcast_json_value_example.py @@ -6,8 +6,8 @@ client = hazelcast.HazelcastClient() employees_map = client.get_map("employees").blocking() -alice = "{\"name\": \"Alice\", \"age\": 35}" -andy = "{\"name\": \"Andy\", \"age\": 22}" +alice = '{"name": "Alice", "age": 35}' +andy = '{"name": "Andy", "age": 22}' bob = {"name": "Bob", "age": 37} # HazelcastJsonValue can be constructed from JSON strings diff --git a/examples/learning-basics/2-create_a_map.py b/examples/learning-basics/2-create_a_map.py index a459ae04f2..678d6fbc16 100644 --- a/examples/learning-basics/2-create_a_map.py +++ b/examples/learning-basics/2-create_a_map.py @@ -1,11 +1,7 @@ import hazelcast # Connect -client = hazelcast.HazelcastClient( - cluster_members=[ - "127.0.0.1:5701" - ] -) +client = hazelcast.HazelcastClient(cluster_members=["127.0.0.1:5701"]) # Get a map that is stored on the server side. We can access it from the client greetings_map = client.get_map("greetings-map").blocking() diff --git a/examples/learning-basics/3-read_from_a_map.py b/examples/learning-basics/3-read_from_a_map.py index c882040414..8dcedb52c5 100644 --- a/examples/learning-basics/3-read_from_a_map.py +++ b/examples/learning-basics/3-read_from_a_map.py @@ -1,11 +1,7 @@ import hazelcast # Connect -client = hazelcast.HazelcastClient( - cluster_members=[ - "127.0.0.1:5701" - ] -) +client = hazelcast.HazelcastClient(cluster_members=["127.0.0.1:5701"]) # We can access maps on the server from the client. Let's access the greetings map that we created already greetings_map = client.get_map("greetings-map").blocking() diff --git a/examples/map/map_listener_example.py b/examples/map/map_listener_example.py index 8fdd8b8aa5..82748751de 100644 --- a/examples/map/map_listener_example.py +++ b/examples/map/map_listener_example.py @@ -12,14 +12,19 @@ def entry_removed(event): def entry_updated(event): - print("Entry updated with key: %s, old value: %s, new value: %s" % (event.key, event.old_value, event.value)) + print( + "Entry updated with key: %s, old value: %s, new value: %s" + % (event.key, event.old_value, event.value) + ) client = hazelcast.HazelcastClient() my_map = client.get_map("listener-map").blocking() -my_map.add_entry_listener(True, added_func=entry_added, removed_func=entry_removed, updated_func=entry_updated) +my_map.add_entry_listener( + True, added_func=entry_added, removed_func=entry_removed, updated_func=entry_updated +) my_map.put("key", "value") my_map.put("key", "new value") diff --git a/examples/map/map_paging_predicate_example.py b/examples/map/map_paging_predicate_example.py index c3c61f5938..e196206c80 100644 --- a/examples/map/map_paging_predicate_example.py +++ b/examples/map/map_paging_predicate_example.py @@ -6,15 +6,17 @@ m1 = client.get_map("m1").blocking() -m1.put_all({ - "a": 1, - "b": 2, - "c": 3, - "d": 4, - "e": 5, - "f": 6, - "g": 7, -}) +m1.put_all( + { + "a": 1, + "b": 2, + "c": 3, + "d": 4, + "e": 5, + "f": 6, + "g": 7, + } +) size = m1.size() print("Added %s elements" % size) @@ -39,6 +41,7 @@ # server side and registered as a Portable or IdentifiedDataSerializable # before the server starts. + class ReversedKeyComparator(IdentifiedDataSerializable): """ This class is simply a marker implementation @@ -47,6 +50,7 @@ class ReversedKeyComparator(IdentifiedDataSerializable): server side. A sample server side implementation is provided at the end of file. """ + def get_class_id(self): return 1 diff --git a/examples/map/map_portable_query_example.py b/examples/map/map_portable_query_example.py index 038edf921c..5fec113c73 100644 --- a/examples/map/map_portable_query_example.py +++ b/examples/map/map_portable_query_example.py @@ -34,11 +34,9 @@ def __eq__(self, other): return isinstance(other, Employee) and self.name == other.name and self.age == other.age -client = hazelcast.HazelcastClient(portable_factories={ - Employee.FACTORY_ID: { - Employee.CLASS_ID: Employee - } -}) +client = hazelcast.HazelcastClient( + portable_factories={Employee.FACTORY_ID: {Employee.CLASS_ID: Employee}} +) my_map = client.get_map("employee-map") diff --git a/examples/map/map_portable_versioning_example.py b/examples/map/map_portable_versioning_example.py index 3dbcd4ca8d..b41de5448a 100644 --- a/examples/map/map_portable_versioning_example.py +++ b/examples/map/map_portable_versioning_example.py @@ -39,6 +39,7 @@ def __str__(self): def __eq__(self, other): return type(self) == type(other) and self.name == other.name and self.age == other.age + # If you update the class by changing the type of one of the fields or by adding a new field, # it is a good idea to upgrade the version of the class, rather than sticking to the global versioning # that is specified in the hazelcast.xml file. @@ -79,8 +80,12 @@ def __str__(self): return "Employee(name:%s, age:%s, manager:%s)" % (self.name, self.age, self.manager) def __eq__(self, other): - return isinstance(other, Employee2) and self.name == other.name and self.age == other.age \ - and self.manager == other.manager + return ( + isinstance(other, Employee2) + and self.name == other.name + and self.age == other.age + and self.manager == other.manager + ) # However, having a version that changes across incompatible field types such as int and String will cause @@ -120,28 +125,26 @@ def __str__(self): return "Employee(name:%s, age:%s manager:%s)" % (self.name, self.age, self.manager) def __eq__(self, other): - return isinstance(other, Employee3) and self.name == other.name and self.age == other.age \ - and self.manager == other.manager + return ( + isinstance(other, Employee3) + and self.name == other.name + and self.age == other.age + and self.manager == other.manager + ) # Let's now configure 3 clients with 3 different versions of Employee. -client = hazelcast.HazelcastClient(portable_factories={ - Employee.FACTORY_ID: { - Employee.CLASS_ID: Employee - } -}) - -client2 = hazelcast.HazelcastClient(portable_factories={ - Employee2.FACTORY_ID: { - Employee2.CLASS_ID: Employee2 - } -}) - -client3 = hazelcast.HazelcastClient(portable_factories={ - Employee3.FACTORY_ID: { - Employee3.CLASS_ID: Employee3 - } -}) +client = hazelcast.HazelcastClient( + portable_factories={Employee.FACTORY_ID: {Employee.CLASS_ID: Employee}} +) + +client2 = hazelcast.HazelcastClient( + portable_factories={Employee2.FACTORY_ID: {Employee2.CLASS_ID: Employee2}} +) + +client3 = hazelcast.HazelcastClient( + portable_factories={Employee3.FACTORY_ID: {Employee3.CLASS_ID: Employee3}} +) # Assume that a member joins a cluster with a newer version of a class. # If you modified the class by adding a new field, the new member's put operations include that @@ -153,7 +156,7 @@ def __eq__(self, other): my_map.put(0, Employee("Jack", 28)) my_map2.put(1, Employee2("Jane", 29, "Josh")) -print('Map Size: %s' % my_map.size()) +print("Map Size: %s" % my_map.size()) # If this new member tries to get an object that was put from the older members, it # gets null for the newly added field. @@ -167,7 +170,7 @@ def __eq__(self, other): my_map3 = client3.get_map("employee-map").blocking() my_map3.put(2, Employee3("Joe", "30", "Mary")) -print('Map Size: %s' % my_map.size()) +print("Map Size: %s" % my_map.size()) # As clients with incompatible versions of the class try to access each other, a HazelcastSerializationError # is raised (caused by a TypeError). diff --git a/examples/monitoring/lifecycle_listener_example.py b/examples/monitoring/lifecycle_listener_example.py index 921bac825f..4c17d0d66e 100644 --- a/examples/monitoring/lifecycle_listener_example.py +++ b/examples/monitoring/lifecycle_listener_example.py @@ -5,8 +5,6 @@ def on_state_change(state): print("State changed to", state) -client = hazelcast.HazelcastClient(lifecycle_listeners=[ - on_state_change -]) +client = hazelcast.HazelcastClient(lifecycle_listeners=[on_state_change]) client.shutdown() diff --git a/examples/org-website/atomic_long_sample.py b/examples/org-website/atomic_long_sample.py index 51d6dff272..4c6612193c 100644 --- a/examples/org-website/atomic_long_sample.py +++ b/examples/org-website/atomic_long_sample.py @@ -3,12 +3,11 @@ # Start the Hazelcast Client and connect to an already running # Hazelcast Cluster on 127.0.0.1 # Note: CP Subsystem has to be enabled on the cluster -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get the AtomicLong counter from Cluster -counter = hz.cp_subsystem.get_atomic_long("counter").blocking() +counter = client.cp_subsystem.get_atomic_long("counter").blocking() # Add and get the counter value = counter.add_and_get(3) print("Counter value is", value) # Shutdown this Hazelcast client -hz.shutdown() - +client.shutdown() diff --git a/examples/org-website/custom_serializer_sample.py b/examples/org-website/custom_serializer_sample.py index 3614895ab3..9000347edb 100644 --- a/examples/org-website/custom_serializer_sample.py +++ b/examples/org-website/custom_serializer_sample.py @@ -23,9 +23,7 @@ def destroy(self): # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient(custom_serializers={ - CustomSerializableType: CustomSerializer -}) +client = hazelcast.HazelcastClient(custom_serializers={CustomSerializableType: CustomSerializer}) # CustomSerializer will serialize/deserialize CustomSerializable objects -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/entry_processor_sample.py b/examples/org-website/entry_processor_sample.py index 540996c52b..3ec6dbcff3 100644 --- a/examples/org-website/entry_processor_sample.py +++ b/examples/org-website/entry_processor_sample.py @@ -21,9 +21,9 @@ def get_class_id(self): # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get the Distributed Map from Cluster. -my_map = hz.get_map("my-distributed-map").blocking() +my_map = client.get_map("my-distributed-map").blocking() # Put the integer value of 0 into the Distributed Map my_map.put("key", 0) # Run the IncEntryProcessor class on the Hazelcast Cluster Member holding the key called "key" @@ -31,4 +31,4 @@ def get_class_id(self): # Show that the IncEntryProcessor updated the value. print("new value:", my_map.get("key")) # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/executor_service_sample.py b/examples/org-website/executor_service_sample.py index a43ad1360c..d9d14aa7f7 100644 --- a/examples/org-website/executor_service_sample.py +++ b/examples/org-website/executor_service_sample.py @@ -24,11 +24,11 @@ def get_class_id(self): # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get the Distributed Executor Service -ex = hz.get_executor("my-distributed-executor") +ex = client.get_executor("my-distributed-executor") # Get the an Hazelcast Cluster Member -member = hz.cluster_service.get_members()[0] +member = client.cluster_service.get_members()[0] # Submit the MessagePrinter Runnable to the first Hazelcast Cluster Member ex.execute_on_member(member, MessagePrinter("message to very first member of the cluster")) # Submit the MessagePrinter Runnable to all Hazelcast Cluster Members @@ -36,4 +36,4 @@ def get_class_id(self): # Submit the MessagePrinter Runnable to the Hazelcast Cluster Member owning the key called "key" ex.execute_on_key_owner("key", MessagePrinter("message to the member that owns the following key")) # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/global_serializer_sample.py b/examples/org-website/global_serializer_sample.py index 82ad38b7d9..d48b41b3ba 100644 --- a/examples/org-website/global_serializer_sample.py +++ b/examples/org-website/global_serializer_sample.py @@ -20,6 +20,6 @@ def destroy(self): # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient(global_serializer=GlobalSerializer) +client = hazelcast.HazelcastClient(global_serializer=GlobalSerializer) # GlobalSerializer will serialize/deserialize all non-builtin types -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/identified_data_serializable_sample.py b/examples/org-website/identified_data_serializable_sample.py index 2d3205f282..d8c811b9c3 100644 --- a/examples/org-website/identified_data_serializable_sample.py +++ b/examples/org-website/identified_data_serializable_sample.py @@ -27,10 +27,8 @@ def get_class_id(self): # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient(data_serializable_factories={ - Employee.FACTORY_ID: { - Employee.CLASS_ID: Employee - } -}) +client = hazelcast.HazelcastClient( + data_serializable_factories={Employee.FACTORY_ID: {Employee.CLASS_ID: Employee}} +) # Employee can be used here -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/list_sample.py b/examples/org-website/list_sample.py index e6618dcbf8..fe753d14e2 100644 --- a/examples/org-website/list_sample.py +++ b/examples/org-website/list_sample.py @@ -1,9 +1,9 @@ import hazelcast # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get the Distributed List from Cluster. -my_list = hz.get_list("my-distributed-list").blocking() +my_list = client.get_list("my-distributed-list").blocking() # Add element to the list my_list.add("item1") my_list.add("item2") @@ -15,4 +15,4 @@ # Clear the list my_list.clear() # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/lock_sample.py b/examples/org-website/lock_sample.py index 875771ddfe..cb8d011b9d 100644 --- a/examples/org-website/lock_sample.py +++ b/examples/org-website/lock_sample.py @@ -2,9 +2,9 @@ # Start the Hazelcast Client and connect to an already running # Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get the Distributed Lock from CP Subsystem -lock = hz.cp_subsystem.get_lock("my-distributed-lock").blocking() +lock = client.cp_subsystem.get_lock("my-distributed-lock").blocking() # Now acquire the lock and execute some guarded code fence = lock.lock() print("Fence token:", fence) @@ -15,4 +15,4 @@ lock.unlock() # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/map_sample.py b/examples/org-website/map_sample.py index cf7c345931..2109d30665 100644 --- a/examples/org-website/map_sample.py +++ b/examples/org-website/map_sample.py @@ -1,9 +1,9 @@ import hazelcast # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get the Distributed Map from Cluster. -my_map = hz.get_map("my-distributed-map").blocking() +my_map = client.get_map("my-distributed-map").blocking() # Standard Put and Get my_map.put("key", "value") my_map.get("key") @@ -11,4 +11,4 @@ my_map.put_if_absent("somekey", "somevalue") my_map.replace_if_same("key", "value", "newvalue") # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/multimap_sample.py b/examples/org-website/multimap_sample.py index d25c462c75..588982efa3 100644 --- a/examples/org-website/multimap_sample.py +++ b/examples/org-website/multimap_sample.py @@ -1,9 +1,9 @@ import hazelcast # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get the Distributed MultiMap from Cluster. -multi_map = hz.get_multi_map("my-distributed-multimap").blocking() +multi_map = client.get_multi_map("my-distributed-multimap").blocking() # Put values in the map against the same key multi_map.put("my-key", "value1") multi_map.put("my-key", "value2") @@ -14,4 +14,4 @@ # remove specific key/value pair multi_map.remove("my-key", "value2") # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/portable_serializable_sample.py b/examples/org-website/portable_serializable_sample.py index bacd9baf12..8e2915e6c7 100644 --- a/examples/org-website/portable_serializable_sample.py +++ b/examples/org-website/portable_serializable_sample.py @@ -30,10 +30,8 @@ def get_class_id(self): # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient(portable_factories={ - Customer.FACTORY_ID: { - Customer.CLASS_ID: Customer - } -}) +client = hazelcast.HazelcastClient( + portable_factories={Customer.FACTORY_ID: {Customer.CLASS_ID: Customer}} +) # Customer can be used here -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/query_sample.py b/examples/org-website/query_sample.py index f33ff5a91d..131e44625f 100644 --- a/examples/org-website/query_sample.py +++ b/examples/org-website/query_sample.py @@ -40,13 +40,9 @@ def generate_users(users): # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient(portable_factories={ - User.FACTORY_ID: { - User.CLASS_ID: User - } -}) +client = hazelcast.HazelcastClient(portable_factories={User.FACTORY_ID: {User.CLASS_ID: User}}) # Get a Distributed Map called "users" -users_map = hz.get_map("users").blocking() +users_map = client.get_map("users").blocking() # Add some users to the Distributed Map generate_users(users_map) # Create a Predicate from a String (a SQL like Where clause) @@ -60,4 +56,4 @@ def generate_users(users): print(result1) print(result2) # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/queue_sample.py b/examples/org-website/queue_sample.py index c00aae227b..4bb424db9c 100644 --- a/examples/org-website/queue_sample.py +++ b/examples/org-website/queue_sample.py @@ -1,9 +1,9 @@ import hazelcast # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get a Blocking Queue called "my-distributed-queue" -queue = hz.get_queue("my-distributed-queue").blocking() +queue = client.get_queue("my-distributed-queue").blocking() # Offer a String into the Distributed Queue queue.offer("item") # Poll the Distributed Queue and return the String @@ -15,4 +15,4 @@ queue.put("yetanotheritem") print(queue.take()) # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/replicated_map_sample.py b/examples/org-website/replicated_map_sample.py index 3d6e375577..3a994e8a35 100644 --- a/examples/org-website/replicated_map_sample.py +++ b/examples/org-website/replicated_map_sample.py @@ -1,9 +1,9 @@ import hazelcast # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get a Replicated Map called "my-replicated-map" -rmap = hz.get_replicated_map("my-replicated-map").blocking() +rmap = client.get_replicated_map("my-replicated-map").blocking() # Put and Get a value from the Replicated Map replaced_value = rmap.put("key", "value") # key/value replicated to all members @@ -13,4 +13,4 @@ # the value is retrieved from a random member in the cluster print("value for key =", value) # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/ringbuffer_sample.py b/examples/org-website/ringbuffer_sample.py index fcae6ae6de..474f386d06 100644 --- a/examples/org-website/ringbuffer_sample.py +++ b/examples/org-website/ringbuffer_sample.py @@ -1,8 +1,8 @@ import hazelcast # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() -rb = hz.get_ringbuffer("rb").blocking() +client = hazelcast.HazelcastClient() +rb = client.get_ringbuffer("rb").blocking() # add two items into ring buffer rb.add(100) rb.add(200) @@ -13,4 +13,4 @@ sequence += 1 print(rb.read_one(sequence)) # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/set_sample.py b/examples/org-website/set_sample.py index 17ceababd4..107bd3fb57 100644 --- a/examples/org-website/set_sample.py +++ b/examples/org-website/set_sample.py @@ -1,9 +1,9 @@ import hazelcast # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get the Distributed Set from Cluster. -my_set = hz.get_set("my-distributed-set").blocking() +my_set = client.get_set("my-distributed-set").blocking() # Add items to the set with duplicates my_set.add("item1") my_set.add("item1") @@ -15,4 +15,4 @@ for item in my_set.get_all(): print(item) # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/org-website/topic_sample.py b/examples/org-website/topic_sample.py index 5a4b602e1c..940d127042 100644 --- a/examples/org-website/topic_sample.py +++ b/examples/org-website/topic_sample.py @@ -6,12 +6,12 @@ def print_on_message(topic_message): # Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 -hz = hazelcast.HazelcastClient() +client = hazelcast.HazelcastClient() # Get a Topic called "my-distributed-topic" -topic = hz.get_topic("my-distributed-topic").blocking() +topic = client.get_topic("my-distributed-topic").blocking() # Add a Listener to the Topic topic.add_listener(print_on_message) # Publish a message to the Topic topic.publish("Hello to distributed world") # Shutdown this Hazelcast Client -hz.shutdown() +client.shutdown() diff --git a/examples/pn-counter/pn_counter_example.py b/examples/pn-counter/pn_counter_example.py index 717c72388a..af89c6c9b0 100644 --- a/examples/pn-counter/pn_counter_example.py +++ b/examples/pn-counter/pn_counter_example.py @@ -9,7 +9,9 @@ for i in range(10): print("Added %s to the counter. Current value is %s" % (i, pn_counter.add_and_get(i))) -print("Incremented the counter after getting the current value. " - "Previous value is", pn_counter.get_and_increment()) +print( + "Incremented the counter after getting the current value. Previous value is", + pn_counter.get_and_increment(), +) print("Final value is", pn_counter.get()) diff --git a/examples/serialization/custom_serialization_example.py b/examples/serialization/custom_serialization_example.py index d3aefef0e4..99dcf0cd07 100644 --- a/examples/serialization/custom_serialization_example.py +++ b/examples/serialization/custom_serialization_example.py @@ -36,9 +36,7 @@ def destroy(self): pass -client = hazelcast.HazelcastClient(custom_serializers={ - TimeOfDay: CustomSerializer -}) +client = hazelcast.HazelcastClient(custom_serializers={TimeOfDay: CustomSerializer}) my_map = client.get_map("map").blocking() time_of_day = TimeOfDay(13, 36, 59) diff --git a/examples/serialization/global_serialization_example.py b/examples/serialization/global_serialization_example.py index f19570c097..ba3a377b0b 100644 --- a/examples/serialization/global_serialization_example.py +++ b/examples/serialization/global_serialization_example.py @@ -39,9 +39,7 @@ def destroy(self): client = hazelcast.HazelcastClient(global_serializer=GlobalSerializer) -group = ColorGroup(id=1, - name="Reds", - colors=["Crimson", "Red", "Ruby", "Maroon"]) +group = ColorGroup(id=1, name="Reds", colors=["Crimson", "Red", "Ruby", "Maroon"]) my_map = client.get_map("map").blocking() diff --git a/examples/serialization/identified_data_serializable_example.py b/examples/serialization/identified_data_serializable_example.py index ad5a47c586..849253feac 100644 --- a/examples/serialization/identified_data_serializable_example.py +++ b/examples/serialization/identified_data_serializable_example.py @@ -32,11 +32,9 @@ def __repr__(self): return "Student(id=%s, name=%s, gpa=%s)" % (self.id, self.name, self.gpa) -client = hazelcast.HazelcastClient(data_serializable_factories={ - Student.FACTORY_ID: { - Student.CLASS_ID: Student - } -}) +client = hazelcast.HazelcastClient( + data_serializable_factories={Student.FACTORY_ID: {Student.CLASS_ID: Student}} +) my_map = client.get_map("map") diff --git a/examples/serialization/portable_example.py b/examples/serialization/portable_example.py index 3feedff83e..7c7819086a 100644 --- a/examples/serialization/portable_example.py +++ b/examples/serialization/portable_example.py @@ -32,11 +32,9 @@ def __repr__(self): return "Engineer(name=%s, age=%s, languages=%s)" % (self.name, self.age, self.languages) -client = hazelcast.HazelcastClient(portable_factories={ - Engineer.FACTORY_ID: { - Engineer.CLASS_ID: Engineer - } -}) +client = hazelcast.HazelcastClient( + portable_factories={Engineer.FACTORY_ID: {Engineer.CLASS_ID: Engineer}} +) my_map = client.get_map("map") diff --git a/examples/ssl/ssl_example.py b/examples/ssl/ssl_example.py index 8728b58424..5f1fd6e0e0 100644 --- a/examples/ssl/ssl_example.py +++ b/examples/ssl/ssl_example.py @@ -4,13 +4,15 @@ # Hazelcast server should be started with SSL enabled to use SSLConfig # Start a new Hazelcast client with SSL configuration. -client = hazelcast.HazelcastClient(cluster_members=["foo.bar.com:8888"], - ssl_enabled=True, - # Absolute paths of PEM files must be given - ssl_cafile="/path/of/server.pem", - # Select the protocol used in SSL communication. - # This step is optional. Default is TLSv1_2 - ssl_protocol=SSLProtocol.TLSv1_3) +client = hazelcast.HazelcastClient( + cluster_members=["foo.bar.com:8888"], + ssl_enabled=True, + # Absolute paths of PEM files must be given + ssl_cafile="/path/of/server.pem", + # Select the protocol used in SSL communication. + # This step is optional. Default is TLSv1_2 + ssl_protocol=SSLProtocol.TLSv1_3, +) hz_map = client.get_map("ssl-map").blocking() hz_map.put("key", "value") diff --git a/examples/ssl/ssl_mutual_authentication_example.py b/examples/ssl/ssl_mutual_authentication_example.py index 09d8e0f8b7..beff2fd0ab 100644 --- a/examples/ssl/ssl_mutual_authentication_example.py +++ b/examples/ssl/ssl_mutual_authentication_example.py @@ -5,17 +5,19 @@ # SSL and mutual authentication enabled # Start a new Hazelcast client with SSL configuration. -client = hazelcast.HazelcastClient(cluster_members=["foo.bar.com:8888"], - ssl_enable=True, - # Absolute paths of PEM files must be given - ssl_cafile="/path/of/server.pem", - ssl_certfile="/path/of/client.pem", - ssl_keyfile="/path/of/client-private.pem", - # If private key is not password protected, skip the option below. - ssl_password="ssl_keyfile_password", - # Select the protocol used in SSL communication. - # This step is optional. Default is TLSv1_2 - ssl_protocol=SSLProtocol.TLSv1_3) +client = hazelcast.HazelcastClient( + cluster_members=["foo.bar.com:8888"], + ssl_enable=True, + # Absolute paths of PEM files must be given + ssl_cafile="/path/of/server.pem", + ssl_certfile="/path/of/client.pem", + ssl_keyfile="/path/of/client-private.pem", + # If private key is not password protected, skip the option below. + ssl_password="ssl_keyfile_password", + # Select the protocol used in SSL communication. + # This step is optional. Default is TLSv1_2 + ssl_protocol=SSLProtocol.TLSv1_3, +) hz_map = client.get_map("ssl-map").blocking() hz_map.put("key", "value") diff --git a/hazelcast/__init__.py b/hazelcast/__init__.py index 88a24ad859..df30f08d82 100644 --- a/hazelcast/__init__.py +++ b/hazelcast/__init__.py @@ -3,13 +3,16 @@ # Set the default handler to "hazelcast" loggers # to avoid "No handlers could be found" warnings. import logging + try: from logging import NullHandler except ImportError: + class NullHandler(logging.Handler): def emit(self, record): pass + logging.getLogger(__name__).addHandler(NullHandler()) from hazelcast.client import HazelcastClient diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..a1a1160df1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,25 @@ +[tool.black] +line-length = 100 +exclude = ''' +( + /( + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist + + | benchmarks + | hazelcast/protocol + | hazelcast/proxy + | hazelcast/serialization + | tests + )/ + | /hazelcast/(?!(__init__)\.py).+ +) +''' diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000000..6fe725e637 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,4 @@ +-r requirements-test.txt +black==20.8b1; python_version >= "3.6" +Sphinx==3.4.2; python_version >= "3.5" +sphinx-rtd-theme==0.5.1; python_version >= "3.5" diff --git a/test-requirements.txt b/requirements-test.txt similarity index 100% rename from test-requirements.txt rename to requirements-test.txt diff --git a/run-tests.ps1 b/run-tests.ps1 index c8cac5380a..d6c8c5033f 100644 --- a/run-tests.ps1 +++ b/run-tests.ps1 @@ -59,7 +59,7 @@ if(Test-Path env:HAZELCAST_ENTERPRISE_KEY){ $classpath += "hazelcast-${hazelcastVersion}.jar" } -pip install -r test-requirements.txt --user +pip install -r requirements-test.txt --user Write-Host Starting Hazelcast ... $remoteControllerApp = Start-Process -FilePath java -ArgumentList ( "-Dhazelcast.enterprise.license.key=$env:HAZELCAST_ENTERPRISE_KEY","-cp", "$classpath", "com.hazelcast.remotecontroller.Main", "--use-simple-server") -RedirectStandardOutput "rc_stdout.log" -RedirectStandardError "rc_stderr.log" -PassThru diff --git a/run-tests.sh b/run-tests.sh index 1ad58b34e6..5e88116e26 100644 --- a/run-tests.sh +++ b/run-tests.sh @@ -106,7 +106,7 @@ else echo "Starting Remote Controller ... oss ..." fi -pip install -r test-requirements.txt ${USER} --no-cache-dir +pip install -r requirements-test.txt ${USER} --no-cache-dir java -Dhazelcast.enterprise.license.key="${HAZELCAST_ENTERPRISE_KEY}" -cp ${CLASSPATH} com.hazelcast.remotecontroller.Main --use-simple-server>rc_stdout.log 2>rc_stderr.log & rcPid=$! diff --git a/setup.py b/setup.py index c674f14ca6..3c793b7cb2 100644 --- a/setup.py +++ b/setup.py @@ -6,51 +6,50 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() stats_requirements = [ - 'psutil', + "psutil", ] extras = { - 'stats': stats_requirements, + "stats": stats_requirements, } setup( - name='hazelcast-python-client', - version=__version__, - description='Hazelcast Python Client', - long_description=long_description, - url='https://github.com/hazelcast/hazelcast-python-client', - - author='Hazelcast Inc. Developers', - author_email='hazelcast@googlegroups.com', - - classifiers=[ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: Implementation :: CPython', - 'Topic :: Software Development :: Libraries :: Python Modules' - - ], - license='Apache 2.0', - keywords='hazelcast,hazelcast client,In-Memory Data Grid,Distributed Computing', - packages=find_packages(exclude=['benchmarks', 'examples', 'examples.*', 'docs', 'tests', 'tests.*']), - package_dir={'hazelcast': 'hazelcast'}, - install_requires=[], - extras_require=extras, - tests_require=['thrift', 'nose', 'coverage', 'psutil', 'mock', 'parameterized'], + name="hazelcast-python-client", + version=__version__, + description="Hazelcast Python Client", + long_description=long_description, + url="https://github.com/hazelcast/hazelcast-python-client", + author="Hazelcast Inc. Developers", + author_email="hazelcast@googlegroups.com", + classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Natural Language :: English", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + license="Apache 2.0", + keywords="hazelcast,hazelcast client,In-Memory Data Grid,Distributed Computing", + packages=find_packages( + exclude=["benchmarks", "examples", "examples.*", "docs", "docs.*", "tests", "tests.*"] + ), + package_dir={"hazelcast": "hazelcast"}, + install_requires=[], + extras_require=extras, + tests_require=["thrift", "nose", "coverage", "psutil", "mock", "parameterized"], ) diff --git a/start-rc.sh b/start-rc.sh index 368b0116a6..00413d4d3a 100644 --- a/start-rc.sh +++ b/start-rc.sh @@ -106,7 +106,7 @@ else echo "Starting Remote Controller ... oss ..." fi -pip install -r test-requirements.txt ${USER} --no-cache-dir +pip install -r requirements-test.txt ${USER} --no-cache-dir java -Dhazelcast.enterprise.license.key="${HAZELCAST_ENTERPRISE_KEY}" -cp ${CLASSPATH} com.hazelcast.remotecontroller.Main --use-simple-server rcPid=$!