Skip to content

Add verbose log level for filenames being bundled #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
and `*_app.py` are now considered. However, if the directory contains more than
one file matching these new patterns, you must provide rsconnect-python with an
explicit `--entrypoint` argument.
- Added a new verbose logging level. Specifying `-v` on the command line uses this
new level. Currently this will cause filenames to be logged as they are added to
a bundle. To enable maximum verbosity (debug level), use `-vv`.

## [1.20.0] - 2023-09-11

Expand Down
12 changes: 7 additions & 5 deletions rsconnect/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
read_manifest_file,
)
from .environment import Environment, MakeEnvironment, EnvironmentException
from .log import logger
from .log import logger, VERBOSE
from .models import AppModes, AppMode
from .api import RSConnectExecutor, filter_out_server_info

Expand Down Expand Up @@ -98,15 +98,17 @@ def failed(err):
logger.set_in_feedback(False)


def set_verbosity(verbose):
def set_verbosity(verbose: int):
"""Set the verbosity level based on a passed flag

:param verbose: boolean specifying verbose or not
"""
if verbose:
logger.setLevel(logging.DEBUG)
else:
if verbose == 0:
logger.setLevel(logging.INFO)
elif verbose == 1:
logger.setLevel(VERBOSE)
else:
logger.setLevel(logging.DEBUG)


def which_python(python, env=os.environ):
Expand Down
8 changes: 5 additions & 3 deletions rsconnect/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

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

from .log import logger
from .log import logger, VERBOSE
from .models import AppMode, AppModes, GlobSet
from .environment import Environment, MakeEnvironment
from .exception import RSConnectException
Expand Down Expand Up @@ -277,11 +277,13 @@ def to_file(self, flatten_to_deploy_dir=True):
if Path(fp).name in self.buffer:
continue
rel_path = Path(fp).relative_to(self.deploy_dir) if flatten_to_deploy_dir else None
logger.log(VERBOSE, "Adding file: %s", fp)
bundle.add(fp, arcname=rel_path)
for k, v in self.buffer.items():
buf = io.BytesIO(to_bytes(v))
file_info = tarfile.TarInfo(k)
file_info.size = len(buf.getvalue())
logger.log(VERBOSE, "Adding file: %s", k)
bundle.addfile(file_info, buf)
bundle_file.seek(0)
return bundle_file
Expand Down Expand Up @@ -424,7 +426,7 @@ def bundle_add_file(bundle, rel_path, base_dir):
The file path is relative to the notebook directory.
"""
path = join(base_dir, rel_path) if os.path.isdir(base_dir) else rel_path
logger.debug("adding file: %s", path)
logger.log(VERBOSE, "Adding file: %s", path)
bundle.add(path, arcname=rel_path)


Expand All @@ -433,7 +435,7 @@ def bundle_add_buffer(bundle, filename, contents):

`contents` may be a string or bytes object
"""
logger.debug("adding file: %s", filename)
logger.log(VERBOSE, "Adding file: %s", filename)
buf = io.BytesIO(to_bytes(contents))
file_info = tarfile.TarInfo(filename)
file_info.size = len(buf.getvalue())
Expand Down
3 changes: 3 additions & 0 deletions rsconnect/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

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

VERBOSE = int((logging.INFO + logging.DEBUG) / 2)
logging.addLevelName(VERBOSE, "VERBOSE")


class LogOutputFormat(object):
TEXT = "text"
Expand Down
29 changes: 16 additions & 13 deletions rsconnect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def server_args(func):
type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="The path to trusted TLS CA certificates.",
)
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
Expand Down Expand Up @@ -243,6 +243,7 @@ def wrapper(*args, **kwargs):

return wrapper


# This callback handles the "shorthand" --disable-env-management option.
# If the shorthand flag is provided, then it takes precendence over the R and Python flags.
# This callback also inverts the --disable-env-management-r and
Expand Down Expand Up @@ -399,7 +400,7 @@ def _test_rstudio_creds(server: api.PositServer):
help="The path to the file containing the private key used to sign the JWT.",
)
@click.option("--raw", "-r", is_flag=True, help="Return the API key as raw output rather than a JSON object")
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose output")
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
@cli_exception_handler
def bootstrap(
server,
Expand Down Expand Up @@ -482,11 +483,10 @@ def bootstrap(
type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="The path to trusted TLS CA certificates.",
)
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
@cloud_shinyapps_args
@click.pass_context
def add(ctx, name, server, api_key, insecure, cacert, account, token, secret, verbose):

set_verbosity(verbose)
if click.__version__ >= "8.0.0" and sys.version_info >= (3, 7):
click.echo("Detected the following inputs:")
Expand Down Expand Up @@ -550,7 +550,7 @@ def add(ctx, name, server, api_key, insecure, cacert, account, token, secret, ve
short_help="List the known Posit Connect servers.",
help="Show the stored information about each known server nickname.",
)
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
def list_servers(verbose):
set_verbosity(verbose)
with cli_feedback(""):
Expand Down Expand Up @@ -630,7 +630,7 @@ def details(name, server, api_key, insecure, cacert, verbose):
)
@click.option("--name", "-n", help="The nickname of the Posit Connect server to remove.")
@click.option("--server", "-s", help="The URL of the Posit Connect server to remove.")
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
def remove(name, server, verbose):
set_verbosity(verbose)

Expand Down Expand Up @@ -866,7 +866,7 @@ def deploy_notebook(
python,
conda,
force_generate,
verbose: bool,
verbose: int,
file: str,
extra_files,
hide_all_input: bool,
Expand Down Expand Up @@ -986,7 +986,7 @@ def deploy_voila(
env_management_r: bool = None,
title: str = None,
env_vars: typing.Dict[str, str] = None,
verbose: bool = False,
verbose: int = 0,
new: bool = False,
app_id: str = None,
name: str = None,
Expand Down Expand Up @@ -1050,7 +1050,7 @@ def deploy_manifest(
new: bool,
app_id: str,
title: str,
verbose: bool,
verbose: int,
file: str,
env_vars: typing.Dict[str, str],
visibility: typing.Optional[str],
Expand Down Expand Up @@ -1143,7 +1143,7 @@ def deploy_quarto(
quarto,
python,
force_generate: bool,
verbose: bool,
verbose: int,
file_or_directory,
extra_files,
env_vars: typing.Dict[str, str],
Expand Down Expand Up @@ -1245,7 +1245,7 @@ def deploy_html(
exclude=None,
title: str = None,
env_vars: typing.Dict[str, str] = None,
verbose: bool = False,
verbose: int = 0,
new: bool = False,
app_id: str = None,
name: str = None,
Expand All @@ -1258,6 +1258,8 @@ def deploy_html(
secret: str = None,
):
kwargs = locals()
set_verbosity(verbose)

ce = None
if connect_server:
kwargs = filter_out_server_info(**kwargs)
Expand Down Expand Up @@ -1360,7 +1362,7 @@ def deploy_app(
python,
conda,
force_generate: bool,
verbose: bool,
verbose: int,
directory,
extra_files,
visibility: typing.Optional[str],
Expand All @@ -1373,6 +1375,7 @@ def deploy_app(
token: str = None,
secret: str = None,
):
set_verbosity(verbose)
kwargs = locals()
kwargs["entrypoint"] = entrypoint = validate_entry_point(entrypoint, directory)
kwargs["extra_files"] = extra_files = validate_extra_files(directory, extra_files)
Expand Down Expand Up @@ -2155,7 +2158,7 @@ def remove_content_build(name, server, api_key, insecure, cacert, guid, all, pur
metavar="TEXT",
help="Check the local build state of a specific content item. This flag can be passed multiple times.",
)
@click.option("--verbose", "-v", is_flag=True, help="Print detailed messages.")
@click.option("--verbose", "-v", count=True, help="Enable verbose output. Use -vv for very verbose (debug) output.")
# todo: --format option (json, text)
def list_content_build(name, server, api_key, insecure, cacert, status, guid, verbose):
set_verbosity(verbose)
Expand Down