2016-05-17 01:53:22 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import logging
|
2016-11-03 05:23:27 +03:00
|
|
|
|
|
|
|
import time
|
2016-05-17 01:53:22 +03:00
|
|
|
import yaml
|
|
|
|
|
2018-10-29 14:11:46 +03:00
|
|
|
from . import GECKO
|
|
|
|
from .actions import render_actions_json
|
2018-10-29 13:18:13 +03:00
|
|
|
from .create import create_tasks
|
2018-10-29 14:11:46 +03:00
|
|
|
from .generator import TaskGraphGenerator
|
2018-01-27 00:09:35 +03:00
|
|
|
from .parameters import Parameters, get_version, get_app_version
|
2016-09-23 16:56:39 +03:00
|
|
|
from .taskgraph import TaskGraph
|
2017-08-22 02:14:14 +03:00
|
|
|
from .try_option_syntax import parse_message
|
2018-10-25 21:39:22 +03:00
|
|
|
from .util.schema import validate_schema, Schema
|
2018-10-29 14:11:46 +03:00
|
|
|
from taskgraph.util.hg import get_hg_revision_branch
|
|
|
|
from taskgraph.util.partials import populate_release_history
|
|
|
|
from taskgraph.util.yaml import load_yaml
|
2018-10-25 21:39:22 +03:00
|
|
|
from voluptuous import Required, Optional
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2018-10-29 14:11:46 +03:00
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2016-07-11 20:13:58 +03:00
|
|
|
ARTIFACTS_DIR = 'artifacts'
|
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
# For each project, this gives a set of parameters specific to the project.
|
|
|
|
# See `taskcluster/docs/parameters.rst` for information on parameters.
|
|
|
|
PER_PROJECT_PARAMETERS = {
|
|
|
|
'try': {
|
2017-06-27 23:33:20 +03:00
|
|
|
'target_tasks_method': 'try_tasks',
|
2016-05-18 00:27:11 +03:00
|
|
|
},
|
|
|
|
|
2017-11-03 00:02:49 +03:00
|
|
|
'try-comm-central': {
|
|
|
|
'target_tasks_method': 'try_tasks',
|
|
|
|
},
|
|
|
|
|
Bug 1281004: Specify test tasks more flexibly; r=gps; r=gbrown
This introduces a completely new way of specifying test task in-tree,
completely replacing the old spider-web of YAML files.
The high-level view is this:
- some configuration files are used to determine which test suites to run
for each test platform, and against which build platforms
- each test suite is then represented by a dictionary, and modified by a
sequence of transforms, duplicating as necessary (e.g., chunks), until
it becomes a task definition
The transforms allow sufficient generality to support just about any desired
configuration, with the advantage that common configurations are "easy" while
unusual configurations are supported but notable for their oddness (they
require a custom transform).
As of this commit, this system produces the same set of test graphs as the
existing YAML, modulo:
- extra.treeherder.groupName -- this was not consistent in the YAML
- extra.treeherder.build -- this is ignored by taskcluster-treeherder anyway
- mozharness command argument order
- boolean True values for environment variables are now the string "true"
- metadata -- this is now much more consistent, with task name being the label
Testing of this commit demonstrates that it produces the same set of test tasks for
the following projects (those which had special cases defined in the YAML):
- autoland
- ash (*)
- willow
- mozilla-inbound
- mozilla-central
- try:
-b do -p all -t all -u all
-b d -p linux64,linux64-asan -u reftest -t none
-b d -p linux64,linux64-asan -u reftest[x64] -t none[x64]
(*) this patch omits the linux64/debug tc-M-e10s(dt) test, which is enabled on
ash; ash will require a small changeset to re-enable this test.
IGNORE BAD COMMIT MESSAGES (because the hook flags try syntax!)
MozReview-Commit-ID: G34dg9f17Hq
--HG--
rename : taskcluster/taskgraph/kind/base.py => taskcluster/taskgraph/task/base.py
rename : taskcluster/taskgraph/kind/docker_image.py => taskcluster/taskgraph/task/docker_image.py
rename : taskcluster/taskgraph/kind/legacy.py => taskcluster/taskgraph/task/legacy.py
extra : rebase_source : 03e70902c2d3a297eb9e3ce852f8737c2550d5a6
extra : histedit_source : d4d9f4b192605af21f41d83495fc3c923759c3cb
2016-07-12 02:27:14 +03:00
|
|
|
'ash': {
|
|
|
|
'target_tasks_method': 'ash_tasks',
|
|
|
|
'optimize_target_tasks': True,
|
|
|
|
},
|
|
|
|
|
2016-11-08 17:22:17 +03:00
|
|
|
'cedar': {
|
|
|
|
'target_tasks_method': 'cedar_tasks',
|
|
|
|
'optimize_target_tasks': True,
|
|
|
|
},
|
|
|
|
|
2016-11-16 23:40:55 +03:00
|
|
|
'graphics': {
|
|
|
|
'target_tasks_method': 'graphics_tasks',
|
|
|
|
'optimize_target_tasks': True,
|
|
|
|
},
|
|
|
|
|
2018-10-23 22:11:31 +03:00
|
|
|
'mozilla-central': {
|
|
|
|
'target_tasks_method': 'default',
|
|
|
|
'optimize_target_tasks': True,
|
|
|
|
'release_type': 'nightly',
|
|
|
|
},
|
|
|
|
|
2017-02-22 21:24:58 +03:00
|
|
|
'mozilla-beta': {
|
|
|
|
'target_tasks_method': 'mozilla_beta_tasks',
|
2017-11-15 20:30:24 +03:00
|
|
|
'optimize_target_tasks': True,
|
2018-09-17 21:09:16 +03:00
|
|
|
'release_type': 'beta',
|
2017-02-22 21:24:58 +03:00
|
|
|
},
|
2017-03-10 03:32:41 +03:00
|
|
|
|
2017-02-22 21:24:58 +03:00
|
|
|
'mozilla-release': {
|
|
|
|
'target_tasks_method': 'mozilla_release_tasks',
|
2017-11-15 20:30:24 +03:00
|
|
|
'optimize_target_tasks': True,
|
2018-09-17 21:09:16 +03:00
|
|
|
'release_type': 'release',
|
2017-02-22 21:24:58 +03:00
|
|
|
},
|
|
|
|
|
2018-04-23 22:39:33 +03:00
|
|
|
'mozilla-esr60': {
|
|
|
|
'target_tasks_method': 'mozilla_esr60_tasks',
|
|
|
|
'optimize_target_tasks': True,
|
2018-09-17 21:09:16 +03:00
|
|
|
'release_type': 'esr60',
|
2018-04-23 22:39:33 +03:00
|
|
|
},
|
|
|
|
|
2018-10-25 21:04:10 +03:00
|
|
|
'comm-central': {
|
|
|
|
'target_tasks_method': 'default',
|
|
|
|
'optimize_target_tasks': True,
|
|
|
|
'release_type': 'nightly',
|
|
|
|
},
|
|
|
|
|
2018-05-31 20:38:14 +03:00
|
|
|
'comm-beta': {
|
|
|
|
'target_tasks_method': 'mozilla_beta_tasks',
|
|
|
|
'optimize_target_tasks': True,
|
2018-09-17 21:09:16 +03:00
|
|
|
'release_type': 'beta',
|
2018-05-31 20:38:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
'comm-esr60': {
|
2018-07-13 20:03:37 +03:00
|
|
|
'target_tasks_method': 'mozilla_esr60_tasks',
|
2018-05-31 20:38:14 +03:00
|
|
|
'optimize_target_tasks': True,
|
2018-09-17 21:09:16 +03:00
|
|
|
'release_type': 'release',
|
2018-05-31 20:38:14 +03:00
|
|
|
},
|
|
|
|
|
2017-02-24 18:19:04 +03:00
|
|
|
'pine': {
|
|
|
|
'target_tasks_method': 'pine_tasks',
|
|
|
|
'optimize_target_tasks': True,
|
|
|
|
},
|
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
# the default parameters are used for projects that do not match above.
|
|
|
|
'default': {
|
2016-09-12 21:41:58 +03:00
|
|
|
'target_tasks_method': 'default',
|
2016-06-05 22:49:41 +03:00
|
|
|
'optimize_target_tasks': True,
|
2016-05-18 00:27:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 21:39:22 +03:00
|
|
|
try_task_config_schema = Schema({
|
|
|
|
Required('tasks'): [basestring],
|
|
|
|
Optional('templates'): {basestring: object},
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
try_task_config_schema_v2 = Schema({
|
|
|
|
Optional('parameters'): {basestring: object},
|
|
|
|
})
|
|
|
|
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2017-12-01 00:05:53 +03:00
|
|
|
def full_task_graph_to_runnable_jobs(full_task_json):
|
|
|
|
runnable_jobs = {}
|
|
|
|
for label, node in full_task_json.iteritems():
|
|
|
|
if not ('extra' in node['task'] and 'treeherder' in node['task']['extra']):
|
|
|
|
continue
|
|
|
|
|
|
|
|
th = node['task']['extra']['treeherder']
|
|
|
|
runnable_jobs[label] = {
|
|
|
|
'symbol': th['symbol']
|
|
|
|
}
|
|
|
|
|
|
|
|
for i in ('groupName', 'groupSymbol', 'collection'):
|
|
|
|
if i in th:
|
|
|
|
runnable_jobs[label][i] = th[i]
|
|
|
|
if th.get('machine', {}).get('platform'):
|
|
|
|
runnable_jobs[label]['platform'] = th['machine']['platform']
|
|
|
|
return runnable_jobs
|
|
|
|
|
|
|
|
|
2017-10-25 01:28:19 +03:00
|
|
|
def taskgraph_decision(options, parameters=None):
|
2016-05-17 01:53:22 +03:00
|
|
|
"""
|
|
|
|
Run the decision task. This function implements `mach taskgraph decision`,
|
|
|
|
and is responsible for
|
|
|
|
|
|
|
|
* processing decision task command-line options into parameters
|
|
|
|
* running task-graph generation exactly the same way the other `mach
|
|
|
|
taskgraph` commands do
|
|
|
|
* generating a set of artifacts to memorialize the graph
|
|
|
|
* calling TaskCluster APIs to create the graph
|
|
|
|
"""
|
|
|
|
|
2018-10-02 02:37:53 +03:00
|
|
|
parameters = parameters or (lambda config: get_decision_parameters(config, options))
|
2017-09-18 15:36:36 +03:00
|
|
|
|
2016-05-17 01:53:22 +03:00
|
|
|
# create a TaskGraphGenerator instance
|
|
|
|
tgg = TaskGraphGenerator(
|
2017-10-25 01:28:19 +03:00
|
|
|
root_dir=options.get('root'),
|
2016-11-18 03:29:51 +03:00
|
|
|
parameters=parameters)
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
# write out the parameters used to generate this graph
|
2018-10-02 02:37:53 +03:00
|
|
|
write_artifact('parameters.yml', dict(**tgg.parameters))
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2017-02-01 02:34:05 +03:00
|
|
|
# write out the public/actions.json file
|
2018-10-02 02:37:53 +03:00
|
|
|
write_artifact('actions.json', render_actions_json(tgg.parameters, tgg.graph_config))
|
2017-02-01 02:34:05 +03:00
|
|
|
|
2016-05-17 01:53:22 +03:00
|
|
|
# write out the full graph for reference
|
2016-09-23 16:56:39 +03:00
|
|
|
full_task_json = tgg.full_task_graph.to_json()
|
|
|
|
write_artifact('full-task-graph.json', full_task_json)
|
|
|
|
|
2017-12-01 00:05:53 +03:00
|
|
|
# write out the public/runnable-jobs.json.gz file
|
|
|
|
write_artifact('runnable-jobs.json.gz', full_task_graph_to_runnable_jobs(full_task_json))
|
|
|
|
|
2016-09-23 16:56:39 +03:00
|
|
|
# this is just a test to check whether the from_json() function is working
|
|
|
|
_, _ = TaskGraph.from_json(full_task_json)
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
# write out the target task set to allow reproducing this as input
|
2016-06-07 06:09:48 +03:00
|
|
|
write_artifact('target-tasks.json', tgg.target_task_set.tasks.keys())
|
2016-05-17 01:53:22 +03:00
|
|
|
|
2016-06-05 22:49:41 +03:00
|
|
|
# write out the optimized task graph to describe what will actually happen,
|
|
|
|
# and the map of labels to taskids
|
2017-03-07 23:39:27 +03:00
|
|
|
write_artifact('task-graph.json', tgg.morphed_task_graph.to_json())
|
2016-06-05 22:49:41 +03:00
|
|
|
write_artifact('label-to-taskid.json', tgg.label_to_taskid)
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
# actually create the graph
|
2018-10-02 02:37:53 +03:00
|
|
|
create_tasks(tgg.morphed_task_graph, tgg.label_to_taskid, tgg.parameters)
|
2016-05-17 01:53:22 +03:00
|
|
|
|
|
|
|
|
2018-10-02 02:37:53 +03:00
|
|
|
def get_decision_parameters(config, options):
|
2016-05-18 00:27:11 +03:00
|
|
|
"""
|
|
|
|
Load parameters from the command-line options for 'taskgraph decision'.
|
|
|
|
This also applies per-project parameters, based on the given project.
|
|
|
|
|
|
|
|
"""
|
2018-10-02 02:37:53 +03:00
|
|
|
product_dir = config['product-dir']
|
2018-09-29 23:53:10 +03:00
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
parameters = {n: options[n] for n in [
|
|
|
|
'base_repository',
|
|
|
|
'head_repository',
|
|
|
|
'head_rev',
|
|
|
|
'head_ref',
|
|
|
|
'message',
|
|
|
|
'project',
|
|
|
|
'pushlog_id',
|
2016-07-13 21:50:50 +03:00
|
|
|
'pushdate',
|
2016-05-18 00:27:11 +03:00
|
|
|
'owner',
|
|
|
|
'level',
|
|
|
|
'target_tasks_method',
|
|
|
|
] if n in options}
|
|
|
|
|
2017-07-27 21:26:48 +03:00
|
|
|
for n in (
|
|
|
|
'comm_base_repository',
|
|
|
|
'comm_head_repository',
|
|
|
|
'comm_head_rev',
|
|
|
|
'comm_head_ref',
|
|
|
|
):
|
|
|
|
if n in options and options[n] is not None:
|
|
|
|
parameters[n] = options[n]
|
|
|
|
|
2016-11-18 02:53:30 +03:00
|
|
|
# Define default filter list, as most configurations shouldn't need
|
|
|
|
# custom filters.
|
|
|
|
parameters['filters'] = [
|
|
|
|
'target_tasks_method',
|
|
|
|
]
|
2017-10-25 01:28:19 +03:00
|
|
|
parameters['existing_tasks'] = {}
|
|
|
|
parameters['do_not_optimize'] = []
|
2017-11-09 02:52:48 +03:00
|
|
|
parameters['build_number'] = 1
|
2018-09-29 23:53:10 +03:00
|
|
|
parameters['version'] = get_version(product_dir)
|
|
|
|
parameters['app_version'] = get_app_version(product_dir)
|
2018-10-30 03:15:23 +03:00
|
|
|
parameters['hg_branch'] = get_hg_revision_branch(GECKO, revision=parameters['head_rev'])
|
2017-11-09 02:52:48 +03:00
|
|
|
parameters['next_version'] = None
|
2018-10-23 22:11:31 +03:00
|
|
|
parameters['release_type'] = ''
|
2018-01-18 17:10:53 +03:00
|
|
|
parameters['release_eta'] = ''
|
2018-04-17 05:48:40 +03:00
|
|
|
parameters['release_enable_partners'] = False
|
|
|
|
parameters['release_partners'] = []
|
|
|
|
parameters['release_partner_config'] = {}
|
|
|
|
parameters['release_partner_build_number'] = 1
|
|
|
|
parameters['release_enable_emefree'] = False
|
2018-05-03 03:33:52 +03:00
|
|
|
parameters['release_product'] = None
|
2018-10-17 20:15:54 +03:00
|
|
|
parameters['try_mode'] = None
|
|
|
|
parameters['try_task_config'] = None
|
|
|
|
parameters['try_options'] = None
|
2016-11-18 02:53:30 +03:00
|
|
|
|
2016-10-04 01:28:02 +03:00
|
|
|
# owner must be an email, but sometimes (e.g., for ffxbld) it is not, in which
|
|
|
|
# case, fake it
|
|
|
|
if '@' not in parameters['owner']:
|
|
|
|
parameters['owner'] += '@noreply.mozilla.org'
|
|
|
|
|
2016-11-03 05:23:27 +03:00
|
|
|
# use the pushdate as build_date if given, else use current time
|
|
|
|
parameters['build_date'] = parameters['pushdate'] or int(time.time())
|
|
|
|
# moz_build_date is the build identifier based on build_date
|
|
|
|
parameters['moz_build_date'] = time.strftime("%Y%m%d%H%M%S",
|
|
|
|
time.gmtime(parameters['build_date']))
|
|
|
|
|
2016-05-18 00:27:11 +03:00
|
|
|
project = parameters['project']
|
|
|
|
try:
|
|
|
|
parameters.update(PER_PROJECT_PARAMETERS[project])
|
|
|
|
except KeyError:
|
|
|
|
logger.warning("using default project parameters; add {} to "
|
2016-06-21 04:06:55 +03:00
|
|
|
"PER_PROJECT_PARAMETERS in {} to customize behavior "
|
|
|
|
"for this project".format(project, __file__))
|
2016-05-18 00:27:11 +03:00
|
|
|
parameters.update(PER_PROJECT_PARAMETERS['default'])
|
|
|
|
|
2016-09-02 20:29:07 +03:00
|
|
|
# `target_tasks_method` has higher precedence than `project` parameters
|
|
|
|
if options.get('target_tasks_method'):
|
|
|
|
parameters['target_tasks_method'] = options['target_tasks_method']
|
|
|
|
|
2017-09-18 15:36:36 +03:00
|
|
|
# If the target method is nightly, we should build partials. This means
|
|
|
|
# knowing what has been released previously.
|
|
|
|
# An empty release_history is fine, it just means no partials will be built
|
|
|
|
parameters.setdefault('release_history', dict())
|
|
|
|
if 'nightly' in parameters.get('target_tasks_method', ''):
|
|
|
|
parameters['release_history'] = populate_release_history('Firefox', project)
|
|
|
|
|
2017-11-21 21:26:56 +03:00
|
|
|
if options.get('try_task_config_file'):
|
|
|
|
task_config_file = os.path.abspath(options.get('try_task_config_file'))
|
|
|
|
else:
|
|
|
|
# if try_task_config.json is present, load it
|
|
|
|
task_config_file = os.path.join(os.getcwd(), 'try_task_config.json')
|
2017-08-22 02:14:14 +03:00
|
|
|
|
|
|
|
# load try settings
|
2017-11-03 00:02:49 +03:00
|
|
|
if 'try' in project:
|
2018-10-17 20:15:54 +03:00
|
|
|
set_try_config(parameters, task_config_file)
|
2017-08-22 02:14:14 +03:00
|
|
|
|
2018-10-17 20:15:54 +03:00
|
|
|
result = Parameters(**parameters)
|
|
|
|
result.check()
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def set_try_config(parameters, task_config_file):
|
|
|
|
if os.path.isfile(task_config_file):
|
|
|
|
logger.info("using try tasks from {}".format(task_config_file))
|
|
|
|
with open(task_config_file, 'r') as fh:
|
2018-10-17 02:04:03 +03:00
|
|
|
task_config = json.load(fh)
|
2018-10-25 21:39:22 +03:00
|
|
|
task_config_version = task_config.pop('version', 1)
|
2018-10-17 02:04:03 +03:00
|
|
|
if task_config_version == 1:
|
2018-10-25 21:39:22 +03:00
|
|
|
validate_schema(
|
|
|
|
try_task_config_schema, task_config,
|
|
|
|
"Invalid v1 `try_task_config.json`.",
|
|
|
|
)
|
2018-10-17 02:04:03 +03:00
|
|
|
parameters['try_mode'] = 'try_task_config'
|
|
|
|
parameters['try_task_config'] = task_config
|
|
|
|
elif task_config_version == 2:
|
2018-10-25 21:39:22 +03:00
|
|
|
validate_schema(
|
|
|
|
try_task_config_schema_v2, task_config,
|
|
|
|
"Invalid v1 `try_task_config.json`.",
|
|
|
|
)
|
2018-10-17 02:04:03 +03:00
|
|
|
parameters.update(task_config['parameters'])
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
raise Exception(
|
|
|
|
"Unknown `try_task_config.json` version: {}".format(task_config_version))
|
2018-10-17 20:15:54 +03:00
|
|
|
|
|
|
|
if 'try:' in parameters['message']:
|
|
|
|
parameters['try_mode'] = 'try_option_syntax'
|
|
|
|
args = parse_message(parameters['message'])
|
|
|
|
parameters['try_options'] = args
|
|
|
|
else:
|
2017-08-22 02:14:14 +03:00
|
|
|
parameters['try_options'] = None
|
|
|
|
|
2018-10-17 20:15:54 +03:00
|
|
|
if parameters['try_mode']:
|
|
|
|
# The user has explicitly requested a set of jobs, so run them all
|
|
|
|
# regardless of optimization. Their dependencies can be optimized,
|
|
|
|
# though.
|
|
|
|
parameters['optimize_target_tasks'] = False
|
|
|
|
else:
|
|
|
|
# For a try push with no task selection, apply the default optimization
|
|
|
|
# process to all of the tasks.
|
|
|
|
parameters['optimize_target_tasks'] = True
|
2016-05-18 00:27:11 +03:00
|
|
|
|
|
|
|
|
2016-05-18 21:02:51 +03:00
|
|
|
def write_artifact(filename, data):
|
|
|
|
logger.info('writing artifact file `{}`'.format(filename))
|
2016-05-17 01:53:22 +03:00
|
|
|
if not os.path.isdir(ARTIFACTS_DIR):
|
|
|
|
os.mkdir(ARTIFACTS_DIR)
|
|
|
|
path = os.path.join(ARTIFACTS_DIR, filename)
|
|
|
|
if filename.endswith('.yml'):
|
|
|
|
with open(path, 'w') as f:
|
|
|
|
yaml.safe_dump(data, f, allow_unicode=True, default_flow_style=False)
|
|
|
|
elif filename.endswith('.json'):
|
|
|
|
with open(path, 'w') as f:
|
|
|
|
json.dump(data, f, sort_keys=True, indent=2, separators=(',', ': '))
|
2017-12-01 00:05:53 +03:00
|
|
|
elif filename.endswith('.gz'):
|
|
|
|
import gzip
|
|
|
|
with gzip.open(path, 'wb') as f:
|
|
|
|
f.write(json.dumps(data))
|
2016-05-17 01:53:22 +03:00
|
|
|
else:
|
|
|
|
raise TypeError("Don't know how to write to {}".format(filename))
|
2018-07-24 20:21:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
def read_artifact(filename):
|
|
|
|
path = os.path.join(ARTIFACTS_DIR, filename)
|
|
|
|
if filename.endswith('.yml'):
|
2018-08-20 06:23:33 +03:00
|
|
|
return load_yaml(path, filename)
|
2018-07-24 20:21:51 +03:00
|
|
|
elif filename.endswith('.json'):
|
|
|
|
with open(path, 'r') as f:
|
|
|
|
return json.load(f)
|
|
|
|
elif filename.endswith('.gz'):
|
|
|
|
import gzip
|
|
|
|
with gzip.open(path, 'rb') as f:
|
|
|
|
return json.load(f)
|
|
|
|
else:
|
|
|
|
raise TypeError("Don't know how to read {}".format(filename))
|