Skip to content

Commit

Permalink
Merge pull request #9 from IBM/v0.3.0.2b
Browse files Browse the repository at this point in the history
V0.3.0.2b
  • Loading branch information
victorterpstra authored Apr 14, 2020
2 parents a280025 + e377150 commit 85efa51
Show file tree
Hide file tree
Showing 39 changed files with 1,305 additions and 652 deletions.
16 changes: 12 additions & 4 deletions InstallationReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ with open(file_path, 'rb') as f:
project = Project.access()
project.save_data(file_name=file_name, data=f, overwrite=True)
```
Once it is in the data assets, the project can be exported and moved to the air-gapped system
Once it is in the data assets, the project can be exported and moved to the air-gapped system.

Next, set the environment customization to:
In CPDv2.5 it is not possible to configure the environment customization so that it loads from a file in data assets.
So, you need to run a pip install in a notebook.
```
- pip:
- dse-do-utils --no-index --find-links=/project_data/data_asset/dse_do_utils-0.3.0.0.tar.gz
!pip install --target /project_data/data_asset/ /project_data/data_asset/dse_do_utils-0.3.0.0-py3-none-any.whl
```
By installing the package in `/project_data/data_asset/`, the installation will be permanent.
But you do need to add this folder to the Python path explicitly:
```
import sys
for path in ['/project_data/data_asset/']:
if path not in sys.path:
sys.path.insert(0, path)
```

### Installation as package in JupyterLab
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Can be subclassed and stored in a script to be able to share code between multip
Also contains some functions to create dvars and export .lp files.
4. ScenarioPicker. Interactively pick an existing scenario from a drop-down menu in a notebook. Typically used in visualization notebooks.
5. MapManager. For creating map visualizations using Folium.
6. DeployedDOModel. Interfacing from Python to a deployed DO model.
6. DOModelExporter. To export DO Models in CPDv2.5.

## Installation (CPDv2.5)
(For Cloud Pak for Data v2.5)
Expand Down Expand Up @@ -47,14 +47,8 @@ This downloads the package as a wheel/zip and puts it in the data assets
```
!pip download dse-do-utils -d /project_data/data_asset/
```
Then move the wheel/zip to the Data Assets (see the `InstallationReadMe.md` for more details)
Next, set the environment customization to:
```
- pip:
- dse-do-utils --no-index --find-links=/project_data/data_asset/dse_do_utils-0.3.0.0.tar.gz
```

See the `InstallationReadMe.md` for many more details on installation and usage in other cases.
Then move the wheel/zip to the Data Assets.
See the `InstallationReadMe.md` for more details on installation and usage in other cases.

## Import
Then import the required classes from `dse_do_utils`:
Expand Down
Binary file modified docs/doc_build/doctrees/dse_do_utils.doctree
Binary file not shown.
Binary file modified docs/doc_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/doc_build/doctrees/readme_link.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/doc_build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 18805d56ab22e017ff794e949f9f600f
config: a4807da18cd21515904f1b5ead8dcaca
tags: 645f666f9bcd5a90fca523b33c5a78b7
9 changes: 5 additions & 4 deletions docs/doc_build/html/_modules/dse_do_utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>dse_do_utils &mdash; DSE DO Utils 0.3.0.1 documentation</title>
<title>dse_do_utils &mdash; DSE DO Utils 0.3.0.2b documentation</title>



Expand All @@ -23,7 +23,7 @@
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'0.3.0.1',
VERSION:'0.3.0.2b',
LANGUAGE:'None',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
Expand Down Expand Up @@ -67,7 +67,7 @@


<div class="version">
0.3.0.1
0.3.0.2b
</div>


Expand Down Expand Up @@ -174,7 +174,8 @@ <h1>Source code for dse_do_utils</h1><div class="highlight"><pre>


<div class="viewcode-block" id="module_reload"><a class="viewcode-back" href="../dse_do_utils.html#dse_do_utils.module_reload">[docs]</a><span class="k">def</span> <span class="nf">module_reload</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;Reloads all component modules. Use when you want to force a reload of this module with imp.reload().</span>
<span class="sd">&quot;&quot;&quot;DEPRECATED. Requires updates to Python 3.6</span>
<span class="sd"> Reloads all component modules. Use when you want to force a reload of this module with imp.reload().</span>

<span class="sd"> This avoids having to code somewhat complex reloading logic in the notebook that is using this module.</span>

Expand Down
278 changes: 278 additions & 0 deletions docs/doc_build/html/_modules/dse_do_utils/cpd25utilities.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@


<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>dse_do_utils.cpd25utilities &mdash; DSE DO Utils 0.3.0.2b documentation</title>








<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>


<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../',
VERSION:'0.3.0.2b',
LANGUAGE:'None',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>

<script type="text/javascript" src="../../_static/js/theme.js"></script>




<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>

<body class="wy-body-for-nav">


<div class="wy-grid-for-nav">

<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >



<a href="../../index.html" class="icon icon-home"> DSE DO Utils



</a>




<div class="version">
0.3.0.2b
</div>




<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>


</div>

<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">






<p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../readme_link.html">Read me</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../readme_link.html#dse-do-utils">DSE_DO_Utils</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">Modules</a></li>
</ul>



</div>
</div>
</nav>

<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">


<nav class="wy-nav-top" aria-label="top navigation">

<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">DSE DO Utils</a>

</nav>


<div class="wy-nav-content">

<div class="rst-content">

















<div role="navigation" aria-label="breadcrumbs navigation">

<ul class="wy-breadcrumbs">

<li><a href="../../index.html">Docs</a> &raquo;</li>

<li><a href="../index.html">Module code</a> &raquo;</li>

<li><a href="../dse_do_utils.html">dse_do_utils</a> &raquo;</li>

<li>dse_do_utils.cpd25utilities</li>


<li class="wy-breadcrumbs-aside">

</li>

</ul>


<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">

<h1>Source code for dse_do_utils.cpd25utilities</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright IBM All Rights Reserved.</span>
<span class="c1"># SPDX-License-Identifier: Apache-2.0</span>

<span class="c1"># -----------------------------------------------------------------------------------</span>
<span class="c1"># -----------------------------------------------------------------------------------</span>
<span class="c1"># Utility functions for CPD v2.5</span>
<span class="c1"># -----------------------------------------------------------------------------------</span>
<span class="c1"># -----------------------------------------------------------------------------------</span>

<span class="kn">import</span> <span class="nn">os</span>

<div class="viewcode-block" id="add_file_path_as_data_asset_cpd25"><a class="viewcode-back" href="../../dse_do_utils.html#dse_do_utils.cpd25utilities.add_file_path_as_data_asset_cpd25">[docs]</a><span class="k">def</span> <span class="nf">add_file_path_as_data_asset_cpd25</span><span class="p">(</span><span class="n">file_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">asset_name</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;Add a data file to the Watson Studio project.</span>
<span class="sd"> Applies to CPDv2.5. Works for any file. Allows the file to be viewed and downloaded from Watson Studio UI.</span>
<span class="sd"> Needs to be called after the file has been saved regularly in the file system.</span>
<span class="sd"> Typically, that would be in `/project_data/data_asset/`.</span>
<span class="sd"> Ensures the file is visible in the Data Assets of the Watson Studio UI.</span>

<span class="sd"> Args:</span>
<span class="sd"> file_path (str): full file path, including the file name and extension</span>
<span class="sd"> asset_name (str): name of data asset. Default is None. If None, the asset_name will be extracted from the file_path.</span>

<span class="sd"> Usage::</span>

<span class="sd"> # Write some file as an example:</span>
<span class="sd"> file_path = &#39;/project_data/data_asset/myfile.csv&#39;</span>
<span class="sd"> with open(file_path, &#39;w+&#39;) as f:</span>
<span class="sd"> f.write(&quot;Hello World&quot;)</span>
<span class="sd"> # Add file as a data asset:</span>
<span class="sd"> add_file_as_data_asset_cpd25(file_path)</span>

<span class="sd"> Beware that the same data now exists in 2 different places:</span>
<span class="sd"> * In the Cloud Object Storage (COS)</span>
<span class="sd"> * As a file in `/project_data/data_asset/`</span>
<span class="sd"> Changing any of the 2 independently can cause inconsistencies.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">asset_name</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">asset_name</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">file_path</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">project_lib</span> <span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">access</span><span class="p">()</span>
<span class="n">project</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">file_name</span><span class="o">=</span><span class="n">asset_name</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">f</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div>


<div class="viewcode-block" id="add_file_as_data_asset_cpd25"><a class="viewcode-back" href="../../dse_do_utils.html#dse_do_utils.cpd25utilities.add_file_as_data_asset_cpd25">[docs]</a><span class="k">def</span> <span class="nf">add_file_as_data_asset_cpd25</span><span class="p">(</span><span class="n">file_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Adds a file located in &#39;/project_data/data_asset/&#39; as a Data Asset to the Watson Studio project.</span>
<span class="sd"> So that it appears in the UI and can be exported.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">file_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;/project_data/data_asset/&#39;</span><span class="p">,</span> <span class="n">file_name</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">project_lib</span> <span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">access</span><span class="p">()</span>
<span class="n">project</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">file_name</span><span class="o">=</span><span class="n">file_name</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">f</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div>


<div class="viewcode-block" id="write_data_asset_as_file_cpd25"><a class="viewcode-back" href="../../dse_do_utils.html#dse_do_utils.cpd25utilities.write_data_asset_as_file_cpd25">[docs]</a><span class="k">def</span> <span class="nf">write_data_asset_as_file_cpd25</span><span class="p">(</span><span class="n">asset_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">path</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">&#39;/project_data/data_asset/&#39;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;Writes a named data asset to file.</span>
<span class="sd"> Assumes a data asset with `asset_name` exists.</span>
<span class="sd"> Makes the file accessable for things like:</span>
<span class="sd"> * Load from disk</span>
<span class="sd"> * Pip install</span>
<span class="sd"> * Module import</span>

<span class="sd"> Args:</span>
<span class="sd"> asset_name (str): name of the asset</span>
<span class="sd"> path (str, Optional): Default is &#39;/project_data/data_asset/&#39;. Use path=&#39;&#39; for current directory.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">project_lib</span> <span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">access</span><span class="p">()</span>
<span class="n">file_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">asset_name</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="s2">&quot;wb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">project</span><span class="o">.</span><span class="n">get_file</span><span class="p">(</span><span class="n">asset_name</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
<span class="k">return</span> <span class="n">file_path</span></div>
</pre></div>

</div>

</div>
<footer>


<hr/>

<div role="contentinfo">
<p>
&copy; Copyright 2019, Victor Terpstra

</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.

</footer>

</div>
</div>

</section>

</div>



<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>






</body>
</html>
Loading

0 comments on commit 85efa51

Please sign in to comment.