text stringlengths 0 828 |
|---|
self = cls.instances[name] = cls(name) |
self.writer.writerow((count, ""%f""%elapsed))" |
1367,"def dump(cls): |
""""""Output all recorded metrics"""""" |
with cls.lock: |
if not cls.instances: return |
atexit.unregister(cls.dump) |
for self in cls.instances.values(): |
self.fh.close()" |
1368,"def metric(self, name, count, elapsed): |
""""""A metric function that writes a single CSV file |
:arg str name: name of the metric |
:arg int count: number of items |
:arg float elapsed: time in seconds |
"""""" |
if name is None: |
warnings.warn(""Ignoring unnamed metric"", stacklevel=3) |
return |
with self.lock: |
self.writer.writerow((name, count, ""%f""%elapsed))" |
1369,"def dump(self): |
""""""Output all recorded metrics"""""" |
with self.lock: |
atexit.unregister(self.dump) |
self.fh.close()" |
1370,"def read(parts): |
"""""" |
Build an absolute path from parts array and and return the contents |
of the resulting file. Assume UTF-8 encoding. |
"""""" |
cur_dir = os.path.abspath(os.path.dirname(__file__)) |
with codecs.open(os.path.join(cur_dir, *parts), ""rb"", ""utf-8"") as f: |
return f.read()" |
1371,"def find_meta(meta): |
"""""" |
Extract __*meta*__ from META_FILE. |
"""""" |
meta_match = re.search( |
r""^__{meta}__ = ['\""]([^'\""]*)['\""]"".format(meta=meta), |
META_FILE, re.M |
) |
if meta_match: |
return meta_match.group(1) |
raise RuntimeError(""Unable to find __{meta}__ string."".format(meta=meta))" |
1372,"def ensure_clean_git(operation='operation'): |
"""""" Verify that git has no uncommitted changes """""" |
if os.system('git diff-index --quiet HEAD --'): |
print(""Unstaged or uncommitted changes detected. {} aborted."".format( |
operation.capitalize())) |
sys.exit()" |
1373,"def load(self): |
"""""" |
_load_ |
Load the defaults file if specified |
and overlay the json file on top of that |
"""""" |
if self._defaults_file is not None: |
if not os.path.exists(self._defaults_file): |
msg = ""Unable to find defaults file: {}"".format(self._defaults_file) |
LOGGER.error(msg) |
raise RuntimeError(msg) |
with open(self._defaults_file, 'r') as handle: |
self._defaults = json.load(handle) |
self.update(self._defaults) |
if self._settings_file is None: |
msg = ""No context file has been provided"" |
LOGGER.error(msg) |
raise RuntimeError(msg) |
if not os.path.exists(self._settings_file): |
msg = ""Unable to find settings file: {}"".format(self._settings_file) |
LOGGER.error(msg) |
raise RuntimeError(msg) |
with open(self._settings_file, 'r') as handle: |
settings = json.load(handle) |
update(self, settings) |
return" |
1374,"def check_var(var, var_types:Union[type, List[type]] =None, var_name=None, enforce_not_none:bool = True, |
allowed_values:Set = None, min_value = None, min_strict:bool = False, |
max_value = None, max_strict:bool = False, min_len:int = None, min_len_strict:bool = False, |
max_len:int = None, max_len_strict:bool = False): |
"""""" |
Helper method to check that an object has certain properties: |
* not none |
* a certain type |
* in some accepted values |
* in some accepted range |
:param var: the object to check |
:param var_types: the type(s) to enforce. If None, type will not be enforced |
:param var_name: the name of the varioable to be used in error messages |
:param enforce_not_none: boolean, default True. Whether to enforce that var is not None. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.