def _api_key(): if _is_pip_installed_bentoml(): # Use prod amplitude key return '1ad6ee0e81b9666761aebd55955bbd3a' else: # Use dev amplitude key return '7f65f2446427226eb86f6adfacbbf47a'
def _bundle_local_bentoml_if_installed_from_source(target_path): """ if bentoml is installed in editor mode(pip install -e), this will build a source distribution with the local bentoml fork and add it to saved BentoService bundle path under bundled_pip_dependencies directory """ # Find bentoml module path (module_location, ) = importlib.util.find_spec('bentoml').submodule_search_locations bentoml_setup_py = os.path.abspath( os.path.join(module_location, '..', 'setup.py')) # this is for BentoML developer to create BentoService containing custom develop # branches of BentoML library, it is True only when BentoML module is installed in # development mode via "pip install --editable ." if not _is_pip_installed_bentoml() and os.path.isfile(bentoml_setup_py): logger.info( "Detected non-PyPI-released BentoML installed, copying local BentoML module" "files to target saved bundle path..") # Create tmp directory inside bentoml module for storing the bundled # targz file. Since dist-dir can only be inside of the module directory bundle_dir_name = '__bentoml_tmp_sdist_build' source_dir = os.path.abspath( os.path.join(module_location, '..', bundle_dir_name)) if os.path.isdir(source_dir): shutil.rmtree(source_dir, ignore_errors=True) os.mkdir(source_dir) from setuptools import sandbox sandbox.run_setup( bentoml_setup_py, [ '-q', 'sdist', '--format', 'gztar', '--dist-dir', bundle_dir_name ], ) # copy the generated targz to saved bundle directory and remove it from # bentoml module directory shutil.copytree(source_dir, target_path) # clean up sdist build files shutil.rmtree(source_dir)
from bentoml import __version__ as BENTOML_VERSION logger = logging.getLogger(__name__) AMPLITUDE_URL = "https://api.amplitude.com/httpapi" PLATFORM = platform.platform() PY_VERSION = "{major}.{minor}.{micro}".format( major=sys.version_info.major, minor=sys.version_info.minor, micro=sys.version_info.micro, ) SESSION_ID = str(uuid.uuid4()) # uuid that marks current python session # Use dev amplitude key API_KEY = '7f65f2446427226eb86f6adfacbbf47a' if _is_pip_installed_bentoml(): # Use prod amplitude key API_KEY = '1ad6ee0e81b9666761aebd55955bbd3a' def _send_amplitude_event(event_type, event_properties): """Send event to amplitude https://developers.amplitude.com/?objc--ios#http-api-v2-request-format """ event = [{ "event_type": event_type, "user_id": SESSION_ID, "event_properties": event_properties, "ip": "$remote", }] event_data = {"api_key": API_KEY, "event": json.dumps(event)}