8000 Merge pull request #123 from SophiaRowland/master · Christian06810/python-sasctl@5fdf080 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5fdf080

Browse files
authored
Merge pull request sassoftware#123 from SophiaRowland/master
Adding Git Example Notebook
2 parents 755da3f + 326ad3d commit 5fdf080

File tree

1 file changed

+235
-0
lines changed

1 file changed

+235
-0
lines changed
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Using GIT with SASTCLT/PZMM\n",
8+
"[Git](https://git-scm.com/) is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Many organizations use Git for tracking changes in files and collaborating on code. In this notebook, we will walk through how to leverage SASCTL/PZMM to move assets from [SAS Model Manager](https://www.sas.com/en_us/software/model-manager.html) to a Git Repository. \n",
9+
"***\n",
10+
"## Getting Started\n",
11+
"To leverage the new Git functionality, we will need a Git repository! If you don't currently use Git, you will need to download and install it. You can [download Git here](https://git-scm.com/downloads). (Want to learn more about using Git? Then I suggest checking out [this book](https://git-scm.com/book/en/v2).) Next, we need a local repository. From within Git Bash, move to where you want the local repository to be. We will initialize our local git repository using \n",
12+
"\n",
13+
"`git init`\n",
14+
"\n",
15+
"If we want to add a remote origin, such as to a repository on GitHub, we can also do that within our Git Bash\n",
16+
"\n",
17+
"`git remote add origin your-remote-repo`\n",
18+
"\n",
19+
"Now, we are ready to get started in our notebook. Let's install the necessary packages. "
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 1,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"from sasctl import Session, pzmm\n",
29+
"from pathlib import Path\n",
30+
"import getpass"
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"metadata": {},
36+
"source": [
37+
"Next, let’s specify the location of our local git repository. "
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 2,
43+
"metadata": {},
44+
"outputs": [
45+
{
46+
"name": "stdout",
47+
"output_type": "stream",
48+
"text": [
49+
]
50+
}
51+
],
52+
"source": [
53+
"path = input('Local Git Repo Path: ')\n",
54+
"gPath = Path(path)"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"Now, let’s create our session to SAS Viya. "
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": 15,
67+
"metadata": {},
68+
"outputs": [
69+
{
70+
"name": "stdout",
71+
"output_type": "stream",
72+
"text": [
73+
]
74+
}
75+
],
76+
"source": [
77+
"server = input('Server Name: ')\n",
78+
"username = input('Username: ')\n",
79+
"password = getpass.getpass('Password')\n",
80+
"sess = Session(server, username, password, protocol='http')"
81+
]
82+
},
83+
{
84+
"cell_type": "markdown",
85+
"metadata": {},
86+
"source": [
87+
"***\n",
88+
"## Git Integration\n",
89+
"Let's initialize our integration with git."
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": 8,
95+
"metadata": {},
96+
"outputs": [],
97+
"source": [
98+
"GI = pzmm.GitIntegrate()"
99+
]
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"metadata": {},
104+
"source": [
105+
"To pull a model from Model Manger into our local git repository, all we need is the Model UUID. "
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": 9,
111+
"metadata": {},
112+
"outputs": [
113+
{
114+
"name": "stdout",
115+
"output_type": "stream",
116+
"text": [
117+
]
118+
}
119+
],
120+
"source": [
121+
"modelUUID = input('Model UUID: ')\n",
122+
"GI.pullViyaModel(modelUUID, gPath)"
123+
]
124+
},
125+
{
126+
"cell_type": "markdown",
127+
"metadata": {},
128+
"source": [
129+
"We could also just pull the whole project into our local git repository using it’s name. "
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": 10,
135+
"metadata": {},
136+
"outputs": [
137+
{
138+
"name": "stdout",
139+
"output_type": "stream",
140+
"text": [
141+
]
142+
}
143+
],
144+
"source": [
145+
"projectName = input('Project Name: ')\n",
146+
"GI.pullMMProject(gPath, projectName)"
147+
]
148+
},
149+
{
150+
"cell_type": "markdown",
151+
"metadata": {},
152+
"source": [
153+
"Now, if we have a model in our local git repository, we can push it into SAS Model Manager. If we don't specify a project name, the model ends up in project whose name matches the name of our local repository folder. "
154+
]
155+
},
156+
{
157+
"cell_type": "code",
158+
"execution_count": 17,
159+
"metadata": {},
160+
"outputs": [
161+
{
162+
"name": "stdout",
163+
"output_type": "stream",
164+
"text": [
165+
]
166+
}
167+
],
168+
"source": [
169+
"localModel = input('Local Model: ')\n",
170+
"GI.pushGitModel(gPath / localModel)"
171+
]
172+
},
173+
{
174+
"cell_type": "markdown",
175+
"metadata": {},
176+
"source": [
177+
"Finally, let’s get our local repository synced with our remote repository. To pull all changes from our remote repo into our local repo we can issue a pull. "
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": 19,
183+
"metadata": {},
184+
"outputs": [],
185+
"source": [
186+
"GI.gitRepoPull(gPath)"
187+
]
188+
},
189+
{
190+
"cell_type": "markdown",
191+
"metadata": {},
192+
"source": [
193+
"We can also push our changes from our local repository back up to our remote repository. "
194+
]
195+
},
196+
{
197+
"cell_type": "code",
198+
"execution_count": 20,
199+
"metadata": {},
200+
"outputs": [],
201+
"source": [
202+
"GI.gitRepoPush(gPath, 'Pushing Local Changes to Remote Repo')"
203+
]
204+
},
205+
{
206+
"cell_type": "markdown",
207+
"metadata": {},
208+
"source": [
209+
"We can now move models and assets between a local git repo, a remote git repo, and SAS Model Manager with ease! Organizations can continue to leverage git for managing source code and for utilizing GitOps processes, but they can seamlessly integrate with SAS Model Manager for the governance, care, monitoring, and management that healthy models need. \n",
210+
"*** "
211+
]
212+
}
213+
],
214+
"metadata": {
215+
"kernelspec": {
216+
"display_name": "Python 3",
217+
"language": "python",
218+
"name": "python3"
219+
},
220+
"language_info": {
221+
"codemirror_mode": {
222+
"name": "ipython",
223+
"version": 3
224+
},
225+
"file_extension": ".py",
226+
"mimetype": "text/x-python",
227+
"name": "python",
228+
"nbconvert_exporter": "python",
229+
"pygments_lexer": "ipython3",
230+
"version": "3.7.1"
231+
}
232+
},
233+
"nbformat": 4,
234+
"nbformat_minor": 2
235+
}

0 commit comments

Comments
 (0)
0