Skip to content

Commit 3c8e1a1

Browse files
authored
Merge pull request #150 from rstudio/mbh-docs-touchup
Update docs and generate API docs
2 parents a0d58fa + 6cd3515 commit 3c8e1a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+214
-135
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ jobs:
109109
virtualenvs-ubuntu-latest-py3.8-
110110
- run: pip install -U pipenv pip
111111
- run: make deps
112-
- run: pipenv run pip install -U 'SecretStorage>=3'
113112
- run: make dist
114113
id: create_dist
115114
- uses: actions/upload-artifact@v2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
/notebooks*/
1717
/rsconnect/version.py
1818
htmlcov
19-
rsconnect/tests/testdata/**/rsconnect-python/
19+
/tests/testdata/**/rsconnect-python/
20+
/docs/docs/index.md

README.md

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
# The rsconnect-python Library
1+
# The rsconnect-python CLI and library
22

3-
This package is a library used by the [`rsconnect-jupyter`](https://github.com/rstudio/rsconnect-jupyter)
4-
package to deploy Jupyter notebooks to RStudio Connect. It contains a full deployment
5-
API so can also be used by other Python-based deployment tools. Other types of content
6-
supported by RStudio Connect may also be deployed by this package, including WSGi-style
7-
APIs, as well as Dash, Streamlit, and Bokeh applications.
3+
This package provides both a CLI (command-line interface) and a library for interacting
4+
with and deploying to RStudio Connect. The library is also used by the
5+
[`rsconnect-jupyter`](https://github.com/rstudio/rsconnect-jupyter) package to deploy
6+
Jupyter notebooks via the Jupyter web console. Many types of content supported by RStudio
7+
Connect may be deployed by this package, including WSGI-style APIs, Dash, Streamlit, and
8+
Bokeh applications.
89

9-
> **Important:** Streamlit and Bokeh support in RStudio Connect are currently in
10-
> beta. You should not rely on them for deployments in production.
10+
> **Important:** Bokeh support in RStudio Connect is currently in beta.
1111
12-
A command-line deployment tool is also provided that can be used directly to deploy
13-
Jupyter notebooks, Python APIs and apps. Content types not directly supported by the
14-
CLI can also be deployed if they include a prepared `manifest.json` file. See
15-
["Deploying R or Other Content"](#deploying-r-or-other-content) for details.
12+
Content types not directly supported by the CLI may also be deployed if they include a
13+
prepared `manifest.json` file. See ["Deploying R or Other
14+
Content"](#deploying-r-or-other-content) for details.
1615

1716
## Deploying Python Content to RStudio Connect
1817

19-
In addition to various kinds of R content, RStudio Connect also supports the deployment
20-
of Jupyter notebooks, Python APIs (such as `flask`-based) and apps (such as Dash, Streamlit,
21-
and Bokeh apps). Much like deploying R content to RStudio Connect, there are some caveats to
22-
understand when replicating your environment on the RStudio Connect server:
18+
RStudio Connect supports the deployment of Jupyter notebooks, Python APIs (such as
19+
`flask`-based) and apps (such as Dash, Streamlit, and Bokeh apps). Much like deploying R
20+
content to RStudio Connect, there are some caveats to understand when replicating your
21+
environment on the RStudio Connect server:
2322

24-
RStudio Connect insists on matching <MAJOR.MINOR> versions of Python. For example,
25-
a server with only Python 3.5 installed will fail to match content deployed with
26-
Python 3.4. Your administrator may also enable exact Python version matching which
23+
RStudio Connect insists on matching `<MAJOR.MINOR>` versions of Python. For example,
24+
a server with only Python 3.8 installed will fail to match content deployed with
25+
Python 3.7. Your administrator may also enable exact Python version matching which
2726
will be stricter and require matching major, minor, and patch versions. For more
2827
information see the [RStudio Connect Admin Guide chapter titled Python Version
2928
Matching](https://docs.rstudio.com/connect/admin/python.html#python-version-matching).
3029

3130
### Installation
3231

33-
To install `rsconnect-python` from this repository:
32+
To install `rsconnect-python` from PYPI, you may use any python package manager such as
33+
pip:
3434

3535
```bash
36-
git clone https://github.com/rstudio/rsconnect-python
37-
cd rsconnect-python
38-
python setup.py install
36+
pip install rsconnect-python
3937
```
4038

41-
To install the current version directly from pip:
39+
You may also build and install a wheel directly from a repository clone:
4240

4341
```bash
44-
pip install rsconnect-python
42+
git clone https://github.com/rstudio/rsconnect-python.git
43+
cd rsconnect-python
44+
pip install pipenv
45+
make deps dist
46+
pip install ./dist/rsconnect_python-*.whl
4547
```
4648

4749
### Using the rsconnect CLI
@@ -50,9 +52,9 @@ Here's an example command that deploys a Jupyter notebook to RStudio Connect.
5052

5153
```bash
5254
rsconnect deploy notebook \
53-
--server https://my.connect.server:3939 \
54-
--api-key my-api-key \
55-
my-notebook.ipynb
55+
--server https://connect.example.org:3939 \
56+
--api-key my-api-key \
57+
my-notebook.ipynb
5658
```
5759

5860
> **Note:** The examples here use long command line options, but there are short
@@ -94,27 +96,27 @@ compinit
9496
### Managing Server Information
9597

9698
The information used by the `rsconnect` command to communicate with an RStudio Connect
97-
server can be tedious to repeat on every command. To help, the CLI supports the idea
99+
server can be tedious to repeat on every command. To help, the CLI supports the idea
98100
of saving this information, making it usable by a simple nickname.
99101

100102
> **Important:** One item of information saved is the API key used to authenticate with
101-
> RStudio Connect. Although the file where this information is saved is marked as
103+
> RStudio Connect. Although the file where this information is saved is marked as
102104
> accessible by the owner only, it's important to remember that the key is present
103105
> in the file as plain text so care must be taken to prevent any unauthorized access
104106
> to the server information file.
105107
106108
#### TLS Support and RStudio Connect
107109

108110
Usually, an RStudio Connect server will be set up to be accessed in a secure manner,
109-
using the `https` protocol rather than simple `http`. If RStudio Connect is set up
111+
using the `https` protocol rather than simple `http`. If RStudio Connect is set up
110112
with a self-signed certificate, you will need to include the `--insecure` flag on
111-
all commands. If RStudio Connect is set up to require a client-side certificate chain,
113+
all commands. If RStudio Connect is set up to require a client-side certificate chain,
112114
you will need to include the `--cacert` option that points to your certificate
113-
authority (CA) trusted certificates file. Both of these options can be saved along
115+
authority (CA) trusted certificates file. Both of these options can be saved along
114116
with the URL and API Key for a server.
115117

116118
> **Note:** When certificate information is saved for the server, the specified file
117-
> is read and its _contents_ are saved under the server's nickname. If the CA file's
119+
> is read and its _contents_ are saved under the server's nickname. If the CA file's
118120
> contents are ever changed, you will need to add the server information again.
119121
120122
See the [Network Options](#network-options) section for more details about these options.
@@ -125,13 +127,13 @@ Use the `add` command to store information about an RStudio Connect server:
125127

126128
```bash
127129
rsconnect add \
128-
--api-key my-api-key \
129-
--server https://my.connect.server:3939 \
130-
--name myserver
130+
--api-key my-api-key \
131+
--server https://connect.example.org:3939 \
132+
--name myserver
131133
```
132134

133135
> **Note:** The `rsconnect` CLI will verify that the serve URL and API key
134-
> are valid. If either is found not to be, no information will be saved.
136+
> are valid. If either is found not to be, no information will be saved.
135137
136138
If any of the access information for the server changes, simply rerun the
137139
`add` command with the new information and it will replace the original
@@ -173,14 +175,14 @@ You can verify that a URL refers to a running instance of RStudio Connect by usi
173175
the `details` command:
174176

175177
```bash
176-
rsconnect details --server https://my.connect.server:3939
178+
rsconnect details --server https://connect.example.org:3939
177179
```
178180

179181
In this form, `rsconnect` will only tell you whether the URL given does, in fact, refer
180-
to a running RStudio Connect instance. If you include a valid API key:
182+
to a running RStudio Connect instance. If you include a valid API key:
181183

182184
```bash
183-
rsconnect details --server https://my.connect.server:3939 --api-key my-api-key
185+
rsconnect details --server https://connect.example.org:3939 --api-key my-api-key
184186
```
185187

186188
the tool will provide the version of RStudio Connect (if the server is configured to
@@ -244,7 +246,7 @@ rsconnect deploy notebook --static my-notebook.ipynb
244246
### Creating a Manifest for Future Deployment
245247

246248
You can create a `manifest.json` file for a Jupyter Notebook, then use that manifest
247-
in a later deployment. Use the `write-manifest` command to do this.
249+
in a later deployment. Use the `write-manifest` command to do this.
248250

249251
The `write-manifest` command will also create a `requirements.txt` file, if it does
250252
not already exist or the `--force-generate` option is specified. It will contain the
@@ -262,8 +264,8 @@ rsconnect write-manifest notebook my-notebook.ipynb
262264
263265
### API/Application Deployment Options
264266

265-
There are a variety of options available to you when deploying a Python WSGi-style API,
266-
Dash, Streamlit, or Bokeh application. All options below apply equally to `api`,
267+
There are a variety of options available to you when deploying a Python WSGI-style API,
268+
Dash, Streamlit, or Bokeh application. All options below apply equally to `api`,
267269
`dash`, `streamlit`, and `bokeh` sub-commands.
268270

269271
#### Including Extra Files
@@ -278,17 +280,17 @@ rsconnect deploy api flask-api/ data.csv
278280

279281
Since deploying an API or application starts at a directory level, there will be times
280282
when some files under that directory subtree should not be included in the deployment
281-
or manifest. Use the `--exclude` option to specify files to exclude. An exclusion may
283+
or manifest. Use the `--exclude` option to specify files to exclude. An exclusion may
282284
be a glob pattern and the `--exclude` option may be repeated.
283285

284286
```bash
285287
rsconnect deploy dash --exclude "workfiles/*" dash-app/ data.csv
286288
```
287289

288290
You should always quote a glob pattern so that it will be passed to `rsconnect` as-is
289-
instead of letting the shell expand it. If a file is specifically listed as an extra
291+
instead of letting the shell expand it. If a file is specifically listed as an extra
290292
file that also matches an exclusion pattern, the file will still be included in the
291-
deployment (i.e., extra files trumps exclusions).
293+
deployment (i.e., extra files take precedence).
292294

293295
#### Package Dependencies
294296

@@ -316,7 +318,7 @@ ensuring that you use the same Python that you use to run your API or applicatio
316318
### Creating a Manifest for Future Deployment
317319

318320
You can create a `manifest.json` file for an API or application, then use that
319-
manifest in a later deployment. Use the `write-manifest` command to do this.
321+
manifest in a later deployment. Use the `write-manifest` command to do this.
320322

321323
The `write-manifest` command will also create a `requirements.txt` file, if it does
322324
not already exist or the `--force-generate` option is specified. It will contain
@@ -392,7 +394,7 @@ is trusted by your Jupyter Notebook server, API client or user's browser, then y
392394
don't need to do anything special. You can test this out with the `details` command:
393395

394396
```bash
395-
rsconnect details --api-key my-api-key --server https://my.connect.server:3939
397+
rsconnect details --api-key my-api-key --server https://connect.example.org:3939
396398
```
397399

398400
If this fails with a TLS Certificate Validation error, then you have two options.
@@ -401,22 +403,22 @@ If this fails with a TLS Certificate Validation error, then you have two options
401403
RStudio Connect server. This will enable `rsconnect` to securely validate the
402404
server's TLS certificate.
403405

404-
```bash
405-
rsconnect details \
406-
--api-key my-api-key \
407-
--server https://my.connect.server:3939 \
408-
--cacert /path/to/certificate.pem
409-
```
406+
```bash
407+
rsconnect details \
408+
--api-key my-api-key \
409+
--server https://connect.example.org:3939 \
410+
--cacert /path/to/certificate.pem
411+
```
410412

411413
* RStudio Connect is in "insecure mode". This disables TLS certificate verification,
412414
which results in a less secure connection.
413415

414-
```bash
415-
rsconnect add \
416-
--api-key my-api-key \
417-
--server https://my.connect.server:3939 \
418-
--insecure
419-
```
416+
```bash
417+
rsconnect add \
418+
--api-key my-api-key \
419+
--server https://connect.example.org:3939 \
420+
--insecure
421+
```
420422

421423
Once you work out the combination of options that allow you to successfully work with
422424
an instance of RStudio Connect, you'll probably want to use the `add` command to have

docs/Dockerfile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ MAINTAINER RStudio Connect <[email protected]>
66
ENV LC_ALL C.UTF-8
77
ENV LANG C.UTF-8
88

9-
RUN pip3 install \
10-
mkdocs==1.0.4 \
11-
mkdocs-material==4.5.1 \
12-
mkdocs-macros-plugin==0.2.4 \
13-
mkdocs-exclude==1.0.2 \
14-
markdown==3.1.1 \
15-
markdown-include==0.5.1 \
16-
pymdown-extensions==6.2 \
17-
Pygments==2.5.2
9+
COPY requirements.txt requirements.txt
10+
RUN pip3 install -r requirements.txt && \
11+
rm -f requirements.txt

docs/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ endif
99
BUILD_RUNNER = \
1010
docker run --rm --name mkdocs \
1111
$(DOCKER_RUN_AS) \
12+
-e PYTHONPATH=/rsconnect_python \
1213
-e VERSION=$(VERSION) \
13-
-v $(CURDIR):/mkdocs \
14-
-w /mkdocs \
14+
-v $(CURDIR)/../:/rsconnect_python \
15+
-w /rsconnect_python/docs \
1516
$(MKDOCS_IMAGE)
1617

1718
.PHONY: all
@@ -31,4 +32,4 @@ build: docs/index.md
3132
@rm docs/index.md
3233

3334
docs/index.md: $(CURDIR)/../README.md
34-
python patch_admonitions.py
35+
python3 patch_admonitions.py

docs/mkdocs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ markdown_extensions:
1313

1414
plugins:
1515
- macros
16+
- search
17+
- mkapi
18+
19+
nav:
20+
- index.md
21+
- API: mkapi/api/rsconnect
1622

1723
theme:
1824
name: material

docs/requirements.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mkdocs
2+
3+
Pygments
4+
markdown
5+
markdown-include
6+
mkapi
7+
mkdocs-exclude
8+
mkdocs-macros-plugin
9+
mkdocs-material
10+
pymdown-extensions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ line-length = 120
66
target-version = ['py27', 'py35', 'py36', 'py37', 'py38']
77

88
[tool.coverage.run]
9-
omit = ["rsconnect/tests/*"]
9+
omit = ["tests/*"]
1010

1111
[tool.setuptools_scm]
1212
write_to = "rsconnect/version.py"

rsconnect/actions.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Public API for managing settings and deploying content.
3+
"""
4+
15
import contextlib
26
import json
37
import logging
@@ -909,7 +913,7 @@ def gather_basic_deployment_info_for_notebook(connect_server, app_store, file_na
909913
app_id, app_mode = app_store.resolve(connect_server.url, app_id, app_mode)
910914
if static and app_mode != AppModes.STATIC:
911915
raise api.RSConnectException(
912-
'Cannot change app mode to "static" once deployed. ' "Use --new to create a new deployment."
916+
'Cannot change app mode to "static" once deployed. Use --new to create a new deployment.'
913917
)
914918

915919
default_title = not bool(title)
@@ -969,22 +973,11 @@ def gather_basic_deployment_info_from_manifest(connect_server, app_store, file_n
969973

970974

971975
def _generate_gather_basic_deployment_info_for_python(app_mode):
976+
"""
977+
Generates function to gather the necessary info for performing a deployment by app mode
978+
"""
979+
972980
def gatherer(connect_server, app_store, directory, entry_point, new, app_id, title):
973-
"""
974-
Helps to gather the necessary info for performing a deployment.
975-
976-
:param connect_server: the Connect server information.
977-
:param app_store: the store for the specified directory.
978-
:param directory: the primary file being deployed.
979-
:param entry_point: the entry point for the API in '<module>:<object> format. if
980-
the object name is omitted, it defaults to the module name. If nothing is specified,
981-
it defaults to 'app'.
982-
:param new: a flag noting whether we should force a new deployment.
983-
:param app_id: the ID of the app to redeploy.
984-
:param title: an optional title. If this isn't specified, a default title will
985-
be generated.
986-
:return: the entry point, app ID, name, title and mode for the deployment.
987-
"""
988981
return _gather_basic_deployment_info_for_framework(
989982
connect_server, app_store, directory, entry_point, new, app_id, app_mode, title,
990983
)

rsconnect/api.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
RStudio Connect API client and utility functions
3+
"""
4+
15
import time
26
from _ssl import SSLError
37

@@ -6,8 +10,10 @@
610
from rsconnect.models import AppModes
711

812
_error_map = {
9-
4: "This content has been deployed before but could not be found on the server.\nUse the --new option to "
10-
"deploy it as new content."
13+
4: (
14+
"This content has been deployed before but could not be found on the server.\nUse the --new option to "
15+
"deploy it as new content."
16+
)
1117
}
1218

1319

0 commit comments

Comments
 (0)