Skip to content

Commit

Permalink
Attempting to fix python client hopefully for the last time
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaSBrown committed Aug 24, 2023
1 parent b9d5549 commit 5f25219
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cmake/Version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ set(DATAFED_AUTHZ_PATCH 0)

set(DATAFED_PYTHON_CLIENT_MAJOR 2)
set(DATAFED_PYTHON_CLIENT_MINOR 0)
set(DATAFED_PYTHON_CLIENT_PATCH 0)
set(DATAFED_PYTHON_CLIENT_PATCH 3)
7 changes: 3 additions & 4 deletions python/datafed_pkg/datafed/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def run():
release_version += f"{Version_pb2.DATAFED_RELEASE_DAY}."
release_version += f"{Version_pb2.DATAFED_RELEASE_HOUR}."
release_version += f"{Version_pb2.DATAFED_RELEASE_MINUTE}"
_print_msg(1, "Welcome to DataFed CLI, version {}".format(__version__))
_print_msg(1, f"Welcome to DataFed CLI, version {VERSION.__version__}")
_print_msg(
1, " Release, version {}".format(release_version)
)
Expand Down Expand Up @@ -2201,12 +2201,11 @@ def _help_cli(ctx, command):
"""

if not command:
click.echo("DataFed _cli, version {}\n".format(version))
click.echo("DataFed _cli, version {}\n".format(VERSION.__version__))
click.echo(ctx.parent.get_help())
else:
first = True
for c in command:
# print( c )
if first:
first = False
subcmd = _cli.get_command(_cli, c)
Expand Down Expand Up @@ -3038,7 +3037,7 @@ def _initialize(opts):
# print("_initialize, opts:", opts )

if "version" in opts and opts["version"]:
click.echo(version)
click.echo(VERSION.__version__)
_interactive = False
raise SystemExit()

Expand Down
54 changes: 25 additions & 29 deletions python/datafed_pkg/datafed/MessageLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def __init__(
else:
self._keys_valid = True
self._keys_loaded = True
print
except:
pub, priv = zmq.curve_keypair()
_client_pub_key = pub.decode("utf-8")
Expand All @@ -183,45 +184,40 @@ def __init__(
self._conn.registerProtocol(anon)
self._conn.registerProtocol(auth)

# Check for compatible protocol versions
reply, mt = self.sendRecv(anon.VersionRequest(), 10000)
if reply is None:
raise Exception("Timeout waiting for server connection.")

if reply.api_major != Version_pb2.DATAFED_COMMON_PROTOCOL_API_MAJOR:
raise Exception(
"Incompatible server api detected {}.{}.{}".format(
reply.api_major, reply.api_minor, reply.api_patch
)
)

# Make a request to pypi
package_name = 'datafed' # Replace with the package name you want to check
latest_version_on_pypi = get_latest_version(package_name)

if latest_version_on_pypi:
pypi_major, pypi_minor, pypi_patch = latest_version_on_pypi.split('.')
major, minor, patch = VERSION.__version__.split('.')
if pypi_major != major:
print("A new major release of the datafed python client is "
"available it is recommended that you update the datafed"
" python client.")
print(f"The current version is: {VERSION.__version__}")
print(f" The latest version is: {latest_version_on_pypi}")
elif pypi_minor > minor:
print("A new minor release of the datafed python client is "
"available.")
print(f"The current version is: {VERSION.__version__}")
print(f" The latest version is: {latest_version_on_pypi}")
elif pypi_patch > patch:
print("A new patch release of the datafed python client is "
"available.")
print(f"The current version is: {VERSION.__version__}")
print(f" The latest version is: {latest_version_on_pypi}")
self.new_client_avail = latest_version_on_pypi

if pypi_major != major or pypi_minor > minor or pypi_patch > patch:
self.new_client_avail = latest_version_on_pypi
else:
self.new_client_avail = False
else:
self.new_client_avail = False

# Check for compatible protocol versions
reply, mt = self.sendRecv(anon.VersionRequest(), 10000)
if reply is None:
raise Exception("Timeout waiting for server connection. Make sure"
"the right ports are open.")

if reply.api_major != Version_pb2.DATAFED_COMMON_PROTOCOL_API_MAJOR:
error_msg = ("Incompatible server api detected {}.{}.{} consider "
"upgrading the datafed python client.".format(
reply.api_major, reply.api_minor, reply.api_patch
))
if self.new_client_avail:
error_msg +=("\nConsider upgrading the datafed python client as"
f" a new version is available {latest_version_on_pypi} that"
" should be compatible with the API.")
raise Exception(

)

if client_token:
self.manualAuthByToken(client_token)
else:
Expand Down
4 changes: 0 additions & 4 deletions python/datafed_pkg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

from datafed.VERSION import __version__

# read the contents of VERSION file
# with open(path.join(this_directory, 'VERSION'), encoding='utf-8') as f:
# version = f.read()

setuptools.setup(
name="datafed",
version=__version__,
Expand Down

0 comments on commit 5f25219

Please sign in to comment.