Skip to content
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

Fix integration tests #292

Merged
merged 3 commits into from
May 10, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ coverage.xml
dist
venv
doc/source/main_help.rst
doc/source/subcommands
Dockerfile
b2/licenses_output.txt
*.spec
2 changes: 2 additions & 0 deletions b2/_internal/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def resolve_b2_bin_call_name(argv: list[str] | None = None) -> str:
if call_name.endswith('.py'):
version_name = re.search(r'[\\/]b2[\\/]_internal[\\/](_?b2v\d+)[\\/]__main__.py', call_name)
call_name = version_name.group(1) if version_name else 'b2'
if 'b2' not in call_name: # prevent silliness when calling b2 from under different process
return 'b2'
return call_name


Expand Down
63 changes: 63 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
from __future__ import annotations

import tempfile

import datetime
import importlib
import os
import filecmp
import pathlib
import re
import shutil
import sys
import textwrap
from os import path
Expand Down Expand Up @@ -213,6 +219,7 @@ def setup(_):
reasonable way to piggy back that behaviour. Checking if the new file contents would the same as the old one
(if any) is important, so that the automatic file-watcher/doc-builder doesn't fall into an endless loop.
"""
regenerate_subcommands_help()
main_help_text = str(B2.lazy_get_description(NAME='b2'))
main_help_text = textwrap.dedent(main_help_text)

Expand All @@ -223,3 +230,59 @@ def setup(_):
return
with open(main_help_path, 'w') as main_help_file:
main_help_file.write(main_help_text)


def regenerate_subcommands_help():
tmpl = textwrap.dedent("""\
.. _{slug}:

{HUMAN_NAME}
************************************************

.. argparse::
:module: b2._internal.console_tool
:func: get_parser
:prog: b2
:path: {COMMAND}
""")

all_commands: list[tuple[tuple[str, ...], type]] = []

def _add_cmd(path, cmd_cls):
if getattr(cmd_cls, "deprecated", False):
return

registry = cmd_cls.subcommands_registry
subcommands = registry.values() if registry else None
if subcommands:
for subcommand in subcommands:
_add_cmd(path + (subcommand.name_and_alias()[0],), subcommand)
else:
all_commands.append((path, cmd_cls))

_add_cmd((), B2)

subcommands_dir_target = pathlib.Path(__file__).parent / "subcommands"
with tempfile.TemporaryDirectory() as temp_dir:
subcommands_dir = pathlib.Path(temp_dir) / "subcommands"
subcommands_dir.mkdir()
for command_path, cmd_cls in sorted(all_commands):
full_command = " ".join(command_path)
slug = full_command.replace(" ", "_")
(subcommands_dir / f"{slug}.rst").write_text(
tmpl.format(
HUMAN_NAME=full_command,
COMMAND=full_command,
slug=f"subcommand_{slug}",
)
)

# prevent infinite loop due sphinx autobuild file watcher
try:
dir_cmp = filecmp.dircmp(subcommands_dir_target, subcommands_dir)
is_diff = bool(dir_cmp.diff_files or dir_cmp.left_only or dir_cmp.right_only)
except FileNotFoundError:
is_diff = True
if is_diff:
shutil.rmtree(subcommands_dir_target, ignore_errors=True)
shutil.copytree(subcommands_dir, subcommands_dir_target)
8 changes: 4 additions & 4 deletions doc/source/replication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Replication
########################

If you have access to accounts hosting both source and destination bucket (it can be the same account), we recommend using ``replication-setup`` command described below. Otherwise use :ref:`manual setup <replication_manual_setup>`.
If you have access to accounts hosting both source and destination bucket (it can be the same account), we recommend using ``replication setup`` command described below. Otherwise use :ref:`manual setup <replication_manual_setup>`.

***********************
Automatic setup
Expand All @@ -15,12 +15,12 @@ Setup replication

.. code-block:: sh

$ b2 replication-setup --destination-profile myprofile2 my-bucket my-bucket2
$ b2 replication setup --destination-profile myprofile2 my-bucket my-bucket2

You can optionally choose source rule priority and source rule name. See :ref:`replication-setup command <replication_setup_command>`.
You can optionally choose source rule priority and source rule name. See :ref:`replication setup command <subcommand_replication_setup>`.

.. note::
``replication-setup`` will reuse or provision a source key with no prefix and full reading capabilities and a destination key with no prefix and full writing capabilities
``replication setup`` will reuse or provision a source key with no prefix and full reading capabilities and a destination key with no prefix and full writing capabilities

.. _replication_manual_setup:

Expand Down
8 changes: 0 additions & 8 deletions doc/source/subcommands/authorize_account.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/cancel_all_unfinished_large_files.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/cancel_large_file.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/cat.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/clear_account.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/copy_file_by_id.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/create_bucket.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/create_key.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/delete_bucket.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/delete_file_version.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/delete_key.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/download_file.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/download_file_by_id.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/download_file_by_name.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/file_info.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/get_account_info.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/get_bucket.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/get_download_auth.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/get_download_url_with_auth.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/get_file_info.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/get_url.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/hide_file.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/install_autocomplete.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/list_buckets.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/list_keys.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/list_parts.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/list_unfinished_large_files.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/ls.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/make_friendly_url.rst

This file was deleted.

8 changes: 0 additions & 8 deletions doc/source/subcommands/make_url.rst

This file was deleted.

Loading
Loading