Skip to content

Commit 0c1c7e8

Browse files
authored
Merge pull request #496 from rstudio/mm-verbose-logging
Add verbose log level for filenames being bundled
2 parents e79f41a + 00903bc commit 0c1c7e8

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
and `*_app.py` are now considered. However, if the directory contains more than
2828
one file matching these new patterns, you must provide rsconnect-python with an
2929
explicit `--entrypoint` argument.
30+
- Added a new verbose logging level. Specifying `-v` on the command line uses this
31+
new level. Currently this will cause filenames to be logged as they are added to
32+
a bundle. To enable maximum verbosity (debug level), use `-vv`.
3033

3134
## [1.20.0] - 2023-09-11
3235

rsconnect/actions.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
read_manifest_file,
4141
)
4242
from .environment import Environment, MakeEnvironment, EnvironmentException
43-
from .log import logger
43+
from .log import logger, VERBOSE
4444
from .models import AppModes, AppMode
4545
from .api import RSConnectExecutor, filter_out_server_info
4646

@@ -98,15 +98,17 @@ def failed(err):
9898
logger.set_in_feedback(False)
9999

100100

101-
def set_verbosity(verbose):
101+
def set_verbosity(verbose: int):
102102
"""Set the verbosity level based on a passed flag
103103
104104
:param verbose: boolean specifying verbose or not
105105
"""
106-
if verbose:
107-
logger.setLevel(logging.DEBUG)
108-
else:
106+
if verbose == 0:
109107
logger.setLevel(logging.INFO)
108+
elif verbose == 1:
109+
logger.setLevel(VERBOSE)
110+
else:
111+
logger.setLevel(logging.DEBUG)
110112

111113

112114
def which_python(python, env=os.environ):

rsconnect/bundle.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from os.path import basename, dirname, exists, isdir, join, relpath, splitext, isfile, abspath
3030

31-
from .log import logger
31+
from .log import logger, VERBOSE
3232
from .models import AppMode, AppModes, GlobSet
3333
from .environment import Environment, MakeEnvironment
3434
from .exception import RSConnectException
@@ -277,11 +277,13 @@ def to_file(self, flatten_to_deploy_dir=True):
277277
if Path(fp).name in self.buffer:
278278
continue
279279
rel_path = Path(fp).relative_to(self.deploy_dir) if flatten_to_deploy_dir else None
280+
logger.log(VERBOSE, "Adding file: %s", fp)
280281
bundle.add(fp, arcname=rel_path)
281282
for k, v in self.buffer.items():
282283
buf = io.BytesIO(to_bytes(v))
283284
file_info = tarfile.TarInfo(k)
284285
file_info.size = len(buf.getvalue())
286+
logger.log(VERBOSE, "Adding file: %s", k)
285287
bundle.addfile(file_info, buf)
286288
bundle_file.seek(0)
287289
return bundle_file
@@ -424,7 +426,7 @@ def bundle_add_file(bundle, rel_path, base_dir):
424426
The file path is relative to the notebook directory.
425427
"""
426428
path = join(base_dir, rel_path) if os.path.isdir(base_dir) else rel_path
427-
logger.debug("adding file: %s", path)
429+
logger.log(VERBOSE, "Adding file: %s", path)
428430
bundle.add(path, arcname=rel_path)
429431

430432

@@ -433,7 +435,7 @@ def bundle_add_buffer(bundle, filename, contents):
433435
434436
`contents` may be a string or bytes object
435437
"""
436-
logger.debug("adding file: %s", filename)
438+
logger.log(VERBOSE, "Adding file: %s", filename)
437439
buf = io.BytesIO(to_bytes(contents))
438440
file_info = tarfile.TarInfo(filename)
439441
file_info.size = len(buf.getvalue())

rsconnect/log.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
_DATE_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
1111

12+
VERBOSE = int((logging.INFO + logging.DEBUG) / 2)
13+
logging.addLevelName(VERBOSE, "VERBOSE")
14+
1215

1316
class LogOutputFormat(object):
1417
TEXT = "text"

rsconnect/main.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def server_args(func):
135135
type=click.Path(exists=True, file_okay=True, dir_okay=False),
136136
help="The path to trusted TLS CA certificates.",
137137
)
138-
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
138+
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
139139
@functools.wraps(func)
140140
def wrapper(*args, **kwargs):
141141
return func(*args, **kwargs)
@@ -243,6 +243,7 @@ def wrapper(*args, **kwargs):
243243

244244
return wrapper
245245

246+
246247
# This callback handles the "shorthand" --disable-env-management option.
247248
# If the shorthand flag is provided, then it takes precendence over the R and Python flags.
248249
# This callback also inverts the --disable-env-management-r and
@@ -399,7 +400,7 @@ def _test_rstudio_creds(server: api.PositServer):
399400
help="The path to the file containing the private key used to sign the JWT.",
400401
)
401402
@click.option("--raw", "-r", is_flag=True, help="Return the API key as raw output rather than a JSON object")
402-
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose output")
403+
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
403404
@cli_exception_handler
404405
def bootstrap(
405406
server,
@@ -482,11 +483,10 @@ def bootstrap(
482483
type=click.Path(exists=True, file_okay=True, dir_okay=False),
483484
help="The path to trusted TLS CA certificates.",
484485
)
485-
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
486+
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
486487
@cloud_shinyapps_args
487488
@click.pass_context
488489
def add(ctx, name, server, api_key, insecure, cacert, account, token, secret, verbose):
489-
490490
set_verbosity(verbose)
491491
if click.__version__ >= "8.0.0" and sys.version_info >= (3, 7):
492492
click.echo("Detected the following inputs:")
@@ -550,7 +550,7 @@ def add(ctx, name, server, api_key, insecure, cacert, account, token, secret, ve
550550
short_help="List the known Posit Connect servers.",
551551
help="Show the stored information about each known server nickname.",
552552
)
553-
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
553+
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
554554
def list_servers(verbose):
555555
set_verbosity(verbose)
556556
with cli_feedback(""):
@@ -630,7 +630,7 @@ def details(name, server, api_key, insecure, cacert, verbose):
630630
)
631631
@click.option("--name", "-n", help="The nickname of the Posit Connect server to remove.")
632632
@click.option("--server", "-s", help="The URL of the Posit Connect server to remove.")
633-
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
633+
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
634634
def remove(name, server, verbose):
635635
set_verbosity(verbose)
636636

@@ -866,7 +866,7 @@ def deploy_notebook(
866866
python,
867867
conda,
868868
force_generate,
869-
verbose: bool,
869+
verbose: int,
870870
file: str,
871871
extra_files,
872872
hide_all_input: bool,
@@ -986,7 +986,7 @@ def deploy_voila(
986986
env_management_r: bool = None,
987987
title: str = None,
988988
env_vars: typing.Dict[str, str] = None,
989-
verbose: bool = False,
989+
verbose: int = 0,
990990
new: bool = False,
991991
app_id: str = None,
992992
name: str = None,
@@ -1050,7 +1050,7 @@ def deploy_manifest(
10501050
new: bool,
10511051
app_id: str,
10521052
title: str,
1053-
verbose: bool,
1053+
verbose: int,
10541054
file: str,
10551055
env_vars: typing.Dict[str, str],
10561056
visibility: typing.Optional[str],
@@ -1143,7 +1143,7 @@ def deploy_quarto(
11431143
quarto,
11441144
python,
11451145
force_generate: bool,
1146-
verbose: bool,
1146+
verbose: int,
11471147
file_or_directory,
11481148
extra_files,
11491149
env_vars: typing.Dict[str, str],
@@ -1245,7 +1245,7 @@ def deploy_html(
12451245
exclude=None,
12461246
title: str = None,
12471247
env_vars: typing.Dict[str, str] = None,
1248-
verbose: bool = False,
1248+
verbose: int = 0,
12491249
new: bool = False,
12501250
app_id: str = None,
12511251
name: str = None,
@@ -1258,6 +1258,8 @@ def deploy_html(
12581258
secret: str = None,
12591259
):
12601260
kwargs = locals()
1261+
set_verbosity(verbose)
1262+
12611263
ce = None
12621264
if connect_server:
12631265
kwargs = filter_out_server_info(**kwargs)
@@ -1360,7 +1362,7 @@ def deploy_app(
13601362
python,
13611363
conda,
13621364
force_generate: bool,
1363-
verbose: bool,
1365+
verbose: int,
13641366
directory,
13651367
extra_files,
13661368
visibility: typing.Optional[str],
@@ -1373,6 +1375,7 @@ def deploy_app(
13731375
token: str = None,
13741376
secret: str = None,
13751377
):
1378+
set_verbosity(verbose)
13761379
kwargs = locals()
13771380
kwargs["entrypoint"] = entrypoint = validate_entry_point(entrypoint, directory)
13781381
kwargs["extra_files"] = extra_files = validate_extra_files(directory, extra_files)
@@ -2155,7 +2158,7 @@ def remove_content_build(name, server, api_key, insecure, cacert, guid, all, pur
21552158
metavar="TEXT",
21562159
help="Check the local build state of a specific content item. This flag can be passed multiple times.",
21572160
)
2158-
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
2161+
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
21592162
# todo: --format option (json, text)
21602163
def list_content_build(name, server, api_key, insecure, cacert, status, guid, verbose):
21612164
set_verbosity(verbose)

0 commit comments

Comments
 (0)