Skip to content

Commit

Permalink
Merge pull request #12 from AIAScience/me/remove-server-host-param
Browse files Browse the repository at this point in the history
Me/remove server host param
  • Loading branch information
iver56 committed Aug 14, 2019
2 parents 32fc011 + 09bfc85 commit 7a85006
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ deploy:
provider: pypi
distributions: sdist bdist_wheel
user: aiascience
server: https://test.pypi.org/legacy/
password:
secure: HS06Jj+E0gzN+EUSt1T9+5DfB8KhCTKA8fRCUvPnTl8C43T+3O/p5IuFYs/8R7nbkh0/iju8ph0Li8UY2pqTpJ1UamG2ZSy03+wBR5uoE5Br/5J58/36mwnH/OOoq0Y+xc4fosTaNPklsFmeV8ZjN9j2EZ+bCNjiI7pKM1brHpO++PZKmwU637IvovFYvbbW0PgpNuPjJbr+ES7EazqXbeTqTTJu8uCQ9vF130bhucii5Lk2bOezR6p5R1+V44RelhbbfjJcRveH+SS5OaTayK8gZ38unBlsjumX7ise8DNtC47mXsaN5pcfdbqvTorAYkJ0S9TlSkvAUWIyC9iQDLftlZXGMOwBkVTNnoAHVWjd96YBzHjYgbql54JLN971Hp/O/cfwHCjBjInJgqIEbEwdXJVs7VZJc4ZglNwDuTVkatOC4A+NML9uy9Nyrp6zcLZPSaMjRrCEnkuECA1YnYprBSomY6FJLDszHGVK08W9cB6dOmg0O6uJ9PR/ih6Y2M7/jkpLm6jdYFwUbGaknUE0cZqPNRqGewvC+jdUyyXncK+thPLJgCiRJz7uPWvJCu99zc7znGxTfvSTx6BS2AE70YwAhhQDMvhMba7QTLrsGbKXQZGhc8bKwm8Wa1R2nRY1dj4CLlZkCemTE1Q6xpf4alYLEkDBO84AA5hOuIs=
on:
Expand Down
25 changes: 17 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,31 @@ mflux-ai



Open source code for the mflux-ai python package
Official the mflux-ai python library.



* Free software: BSD license
* Documentation: https://mflux-ai.readthedocs.io.


Features
--------
- acquire and set environment variables required by mflux-server
- cache the environment variables


Quickstart
----------
Install mflux-ai

pip install mflux-ai

Import mflux_ai

Import mflux-ai

mflux_ai.set_env_vars(token="9s9kQ0D86wWKUHdPMj0HHA")

* TODO

Credits
-------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
12 changes: 11 additions & 1 deletion mflux_ai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# -*- coding: utf-8 -*-

from mflux_ai.mflux_ai import MfluxClient
from mflux_ai.mflux_ai import *
"""Top-level package for mflux-ai."""

__author__ = """Meklit Elfiyos Dekita"""
__email__ = "me@aiascience.com"
__version__ = "0.1.0"


def set_env_vars(token):
try:
MfluxClient(token=token).set_env_vars()
return True
except Exception as e:
print("couldn't connect to mflux server :", e)

9 changes: 9 additions & 0 deletions mflux_ai/mflux_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def get_env_vars_from_cache_file(self):
except FileNotFoundError:
print("Could not open file:", self.cache_file_name)

def set_env_vars_from_cache_file(self):
try:
with open(self.cache_file_name, "r") as cache_file:
self.variables = json.load(cache_file)
self.set_env_vars()

except FileNotFoundError:
print("Could not open file:", self.cache_file_name)

def save_cache_to_file(self):
if self.variables:
try:
Expand Down
14 changes: 6 additions & 8 deletions tests/test_mflux_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import os

import responses
from mflux_ai.mflux_ai import MfluxClient

import mflux_ai
from mflux_ai import MfluxClient, SERVER_HOST


@responses.activate
Expand All @@ -19,20 +21,16 @@ def test_mflux_ai():

responses.add(
responses.Response(
method="GET",
url="http://mflux-server.com/api/env_vars/",
json=content,
status=200,
method="GET", url=SERVER_HOST + "/api/env_vars/", json=content, status=200
)
)

mflux_client = MfluxClient(
token="thisshouldbevalidtoken", server_host="http://mflux-server.com"
)
mflux_client = MfluxClient(token="thisshouldbevalidtoken")

assert mflux_client.get_env_vars() == content
assert mflux_client.set_env_vars() == True
assert os.environ.get("MLFLOW_TRACKING_URI") == content["mlflow_server"]
assert os.environ.get("MLFLOW_S3_ENDPOINT_URL") == content["minio_server"]
assert os.environ.get("AWS_SECRET_ACCESS_KEY") == content["minio_secret_key"]
assert os.environ.get("AWS_ACCESS_KEY_ID") == content["minio_access_key"]
assert mflux_ai.set_env_vars(token="thisshouldbevalidtoken") == True

0 comments on commit 7a85006

Please sign in to comment.