Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit c7ca07c

Browse files
committed
scripts: docs: Remove replacement of username
Signed-off-by: John Andersen <[email protected]>
1 parent e368d13 commit c7ca07c

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

docs/contributing/dev_env.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ all the packages in development mode.
174174
$ mkdir -p .venv
175175
$ export HOME="${PWD}/.venv"
176176
$ export PATH="${HOME}/.local/bin:${PATH}"
177-
$ pip install --user -U setuptools
177+
$ pip install --user -U pip setuptools
178178
$ pip install --prefix=~/.local -e .[dev]
179179
$ dffml service dev install -user
180180

scripts/docs.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# SPDX-License-Identifier: MIT
22
# Copyright (c) 2019 Intel Corporation
33
import os
4-
import getpass
4+
import pwd
55
import inspect
66
import argparse
77
import importlib
8-
import pkg_resources
98
import configparser
9+
import pkg_resources
10+
import unittest.mock
1011
from typing import List, Type
1112

1213

@@ -65,7 +66,7 @@ def data_type_string(data_type, nargs=None):
6566
def sanitize_default(default):
6667
if not isinstance(default, str):
6768
return sanitize_default(str(default))
68-
return default.replace(getpass.getuser(), "user")
69+
return default
6970

7071

7172
def build_args(config):
@@ -209,6 +210,12 @@ def gen_docs(
209210
)
210211

211212

213+
def fake_getpwuid(uid):
214+
return pwd.struct_passwd(
215+
("user", "x", uid, uid, "", "/home/user", "/bin/bash",)
216+
)
217+
218+
212219
def main():
213220
parser = argparse.ArgumentParser(description="Generate plugin docs")
214221
parser.add_argument("--entrypoint", help="Entrypoint to document")
@@ -226,26 +233,32 @@ def main():
226233
)
227234
args = parser.parse_args()
228235

229-
if getattr(args, "entrypoint", False) and getattr(args, "modules", False):
230-
print(gen_docs(args.entrypoint, args.modules, args.maintenance))
231-
return
232-
233-
with open(args.care, "rb") as genspec:
234-
for line in genspec:
235-
entrypoint, modules = line.decode("utf-8").split(maxsplit=1)
236-
modules = modules.split()
237-
template = entrypoint.replace(".", "_") + ".rst"
238-
output = os.path.join("docs", "plugins", template)
239-
template = os.path.join("scripts", "docs", "templates", template)
240-
with open(template, "rb") as template_fd, open(
241-
output, "wb"
242-
) as output_fd:
243-
output_fd.write(
244-
(
245-
template_fd.read().decode("utf-8")
246-
+ gen_docs(entrypoint, modules)
247-
).encode("utf-8")
236+
with unittest.mock.patch("pwd.getpwuid", new=fake_getpwuid):
237+
238+
if getattr(args, "entrypoint", False) and getattr(
239+
args, "modules", False
240+
):
241+
print(gen_docs(args.entrypoint, args.modules, args.maintenance))
242+
return
243+
244+
with open(args.care, "rb") as genspec:
245+
for line in genspec:
246+
entrypoint, modules = line.decode("utf-8").split(maxsplit=1)
247+
modules = modules.split()
248+
template = entrypoint.replace(".", "_") + ".rst"
249+
output = os.path.join("docs", "plugins", template)
250+
template = os.path.join(
251+
"scripts", "docs", "templates", template
248252
)
253+
with open(template, "rb") as template_fd, open(
254+
output, "wb"
255+
) as output_fd:
256+
output_fd.write(
257+
(
258+
template_fd.read().decode("utf-8")
259+
+ gen_docs(entrypoint, modules)
260+
).encode("utf-8")
261+
)
249262

250263

251264
if __name__ == "__main__":

0 commit comments

Comments
 (0)