depot/patches/base/dvc/no-analytics.patch

268 lines
7.7 KiB
Diff
Raw Normal View History

2022-08-05 15:59:38 +03:00
diff --git a/dvc/analytics.py b/dvc/analytics.py
2023-06-06 01:59:36 +03:00
deleted file mode 100644
index 6e3dc91..0000000
2022-08-05 15:59:38 +03:00
--- a/dvc/analytics.py
2023-06-06 01:59:36 +03:00
+++ /dev/null
@@ -1,156 +0,0 @@
2022-08-05 15:59:38 +03:00
-import json
-import logging
-import os
-
-from .env import DVC_NO_ANALYTICS
-
-logger = logging.getLogger(__name__)
-
-
2023-06-06 01:59:36 +03:00
-def collect_and_send_report(args=None, return_code=None):
- """
- Collect information from the runtime/environment and the command
- being executed into a report and send it over the network.
-
- To prevent analytics from blocking the execution of the main thread,
- sending the report is done in a separate process.
-
- The inter-process communication happens through a file containing the
- report as a JSON, where the _collector_ generates it and the _sender_
- removes it after sending it.
- """
2022-08-05 15:59:38 +03:00
- import tempfile
-
- from dvc.daemon import daemon
-
- report = {}
-
- # Include command execution information on the report only when available.
- if args and hasattr(args, "func"):
- report.update({"cmd_class": args.func.__name__})
-
- if return_code is not None:
- report.update({"cmd_return_code": return_code})
-
- with tempfile.NamedTemporaryFile(delete=False, mode="w") as fobj:
- json.dump(report, fobj)
- daemon(["analytics", fobj.name])
2023-06-06 01:59:36 +03:00
-
-
-def is_enabled():
2022-08-05 15:59:38 +03:00
- from dvc.config import Config, to_bool
- from dvc.utils import env2bool
-
- if env2bool("DVC_TEST"):
- return False
-
- enabled = not os.getenv(DVC_NO_ANALYTICS)
- if enabled:
- enabled = to_bool(
2023-06-06 01:59:36 +03:00
- Config.from_cwd(validate=False).get("core", {}).get("analytics", "true")
2022-08-05 15:59:38 +03:00
- )
-
2022-12-17 14:52:18 +02:00
- logger.debug("Analytics is %sabled.", "en" if enabled else "dis")
2022-08-05 15:59:38 +03:00
-
- return enabled
2023-06-06 01:59:36 +03:00
-
-
-def send(path):
- """
- Side effect: Removes the report after sending it.
-
- The report is generated and stored in a temporary file, see:
- `collect_and_send_report`. Sending happens on another process,
- thus, the need of removing such file afterwards.
- """
2022-08-05 15:59:38 +03:00
- import requests
-
- url = "https://analytics.dvc.org"
- headers = {"content-type": "application/json"}
-
- with open(path, encoding="utf-8") as fobj:
- report = json.load(fobj)
-
- report.update(_runtime_info())
-
- try:
- requests.post(url, json=report, headers=headers, timeout=5)
- except requests.exceptions.RequestException:
- logger.debug("failed to send analytics report", exc_info=True)
-
- os.remove(path)
-
2023-06-06 01:59:36 +03:00
-
-def _scm_in_use():
2022-08-05 15:59:38 +03:00
- from dvc.exceptions import NotDvcRepoError
- from dvc.repo import Repo
2023-06-06 01:59:36 +03:00
- from dvc.scm import NoSCM
2022-08-05 15:59:38 +03:00
-
- from .scm import SCM, SCMError
-
- try:
- scm = SCM(root_dir=Repo.find_root())
- return type(scm).__name__
- except SCMError:
- return NoSCM.__name__
- except NotDvcRepoError:
- pass
2023-06-06 01:59:36 +03:00
-
-
-def _runtime_info():
- """
- Gather information from the environment where DVC runs to fill a report.
- """
- from iterative_telemetry import _generate_ci_id, find_or_create_user_id
-
2022-08-05 15:59:38 +03:00
- from dvc import __version__
- from dvc.utils import is_binary
-
2023-06-06 01:59:36 +03:00
- ci_id = _generate_ci_id()
- if ci_id:
- group_id, user_id = ci_id
- else:
- group_id, user_id = None, find_or_create_user_id()
-
2022-08-05 15:59:38 +03:00
- return {
- "dvc_version": __version__,
- "is_binary": is_binary(),
- "scm_class": _scm_in_use(),
- "system_info": _system_info(),
2023-06-06 01:59:36 +03:00
- "user_id": user_id,
- "group_id": group_id,
2022-08-05 15:59:38 +03:00
- }
2023-06-06 01:59:36 +03:00
-
-
-def _system_info():
2022-08-05 15:59:38 +03:00
- import platform
- import sys
-
- import distro
-
- system = platform.system()
-
- if system == "Windows":
2023-06-06 01:59:36 +03:00
- version = sys.getwindowsversion() # type: ignore[attr-defined]
2022-08-05 15:59:38 +03:00
-
- return {
- "os": "windows",
- "windows_version_build": version.build,
- "windows_version_major": version.major,
- "windows_version_minor": version.minor,
- "windows_version_service_pack": version.service_pack,
- }
-
- if system == "Darwin":
- return {"os": "mac", "mac_version": platform.mac_ver()[0]}
-
- if system == "Linux":
- return {
- "os": "linux",
- "linux_distro": distro.id(),
- "linux_distro_like": distro.like(),
- "linux_distro_version": distro.version(),
- }
-
- # We don't collect data for any other system.
2023-06-06 01:59:36 +03:00
- raise NotImplementedError
2022-08-05 15:59:38 +03:00
diff --git a/dvc/cli/__init__.py b/dvc/cli/__init__.py
2023-06-06 01:59:36 +03:00
index 274b564..b601d84 100644
2022-08-05 15:59:38 +03:00
--- a/dvc/cli/__init__.py
+++ b/dvc/cli/__init__.py
2023-06-06 01:59:36 +03:00
@@ -236,11 +236,6 @@ def main(argv=None): # noqa: C901, PLR0912, PLR0915
2022-12-17 14:52:18 +02:00
ret = _log_exceptions(exc) or 255
2022-08-05 15:59:38 +03:00
try:
- from dvc import analytics
-
- if analytics.is_enabled():
- analytics.collect_and_send_report(args, ret)
-
return ret
finally:
2023-06-06 01:59:36 +03:00
logger.setLevel(outer_log_level)
2022-08-05 15:59:38 +03:00
diff --git a/dvc/commands/daemon.py b/dvc/commands/daemon.py
2023-06-06 01:59:36 +03:00
index 35d6e90..d5a7b6e 100644
2022-08-05 15:59:38 +03:00
--- a/dvc/commands/daemon.py
+++ b/dvc/commands/daemon.py
@@ -26,15 +26,6 @@ class CmdDaemonUpdater(CmdDaemonBase):
return 0
-class CmdDaemonAnalytics(CmdDaemonBase):
- def run(self):
- from dvc import analytics
-
- analytics.send(self.args.target)
-
- return 0
-
-
def add_parser(subparsers, parent_parser):
DAEMON_HELP = "Service daemon."
daemon_parser = subparsers.add_parser(
@@ -59,15 +50,3 @@ def add_parser(subparsers, parent_parser):
help=DAEMON_UPDATER_HELP,
)
daemon_updater_parser.set_defaults(func=CmdDaemonUpdater)
-
- DAEMON_ANALYTICS_HELP = "Send dvc usage analytics."
- daemon_analytics_parser = daemon_subparsers.add_parser(
- "analytics",
- parents=[parent_parser],
- description=DAEMON_ANALYTICS_HELP,
- help=DAEMON_ANALYTICS_HELP,
- )
- daemon_analytics_parser.add_argument(
- "target", help="Analytics file."
- ).complete = completion.FILE
- daemon_analytics_parser.set_defaults(func=CmdDaemonAnalytics)
diff --git a/dvc/commands/init.py b/dvc/commands/init.py
2023-06-06 01:59:36 +03:00
index ca44919..05730aa 100644
2022-08-05 15:59:38 +03:00
--- a/dvc/commands/init.py
+++ b/dvc/commands/init.py
@@ -3,7 +3,6 @@ import logging
import colorama
-from dvc import analytics
from dvc.cli.command import CmdBaseNoRepo
from dvc.cli.utils import append_doc_link
from dvc.utils import boxify
@@ -15,16 +14,6 @@ logger = logging.getLogger(__name__)
def _welcome_message():
from dvc.ui import ui
- if analytics.is_enabled():
- ui.write(
- boxify(
- "DVC has enabled anonymous aggregate usage analytics.\n"
- "Read the analytics documentation (and how to opt-out) here:\n"
- + fmt_link("https://dvc.org/doc/user-guide/analytics"),
- border_color="red",
- )
- )
-
msg = (
"{yellow}What's next?{nc}\n"
"{yellow}------------{nc}\n"
diff --git a/dvc/config_schema.py b/dvc/config_schema.py
2023-06-06 01:59:36 +03:00
index 2e36e90..3d9e402 100644
2022-08-05 15:59:38 +03:00
--- a/dvc/config_schema.py
+++ b/dvc/config_schema.py
2023-06-06 01:59:36 +03:00
@@ -144,7 +144,6 @@ SCHEMA = {
2022-08-05 15:59:38 +03:00
"remote": Lower,
"checksum_jobs": All(Coerce(int), Range(1)),
Optional("interactive", default=False): Bool,
- Optional("analytics", default=True): Bool,
Optional("hardlink_lock", default=False): Bool,
Optional("no_scm", default=False): Bool,
Optional("autostage", default=False): Bool,
2023-06-06 01:59:36 +03:00
diff --git a/dvc/env.py b/dvc/env.py
index 081ec9d..06c1332 100644
--- a/dvc/env.py
+++ b/dvc/env.py
@@ -7,7 +7,6 @@ DVC_EXP_GIT_REMOTE = "DVC_EXP_GIT_REMOTE"
DVC_EXP_NAME = "DVC_EXP_NAME"
DVC_GLOBAL_CONFIG_DIR = "DVC_GLOBAL_CONFIG_DIR"
DVC_IGNORE_ISATTY = "DVC_IGNORE_ISATTY"
-DVC_NO_ANALYTICS = "DVC_NO_ANALYTICS"
DVC_PAGER = "DVC_PAGER"
DVC_ROOT = "DVC_ROOT"
DVC_SHOW_TRACEBACK = "DVC_SHOW_TRACEBACK"