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

analytics: refactor into a module #2826

Merged
merged 46 commits into from Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ef1f038
analytics: refactor into a module
Nov 20, 2019
b618d03
analytics: return OS when system info not supported
Nov 26, 2019
7d3cbd7
analytics: collect system info under the same module
Nov 26, 2019
64d102c
analytics: move user_id module to a method
Nov 26, 2019
2e7a6d3
:nail_care: sort methods
Nov 26, 2019
5cb437b
analytics: move to single file
Nov 26, 2019
610d1ee
analytics: go back to daemon implementation
Nov 26, 2019
d958870
analytics: exit_code -> return_code
Nov 26, 2019
34d3004
:face_palm: fix wrong module
Nov 26, 2019
5261ed7
tests: analytics.find_or_create_user_id
Nov 26, 2019
467b110
py2: FileNotFoundError -> IOError
Nov 27, 2019
48b4cba
:nail_care: change naming and docstring
Nov 27, 2019
6bc2403
:nail_care: black
Nov 27, 2019
f995204
tests: functional and unit tests for analytics
Nov 27, 2019
2a5cac5
:nail_care: deepsource
Nov 27, 2019
e9d56a9
:nail_care: sort imports
Nov 27, 2019
787ea9c
tests: set temporary global config
Nov 27, 2019
e69fffa
py2 compat issues :shrug:
Nov 28, 2019
656f986
:nail_care: correct wording "disenabled" -> "disabled"
Nov 28, 2019
946dfc1
analytics: send report without loading it to memory
Dec 2, 2019
5596015
analytics: document why tmp_global_config is needed
Dec 2, 2019
2c8e149
analytics: use fspath instead of str
Dec 3, 2019
ca485db
analytics: define report schema and use it on tests
Dec 3, 2019
e0d47a1
:nail_care: formatting
Dec 3, 2019
8b5ca25
analytics: move report schema to tests
Dec 3, 2019
8a32b28
analytics: collect and send on daemon
Dec 3, 2019
624cbb2
:nail_care: more specific comment about analytics
Dec 3, 2019
285620d
tests: mock analytics.collect while testing daemon
Dec 3, 2019
02eaa9a
py35: support for fspath(pathlib.Path())
Dec 4, 2019
ede0103
py2: use convert_to_unicode instead of str
Dec 5, 2019
7a3aae1
tests: add unit test for analytics.system_info
Dec 5, 2019
05a6868
tests: isolate global config from analytics tests
Dec 5, 2019
71ead3f
analytics: use a tempfile for inter-process communication
Dec 5, 2019
7e8bdbd
remove pathlib / fspath changes related to the patch
Dec 6, 2019
bc2471c
tests: adjust scm_class schema
Dec 6, 2019
c82d9dc
compat: bring back unicode literals
Dec 6, 2019
f704e54
tests: stringify tmp_global_config since it doesnt return a pathlike …
Dec 6, 2019
da064e2
analytics: remove the report after sending it
Dec 6, 2019
5a80334
tests: use str, builtin_str in schema
Dec 6, 2019
2145daa
analytics: define private methods
Dec 6, 2019
c50bd17
analytics: collect execution info only when available
Dec 8, 2019
146e75b
analytics: raise error when collecting a not supported os
Dec 8, 2019
c9f958d
analytics: AttributeError -> KeyError
Dec 8, 2019
3244f10
:nail_care: add dot to the end of the comment
Dec 8, 2019
6e4c3d6
tests: require keys on analytics report schema
Dec 8, 2019
5dd6300
:nail_care: black
Dec 8, 2019
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
256 changes: 0 additions & 256 deletions dvc/analytics.py

This file was deleted.

64 changes: 64 additions & 0 deletions dvc/analytics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import json
import logging
import requests
import subprocess
import tempfile

from dvc import __version__
from dvc.analytics import user_id, system_info
from dvc.config import Config, to_bool
from dvc.exceptions import NotDvcRepoError
from dvc.repo import Repo
from dvc.scm import SCM
from dvc.utils import env2bool, is_binary


logger = logging.getLogger(__name__)


def collect_and_send_report(arguments=None, exit_code=None):
report = {
"cmd_class": arguments.func.__name__,
"cmd_return_code": exit_code,
"dvc_version": __version__,
"is_binary": is_binary(),
"scm_class": scm_in_use(),
"system_info": system_info.collect(),
"user_id": user_id.find_or_create(),
}

with tempfile.NamedTemporaryFile(delete=False, mode="w") as fobj:
json.dump(report, fobj)
subprocess.Popen(["python", "-m", "dvc.analytics", fobj.name])


def send(path):
url = "https://analytics.dvc.org"

with open(path) as fobj:
report = json.load(fobj)

requests.post(url, json=report, timeout=5)


def is_enabled():
if env2bool("DVC_TEST"):
return False

enabled = to_bool(
Config(validate=False)
.config.get(Config.SECTION_CORE, {})
.get(Config.SECTION_CORE_ANALYTICS, "true")
)

logger.debug("Analytics is {}enabled.".format("" if enabled else "dis"))

return enabled


def scm_in_use():
try:
scm = SCM(root_dir=Repo.find_root())
return type(scm).__name__
except NotDvcRepoError:
pass
8 changes: 8 additions & 0 deletions dvc/analytics/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys

from dvc.analytics import send


if __name__ == "__main__":
report_fname = sys.argv[1]
This conversation was marked as resolved.
Show resolved Hide resolved
send(report_fname)
29 changes: 29 additions & 0 deletions dvc/analytics/system_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import platform
import sys
import distro


def collect():
system = platform.system()

if system == "Windows":
version = sys.getwindowsversion()

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 == "Darwing":
This conversation was marked as resolved.
Show resolved Hide resolved
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(),
}
This conversation was marked as resolved.
Show resolved Hide resolved
Loading