Skip to content

Commit 011d10d

Browse files
committed
Improve documentation
- Switch to Read the Docs theme - Include project README in docs homepage - Move documentation of login environment variables from hidden logging to docstring and README.
1 parent f699585 commit 011d10d

File tree

6 files changed

+73
-42
lines changed

6 files changed

+73
-42
lines changed

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ can use it to automate uploads and downloads to the PMHC portal.
55

66
## Install
77

8-
This script is setup as a Python package. You should be able to install
8+
`pmhclib` is a Python package. You should be able to install
99
it directly with `pip` or `poetry`:
1010

1111
``` sh
@@ -20,6 +20,15 @@ poetry add pmhclib@git+https://github.com/swsphn/pmhclib.git
2020

2121
This will install `pmhclib` as an importable Python library.
2222

23+
NOTE: This package depends on [Playwright][] to authenticate to the PMHC
24+
portal. Once the package is installed, you will need to install
25+
a browser for Playwright to use. Make sure you are in the same Python
26+
environment in which you installed `pmhclib`, then run:
27+
28+
```
29+
playwright install chromium
30+
```
31+
2332
## Usage
2433

2534
`pmhclib.PMHC` is intended to be used with a context manager. This
@@ -45,11 +54,55 @@ PMHC_PASSWORD
4554

4655
Otherwise, you will be prompted for credentials interactively.
4756

57+
In PowerShell, you can set the environment variables interactively as
58+
follows:
59+
60+
``` ps1
61+
$env:PMHC_USERNAME='your_username_here'
62+
$env:PMHC_PASSWORD=python -c 'import getpass; print(getpass.getpass())'
63+
```
64+
65+
In a Unix shell (Mac, Linux), you can do:
66+
67+
``` bash
68+
export PMHC_USERNAME='your_username_here'
69+
read -rs PMHC_PASSWORD && export PMHC_PASSWORD
70+
```
71+
4872
## Documentation
4973

74+
See the [online documentation][docs].
75+
76+
### Built-in docs
77+
5078
Review the built-in documentation from Python as follows:
5179

5280
``` python
5381
>>> from pmhclib import PMHC
5482
>>> help(PMHC)
5583
```
84+
85+
### Build docs
86+
87+
You can also generate html documentation locally using [Sphinx][] if you
88+
have a local copy of the repository.
89+
90+
Linux:
91+
92+
```
93+
cd docs
94+
make html
95+
```
96+
97+
PowerShell:
98+
99+
```
100+
cd docs
101+
./make.bat html
102+
```
103+
104+
The generated documentation can be viewed at `docs/_build/html/index.html`.
105+
106+
[Playwright]: https://playwright.dev/python/
107+
[Sphinx]: https://www.sphinx-doc.org/
108+
[docs]: https://reimagined-doodle-o4zv319.pages.github.io/

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# -- Options for HTML output -------------------------------------------------
2424
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
2525

26-
html_theme = 'alabaster'
26+
html_theme = 'sphinx_rtd_theme'
2727
html_static_path = ['_static']
2828

2929
# -- Options for autoapi

docs/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
```{include} ../README.md
2+
```
3+
4+
```{toctree}
5+
:maxdepth: 1
6+
:hidden:
7+
8+
autoapi/index
9+
```
10+

docs/index.rst

Lines changed: 0 additions & 20 deletions
This file was deleted.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ playwright = ">=1.40.0"
1515

1616
[tool.poetry.group.docs.dependencies]
1717
sphinx = ">=7.0.0"
18-
myst-parser = "^2.0.0"
19-
sphinx-autoapi = "^3.0.0"
18+
myst-parser = ">=2.0.0"
19+
sphinx-autoapi = ">=3.0.0"
20+
sphinx-rtd-theme = ">=2.0.0"
2021

2122
[build-system]
2223
requires = ["poetry-core"]

src/pmhclib/pmhc.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,31 +118,18 @@ def __init__(self, headless: bool = True):
118118
def login(self):
119119
"""Logs in to PMHC website. This allows us to reuse the login the session
120120
across other class methods.
121+
122+
Set the following environment variables to skip interactive login prompt:
123+
124+
- `PMHC_USERNAME`
125+
- `PMHC_PASSWORD`
121126
"""
122127

123128
# Prompt user for credentials if not set in env.
124129
username = os.getenv("PMHC_USERNAME")
125130
password = SecureString(os.getenv("PMHC_PASSWORD") or "")
126131

127132
while not username:
128-
if platform.system() == "Windows":
129-
logging.debug(
130-
"In future, consider setting the following environment variables "
131-
"when running this script:\n"
132-
"PMHC_USERNAME and PMHC_PASSWORD\n"
133-
"To do so, run the following commands in PowerShell:\n"
134-
"$env:PMHC_USERNAME='your_username_here'\n"
135-
"$env:PMHC_PASSWORD=python -c 'import getpass; print(getpass.getpass())'"
136-
)
137-
elif platform.system() == "Linux":
138-
logging.debug(
139-
"In future, consider setting the following environment variables "
140-
"when running this script:\n"
141-
"PMHC_USERNAME and PMHC_PASSWORD\n"
142-
"To do so, run the following commands in Linux:\n"
143-
"read PMHC_USERNAME && export PMHC_USERNAME\n"
144-
"read -rs PMHC_PASSWORD && export PMHC_PASSWORD"
145-
)
146133
username = input("Enter PMHC username: ")
147134

148135
while not password:

0 commit comments

Comments
 (0)