repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_documentation_string
stringlengths
1
47.2k
func_code_url
stringlengths
85
339
SiLab-Bonn/basil
basil/HL/GPAC.py
GPAC.set_current
def set_current(self, channel, value, unit='A'): '''Setting current of current source ''' dac_offset = self._ch_cal[channel]['DAC']['offset'] dac_gain = self._ch_cal[channel]['DAC']['gain'] if unit == 'raw': value = value elif unit == 'A': value = ...
python
def set_current(self, channel, value, unit='A'): '''Setting current of current source ''' dac_offset = self._ch_cal[channel]['DAC']['offset'] dac_gain = self._ch_cal[channel]['DAC']['gain'] if unit == 'raw': value = value elif unit == 'A': value = ...
Setting current of current source
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/GPAC.py#L858-L874
SiLab-Bonn/basil
basil/HL/MIO_PLL.py
MIO_PLL._calculateParameters
def _calculateParameters(self, fout): q_d_f = 0 ''' fout = fref * (p_total / q_total) * (1 / div) p_total = 2 * ((p_counter + 4) + p_0) [16..1023] q_total = q_counter + 2 [2..129] div = [2,(3),4..127] constraints: f_ref * p_total ...
python
def _calculateParameters(self, fout): q_d_f = 0 ''' fout = fref * (p_total / q_total) * (1 / div) p_total = 2 * ((p_counter + 4) + p_0) [16..1023] q_total = q_counter + 2 [2..129] div = [2,(3),4..127] constraints: f_ref * p_total ...
fout = fref * (p_total / q_total) * (1 / div) p_total = 2 * ((p_counter + 4) + p_0) [16..1023] q_total = q_counter + 2 [2..129] div = [2,(3),4..127] constraints: f_ref * p_total / q_total = [100..400] MHz f_ref / q_total > 0.25 MHz
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/MIO_PLL.py#L111-L180
SiLab-Bonn/basil
basil/TL/Visa.py
Visa.init
def init(self): ''' Initialize the device. Parameters of visa.ResourceManager().open_resource() ''' super(Visa, self).init() backend = self._init.get('backend', '') # Empty string means std. backend (NI VISA) rm = visa.ResourceManager(backend) try: ...
python
def init(self): ''' Initialize the device. Parameters of visa.ResourceManager().open_resource() ''' super(Visa, self).init() backend = self._init.get('backend', '') # Empty string means std. backend (NI VISA) rm = visa.ResourceManager(backend) try: ...
Initialize the device. Parameters of visa.ResourceManager().open_resource()
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/TL/Visa.py#L26-L38
SiLab-Bonn/basil
basil/HL/bram_fifo.py
bram_fifo.get_data
def get_data(self): ''' Reading data in BRAM. Returns ------- array : numpy.ndarray Array of unsigned integers (32 bit). ''' fifo_int_size_1 = self.FIFO_INT_SIZE fifo_int_size_2 = self.FIFO_INT_SIZE if fifo_int_size_1 > fifo_int_size_2: ...
python
def get_data(self): ''' Reading data in BRAM. Returns ------- array : numpy.ndarray Array of unsigned integers (32 bit). ''' fifo_int_size_1 = self.FIFO_INT_SIZE fifo_int_size_2 = self.FIFO_INT_SIZE if fifo_int_size_1 > fifo_int_size_2: ...
Reading data in BRAM. Returns ------- array : numpy.ndarray Array of unsigned integers (32 bit).
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/bram_fifo.py#L60-L75
SiLab-Bonn/basil
basil/utils/sim/SiLibUsbBusDriver.py
SiLibUsbBusDriver.read_external
def read_external(self, address): """Copied from silusb.sv testbench interface""" self.bus.RD_B <= 1 self.bus.ADD <= self._x self.bus.BUS_DATA <= self._high_impedence for _ in range(5): yield RisingEdge(self.clock) yield RisingEdge(self.clock) self.bu...
python
def read_external(self, address): """Copied from silusb.sv testbench interface""" self.bus.RD_B <= 1 self.bus.ADD <= self._x self.bus.BUS_DATA <= self._high_impedence for _ in range(5): yield RisingEdge(self.clock) yield RisingEdge(self.clock) self.bu...
Copied from silusb.sv testbench interface
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/sim/SiLibUsbBusDriver.py#L101-L130
SiLab-Bonn/basil
basil/utils/sim/SiLibUsbBusDriver.py
SiLibUsbBusDriver.write_external
def write_external(self, address, value): """Copied from silusb.sv testbench interface""" self.bus.WR_B <= 1 self.bus.ADD <= self._x for _ in range(5): yield RisingEdge(self.clock) yield RisingEdge(self.clock) self.bus.ADD <= address + 0x4000 self.bu...
python
def write_external(self, address, value): """Copied from silusb.sv testbench interface""" self.bus.WR_B <= 1 self.bus.ADD <= self._x for _ in range(5): yield RisingEdge(self.clock) yield RisingEdge(self.clock) self.bus.ADD <= address + 0x4000 self.bu...
Copied from silusb.sv testbench interface
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/sim/SiLibUsbBusDriver.py#L133-L168
SiLab-Bonn/basil
basil/HL/FEI4AdapterCard.py
AdcMax1239._setup_adc
def _setup_adc(self, flags): '''Initialize ADC ''' self._intf.write(self._base_addr + self.MAX_1239_ADD, array('B', pack('B', flags)))
python
def _setup_adc(self, flags): '''Initialize ADC ''' self._intf.write(self._base_addr + self.MAX_1239_ADD, array('B', pack('B', flags)))
Initialize ADC
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4AdapterCard.py#L45-L48
SiLab-Bonn/basil
basil/HL/FEI4AdapterCard.py
AdcMax1239._get_adc_value
def _get_adc_value(self, channel, average=None): '''Read ADC ''' conf = self.SCAN_OFF | self.SINGLE_ENDED | ((0x1e) & (channel << 1)) self._intf.write(self._base_addr + self.MAX_1239_ADD, array('B', pack('B', conf))) def read_data(): ret = self._intf.read(self._base_...
python
def _get_adc_value(self, channel, average=None): '''Read ADC ''' conf = self.SCAN_OFF | self.SINGLE_ENDED | ((0x1e) & (channel << 1)) self._intf.write(self._base_addr + self.MAX_1239_ADD, array('B', pack('B', conf))) def read_data(): ret = self._intf.read(self._base_...
Read ADC
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4AdapterCard.py#L50-L70
SiLab-Bonn/basil
basil/HL/FEI4AdapterCard.py
Eeprom24Lc128._read_eeprom
def _read_eeprom(self, address, size): '''Read EEPROM ''' self._intf.write(self._base_addr + self.CAL_EEPROM_ADD, array('B', pack('>H', address & 0x3FFF))) # 14-bit address, 16384 bytes n_pages, n_bytes = divmod(size, self.CAL_EEPROM_PAGE_SIZE) data = array('B') for _ i...
python
def _read_eeprom(self, address, size): '''Read EEPROM ''' self._intf.write(self._base_addr + self.CAL_EEPROM_ADD, array('B', pack('>H', address & 0x3FFF))) # 14-bit address, 16384 bytes n_pages, n_bytes = divmod(size, self.CAL_EEPROM_PAGE_SIZE) data = array('B') for _ i...
Read EEPROM
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4AdapterCard.py#L102-L115
SiLab-Bonn/basil
basil/HL/FEI4AdapterCard.py
Fei4Dcs.set_default
def set_default(self, channels=None): '''Setting default voltage ''' if not channels: channels = self._ch_cal.keys() for channel in channels: self.set_voltage(channel, self._ch_cal[channel]['default'], unit='V')
python
def set_default(self, channels=None): '''Setting default voltage ''' if not channels: channels = self._ch_cal.keys() for channel in channels: self.set_voltage(channel, self._ch_cal[channel]['default'], unit='V')
Setting default voltage
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4AdapterCard.py#L140-L146
SiLab-Bonn/basil
basil/HL/FEI4AdapterCard.py
Fei4Dcs.get_voltage
def get_voltage(self, channel, unit='V'): '''Reading voltage ''' kwargs = self._ch_map[channel]['ADCV'] voltage_raw = self._get_adc_value(**kwargs) voltage = (voltage_raw - self._ch_cal[channel]['ADCV']['offset']) / self._ch_cal[channel]['ADCV']['gain'] if unit == 'raw'...
python
def get_voltage(self, channel, unit='V'): '''Reading voltage ''' kwargs = self._ch_map[channel]['ADCV'] voltage_raw = self._get_adc_value(**kwargs) voltage = (voltage_raw - self._ch_cal[channel]['ADCV']['offset']) / self._ch_cal[channel]['ADCV']['gain'] if unit == 'raw'...
Reading voltage
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4AdapterCard.py#L165-L180
SiLab-Bonn/basil
basil/HL/FEI4AdapterCard.py
Fei4Dcs.get_current
def get_current(self, channel, unit='A'): '''Reading current ''' kwargs = self._ch_map[channel]['ADCI'] current_raw = self._get_adc_value(**kwargs) voltage = self.get_voltage(channel) current_raw_iq = current_raw - (self._ch_cal[channel]['ADCI']['iq_offset'] + self._ch_c...
python
def get_current(self, channel, unit='A'): '''Reading current ''' kwargs = self._ch_map[channel]['ADCI'] current_raw = self._get_adc_value(**kwargs) voltage = self.get_voltage(channel) current_raw_iq = current_raw - (self._ch_cal[channel]['ADCI']['iq_offset'] + self._ch_c...
Reading current
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4AdapterCard.py#L182-L203
SiLab-Bonn/basil
basil/HL/FEI4AdapterCard.py
FEI4AdapterCard.read_eeprom_calibration
def read_eeprom_calibration(self, temperature=False): # use default values for temperature, EEPROM values are usually not calibrated and random '''Reading EEPROM calibration for power regulators and temperature ''' header = self.get_format() if header == self.HEADER_V1: data...
python
def read_eeprom_calibration(self, temperature=False): # use default values for temperature, EEPROM values are usually not calibrated and random '''Reading EEPROM calibration for power regulators and temperature ''' header = self.get_format() if header == self.HEADER_V1: data...
Reading EEPROM calibration for power regulators and temperature
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4AdapterCard.py#L336-L366
SiLab-Bonn/basil
basil/HL/FEI4AdapterCard.py
FEI4AdapterCard.get_temperature
def get_temperature(self, channel, sensor='VNTC'): '''Reading temperature ''' # NTC type SEMITEC 103KT1608 http://www.semitec.co.jp/english/products/pdf/KT_Thermistor.pdf # # R_NTC = R_25 * exp(B_NTC * (1/T - 1/T_25)) # # R_NTC measured NTC resistance # R_NTC_25 ...
python
def get_temperature(self, channel, sensor='VNTC'): '''Reading temperature ''' # NTC type SEMITEC 103KT1608 http://www.semitec.co.jp/english/products/pdf/KT_Thermistor.pdf # # R_NTC = R_25 * exp(B_NTC * (1/T - 1/T_25)) # # R_NTC measured NTC resistance # R_NTC_25 ...
Reading temperature
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4AdapterCard.py#L368-L396
SiLab-Bonn/basil
basil/utils/DataManipulation.py
convert_data_array
def convert_data_array(arr, filter_func=None, converter_func=None): '''Filter and convert any given data array of any dtype. Parameters ---------- arr : numpy.array Data array of any dtype. filter_func : function Function that takes array and returns true or false for each i...
python
def convert_data_array(arr, filter_func=None, converter_func=None): '''Filter and convert any given data array of any dtype. Parameters ---------- arr : numpy.array Data array of any dtype. filter_func : function Function that takes array and returns true or false for each i...
Filter and convert any given data array of any dtype. Parameters ---------- arr : numpy.array Data array of any dtype. filter_func : function Function that takes array and returns true or false for each item in array. converter_func : function Function that takes ar...
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/DataManipulation.py#L11-L37
SiLab-Bonn/basil
basil/utils/DataManipulation.py
logical_and
def logical_and(f1, f2): # function factory '''Logical and from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function Examples -------- filter_func=logical_...
python
def logical_and(f1, f2): # function factory '''Logical and from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function Examples -------- filter_func=logical_...
Logical and from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function Examples -------- filter_func=logical_and(is_data_record, is_data_from_channel(4)) # new f...
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/DataManipulation.py#L44-L64
SiLab-Bonn/basil
basil/utils/DataManipulation.py
logical_or
def logical_or(f1, f2): # function factory '''Logical or from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function ''' def f_or(arr): return np.logical_o...
python
def logical_or(f1, f2): # function factory '''Logical or from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function ''' def f_or(arr): return np.logical_o...
Logical or from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/DataManipulation.py#L67-L82
SiLab-Bonn/basil
basil/utils/DataManipulation.py
logical_not
def logical_not(f): # function factory '''Logical not from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function ''' def f_not(arr): return np.logical_not...
python
def logical_not(f): # function factory '''Logical not from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function ''' def f_not(arr): return np.logical_not...
Logical not from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/DataManipulation.py#L85-L100
SiLab-Bonn/basil
basil/utils/DataManipulation.py
logical_xor
def logical_xor(f1, f2): # function factory '''Logical xor from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function ''' def f_xor(arr): return np.logica...
python
def logical_xor(f1, f2): # function factory '''Logical xor from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function ''' def f_xor(arr): return np.logica...
Logical xor from functions. Parameters ---------- f1, f2 : function Function that takes array and returns true or false for each item in array. Returns ------- Function
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/DataManipulation.py#L103-L118
SiLab-Bonn/basil
basil/utils/DataManipulation.py
arr_select
def arr_select(value): # function factory '''Selecting array elements by bitwise and comparison to a given value. Parameters: value : int Value to which array elements are compared to. Returns: array : np.array ''' def f_eq(arr): return np.equal(np.bitwise_and(a...
python
def arr_select(value): # function factory '''Selecting array elements by bitwise and comparison to a given value. Parameters: value : int Value to which array elements are compared to. Returns: array : np.array ''' def f_eq(arr): return np.equal(np.bitwise_and(a...
Selecting array elements by bitwise and comparison to a given value. Parameters: value : int Value to which array elements are compared to. Returns: array : np.array
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/DataManipulation.py#L121-L134
SiLab-Bonn/basil
basil/utils/DataManipulation.py
arr_astype
def arr_astype(arr_type): # function factory '''Change dtype of array. Parameters: arr_type : str, np.dtype Character codes (e.g. 'b', '>H'), type strings (e.g. 'i4', 'f8'), Python types (e.g. float, int) and numpy dtypes (e.g. np.uint32) are allowed. Returns: array : np.array ...
python
def arr_astype(arr_type): # function factory '''Change dtype of array. Parameters: arr_type : str, np.dtype Character codes (e.g. 'b', '>H'), type strings (e.g. 'i4', 'f8'), Python types (e.g. float, int) and numpy dtypes (e.g. np.uint32) are allowed. Returns: array : np.array ...
Change dtype of array. Parameters: arr_type : str, np.dtype Character codes (e.g. 'b', '>H'), type strings (e.g. 'i4', 'f8'), Python types (e.g. float, int) and numpy dtypes (e.g. np.uint32) are allowed. Returns: array : np.array
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/DataManipulation.py#L139-L152
SiLab-Bonn/basil
basil/utils/sim/Protocol.py
PickleInterface.send
def send(self, obj): """Prepend a 4-byte length to the string""" assert isinstance(obj, ProtocolBase) string = pickle.dumps(obj) length = len(string) self.sock.sendall(struct.pack("<I", length) + string)
python
def send(self, obj): """Prepend a 4-byte length to the string""" assert isinstance(obj, ProtocolBase) string = pickle.dumps(obj) length = len(string) self.sock.sendall(struct.pack("<I", length) + string)
Prepend a 4-byte length to the string
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/sim/Protocol.py#L57-L62
SiLab-Bonn/basil
basil/utils/sim/Protocol.py
PickleInterface.recv
def recv(self, blocking=True): """Receive the next object from the socket""" length = struct.unpack("<I", self.sock.recv(4))[0] return self._get_next_obj(length)
python
def recv(self, blocking=True): """Receive the next object from the socket""" length = struct.unpack("<I", self.sock.recv(4))[0] return self._get_next_obj(length)
Receive the next object from the socket
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/sim/Protocol.py#L64-L67
SiLab-Bonn/basil
basil/utils/sim/Protocol.py
PickleInterface.try_recv
def try_recv(self): """Return None immediately if nothing is waiting""" try: lenstr = self.sock.recv(4, socket.MSG_DONTWAIT) except socket.error: return None if len(lenstr) < 4: raise EOFError("Socket closed") length = struct.unpack("<I", lenst...
python
def try_recv(self): """Return None immediately if nothing is waiting""" try: lenstr = self.sock.recv(4, socket.MSG_DONTWAIT) except socket.error: return None if len(lenstr) < 4: raise EOFError("Socket closed") length = struct.unpack("<I", lenst...
Return None immediately if nothing is waiting
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/sim/Protocol.py#L69-L78
SiLab-Bonn/basil
basil/utils/sim/Protocol.py
PickleInterface._get_next_obj
def _get_next_obj(self, length): """Assumes we've already read the object length""" data = b'' while len(data) < length: data += self.sock.recv(length - len(data)) return pickle.loads(data)
python
def _get_next_obj(self, length): """Assumes we've already read the object length""" data = b'' while len(data) < length: data += self.sock.recv(length - len(data)) return pickle.loads(data)
Assumes we've already read the object length
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/sim/Protocol.py#L80-L86
SiLab-Bonn/basil
basil/dut.py
Dut.get_modules
def get_modules(self, type_name): '''Getting modules by type name. Parameters ---------- type_name : string Type name of the modules to be returned. Returns ------- List of modules of given type name else empty list. ''' modules = [] ...
python
def get_modules(self, type_name): '''Getting modules by type name. Parameters ---------- type_name : string Type name of the modules to be returned. Returns ------- List of modules of given type name else empty list. ''' modules = [] ...
Getting modules by type name. Parameters ---------- type_name : string Type name of the modules to be returned. Returns ------- List of modules of given type name else empty list.
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/dut.py#L288-L304
SiLab-Bonn/basil
basil/HL/sensirion_ekh4.py
sensirionEKH4.ask
def ask(self, command): '''Read response to command and convert it to 16-bit integer. Returns : list of values ''' self.write(command) time.sleep(0.1) return self.read()
python
def ask(self, command): '''Read response to command and convert it to 16-bit integer. Returns : list of values ''' self.write(command) time.sleep(0.1) return self.read()
Read response to command and convert it to 16-bit integer. Returns : list of values
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/sensirion_ekh4.py#L34-L40
SiLab-Bonn/basil
basil/HL/tti_ql355tp.py
ttiQl355tp.set_enable
def set_enable(self, on, channel=1): """ channel: 1=OP1, 2=OP2, 3=AUX, ALL=all channels""" if isinstance(channel, str): cmd = "OPALL %d" % int(on) elif isinstance(channel, int): cmd = "OP%d %d" % (channel, int(on)) self.write(cmd)
python
def set_enable(self, on, channel=1): """ channel: 1=OP1, 2=OP2, 3=AUX, ALL=all channels""" if isinstance(channel, str): cmd = "OPALL %d" % int(on) elif isinstance(channel, int): cmd = "OP%d %d" % (channel, int(on)) self.write(cmd)
channel: 1=OP1, 2=OP2, 3=AUX, ALL=all channels
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/tti_ql355tp.py#L41-L47
SiLab-Bonn/basil
basil/HL/tti_ql355tp.py
ttiQl355tp.get_current
def get_current(self, channel): """ channel: 1=OP1, 2=OP2, AUX is not supported""" ret = self.ask("I%dO?" % channel) if ret[-1] != "A": print("ttiQl355tp.get_current() format error", ret) return None return float(ret[:-1])
python
def get_current(self, channel): """ channel: 1=OP1, 2=OP2, AUX is not supported""" ret = self.ask("I%dO?" % channel) if ret[-1] != "A": print("ttiQl355tp.get_current() format error", ret) return None return float(ret[:-1])
channel: 1=OP1, 2=OP2, AUX is not supported
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/tti_ql355tp.py#L52-L58
SiLab-Bonn/basil
basil/HL/tti_ql355tp.py
ttiQl355tp.get_voltage
def get_voltage(self, channel): """ channel: 1=OP1, 2=OP2, AUX is not supported""" ret = self.ask("V%dO?" % channel) if ret[-1] != "V": print("ttiQl355tp.get_voltage() format error", ret) return None return float(ret[:-1])
python
def get_voltage(self, channel): """ channel: 1=OP1, 2=OP2, AUX is not supported""" ret = self.ask("V%dO?" % channel) if ret[-1] != "V": print("ttiQl355tp.get_voltage() format error", ret) return None return float(ret[:-1])
channel: 1=OP1, 2=OP2, AUX is not supported
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/tti_ql355tp.py#L60-L66
SiLab-Bonn/basil
basil/HL/tti_ql355tp.py
ttiQl355tp.get_set_voltage
def get_set_voltage(self, channel): """ channel: 1=OP1, 2=OP2, AUX is not supported""" ret = self.ask("V%d?" % channel) if ret[:3] != "V%d " % channel: print("ttiQl355tp.get_voltage() format error", ret) return None return float(ret[3:])
python
def get_set_voltage(self, channel): """ channel: 1=OP1, 2=OP2, AUX is not supported""" ret = self.ask("V%d?" % channel) if ret[:3] != "V%d " % channel: print("ttiQl355tp.get_voltage() format error", ret) return None return float(ret[3:])
channel: 1=OP1, 2=OP2, AUX is not supported
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/tti_ql355tp.py#L68-L74
SiLab-Bonn/basil
basil/HL/tti_ql355tp.py
ttiQl355tp.get_current_limit
def get_current_limit(self, channel): """ channel: 1=OP1, 2=OP2, AUX is not supported""" ret = self.ask("I%d?" % channel) if ret[:3] != "I%d " % channel: print("ttiQl355tp.get_current_limit() format error", ret) return None return float(ret[3:])
python
def get_current_limit(self, channel): """ channel: 1=OP1, 2=OP2, AUX is not supported""" ret = self.ask("I%d?" % channel) if ret[:3] != "I%d " % channel: print("ttiQl355tp.get_current_limit() format error", ret) return None return float(ret[3:])
channel: 1=OP1, 2=OP2, AUX is not supported
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/tti_ql355tp.py#L76-L82
SiLab-Bonn/basil
basil/HL/tti_ql355tp.py
ttiQl355tp.set_voltage
def set_voltage(self, value, channel=1): """ channel: 1=OP1, 2=OP2, AUX is not supported""" cmd = "V%d %f" % (channel, value) self.write(cmd)
python
def set_voltage(self, value, channel=1): """ channel: 1=OP1, 2=OP2, AUX is not supported""" cmd = "V%d %f" % (channel, value) self.write(cmd)
channel: 1=OP1, 2=OP2, AUX is not supported
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/tti_ql355tp.py#L84-L87
SiLab-Bonn/basil
basil/HL/tti_ql355tp.py
ttiQl355tp.set_current_limit
def set_current_limit(self, value, channel=1): """ channel: 1=OP1, 2=OP2, AUX is not supported""" cmd = "I%d %f" % (channel, value) self.write(cmd)
python
def set_current_limit(self, value, channel=1): """ channel: 1=OP1, 2=OP2, AUX is not supported""" cmd = "I%d %f" % (channel, value) self.write(cmd)
channel: 1=OP1, 2=OP2, AUX is not supported
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/tti_ql355tp.py#L89-L92
SiLab-Bonn/basil
basil/HL/HardwareLayer.py
HardwareLayer.wait_for_ready
def wait_for_ready(self, timeout=None, times=None, delay=None, delay_between=None, abort=None): '''Determine the ready state of the device and wait until device is ready. Parameters ---------- timeout : int, float The maximum amount of time to wait in seconds. Reaching the t...
python
def wait_for_ready(self, timeout=None, times=None, delay=None, delay_between=None, abort=None): '''Determine the ready state of the device and wait until device is ready. Parameters ---------- timeout : int, float The maximum amount of time to wait in seconds. Reaching the t...
Determine the ready state of the device and wait until device is ready. Parameters ---------- timeout : int, float The maximum amount of time to wait in seconds. Reaching the timeout will raise a RuntimeError. times : int Maximum number of times reading the ready...
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/HardwareLayer.py#L26-L71
SiLab-Bonn/basil
basil/HL/FEI4QuadModuleAdapterCard.py
DacMax5380._set_dac_value
def _set_dac_value(self, channel, value): '''Write DAC ''' self._intf.write(self._base_addr + self.MAX_5380_ADD, array('B', pack('B', value)))
python
def _set_dac_value(self, channel, value): '''Write DAC ''' self._intf.write(self._base_addr + self.MAX_5380_ADD, array('B', pack('B', value)))
Write DAC
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4QuadModuleAdapterCard.py#L32-L35
SiLab-Bonn/basil
basil/HL/FEI4QuadModuleAdapterCard.py
DacDs4424._set_dac_value
def _set_dac_value(self, channel, value): '''Write DAC ''' # DAC value cannot be -128 if value == -128: value = -127 if value < 0: sign = 1 else: sign = 0 value = (sign << 7) | (0x7F & abs(value)) self._intf.write(self._...
python
def _set_dac_value(self, channel, value): '''Write DAC ''' # DAC value cannot be -128 if value == -128: value = -127 if value < 0: sign = 1 else: sign = 0 value = (sign << 7) | (0x7F & abs(value)) self._intf.write(self._...
Write DAC
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4QuadModuleAdapterCard.py#L49-L60
SiLab-Bonn/basil
basil/HL/FEI4QuadModuleAdapterCard.py
FEI4QuadModuleAdapterCard.read_eeprom_calibration
def read_eeprom_calibration(self, temperature=False): # use default values for temperature, EEPROM values are usually not calibrated and random '''Reading EEPROM calibration for power regulators and temperature ''' header = self.get_format() if header == self.HEADER_V2: data...
python
def read_eeprom_calibration(self, temperature=False): # use default values for temperature, EEPROM values are usually not calibrated and random '''Reading EEPROM calibration for power regulators and temperature ''' header = self.get_format() if header == self.HEADER_V2: data...
Reading EEPROM calibration for power regulators and temperature
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4QuadModuleAdapterCard.py#L164-L191
SiLab-Bonn/basil
basil/HL/FEI4QuadModuleAdapterCard.py
FEI4QuadModuleAdapterCard.set_current_limit
def set_current_limit(self, channel, value, unit='A'): '''Setting current limit Note: same limit for all channels. ''' dac_offset = self._ch_cal[channel]['DACI']['offset'] dac_gain = self._ch_cal[channel]['DACI']['gain'] if unit == 'raw': value = value ...
python
def set_current_limit(self, channel, value, unit='A'): '''Setting current limit Note: same limit for all channels. ''' dac_offset = self._ch_cal[channel]['DACI']['offset'] dac_gain = self._ch_cal[channel]['DACI']['gain'] if unit == 'raw': value = value ...
Setting current limit Note: same limit for all channels.
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/FEI4QuadModuleAdapterCard.py#L226-L243
SiLab-Bonn/basil
basil/utils/sim/SiLibUsb.py
SiUSBDevice.DownloadXilinx
def DownloadXilinx(self, bitfile): """We hijack this call to perform the socket connect""" self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._sock.connect((self.simulation_host, self.simulation_port)) self._iface = PickleInterface(self._sock) return True
python
def DownloadXilinx(self, bitfile): """We hijack this call to perform the socket connect""" self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._sock.connect((self.simulation_host, self.simulation_port)) self._iface = PickleInterface(self._sock) return True
We hijack this call to perform the socket connect
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/utils/sim/SiLibUsb.py#L56-L61
SiLab-Bonn/basil
basil/HL/SussProber.py
SussProber.set_position
def set_position(self, x, y, speed=None): ''' Move chuck to absolute position in um''' if speed: self._intf.write('MoveChuckSubsite %1.1f %1.1f R Y %d' % (x, y, speed)) else: self._intf.write('MoveChuckSubsite %1.1f %1.1f R Y' % (x, y))
python
def set_position(self, x, y, speed=None): ''' Move chuck to absolute position in um''' if speed: self._intf.write('MoveChuckSubsite %1.1f %1.1f R Y %d' % (x, y, speed)) else: self._intf.write('MoveChuckSubsite %1.1f %1.1f R Y' % (x, y))
Move chuck to absolute position in um
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/SussProber.py#L20-L25
SiLab-Bonn/basil
basil/HL/SussProber.py
SussProber.move_position
def move_position(self, dx, dy, speed=None): ''' Move chuck relative to actual position in um''' if speed: self._intf.write('MoveChuckPosition %1.1f %1.1f R Y %d' % (dx, dy, speed)) else: self._intf.write('MoveChuckPosition %1.1f %1.1f R Y' % (dx, dy))
python
def move_position(self, dx, dy, speed=None): ''' Move chuck relative to actual position in um''' if speed: self._intf.write('MoveChuckPosition %1.1f %1.1f R Y %d' % (dx, dy, speed)) else: self._intf.write('MoveChuckPosition %1.1f %1.1f R Y' % (dx, dy))
Move chuck relative to actual position in um
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/SussProber.py#L27-L32
SiLab-Bonn/basil
basil/HL/SussProber.py
SussProber.get_position
def get_position(self): ''' Read chuck position (x, y, z)''' reply = self._intf.query('ReadChuckPosition Y H')[2:] return [float(i) for i in reply.split()]
python
def get_position(self): ''' Read chuck position (x, y, z)''' reply = self._intf.query('ReadChuckPosition Y H')[2:] return [float(i) for i in reply.split()]
Read chuck position (x, y, z)
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/SussProber.py#L34-L37
SiLab-Bonn/basil
basil/HL/SussProber.py
SussProber.get_die
def get_die(self): ''' Move chuck to wafer map chip index''' reply = self._intf.query('ReadMapPosition') values = reply[2:].split(' ') return (int(values[0]), int(values[1]))
python
def get_die(self): ''' Move chuck to wafer map chip index''' reply = self._intf.query('ReadMapPosition') values = reply[2:].split(' ') return (int(values[0]), int(values[1]))
Move chuck to wafer map chip index
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/SussProber.py#L51-L55
SiLab-Bonn/basil
basil/RL/TrackRegister.py
TrackRegister.clear
def clear(self): 'Clear tracks in memory - all zero' for track in self._tracks: self._tracks[track].setall(False)
python
def clear(self): 'Clear tracks in memory - all zero' for track in self._tracks: self._tracks[track].setall(False)
Clear tracks in memory - all zero
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/RL/TrackRegister.py#L38-L41
SiLab-Bonn/basil
basil/HL/sitcp_fifo.py
sitcp_fifo.get_data
def get_data(self): ''' Reading data from SiTCP FIFO (via TCP). Returns ------- array : numpy.ndarray Array of unsigned integers (32 bit). ''' fifo_size = self._intf._get_tcp_data_size() fifo_int_size = int((fifo_size - (fifo_size % 4)) / 4) d...
python
def get_data(self): ''' Reading data from SiTCP FIFO (via TCP). Returns ------- array : numpy.ndarray Array of unsigned integers (32 bit). ''' fifo_size = self._intf._get_tcp_data_size() fifo_int_size = int((fifo_size - (fifo_size % 4)) / 4) d...
Reading data from SiTCP FIFO (via TCP). Returns ------- array : numpy.ndarray Array of unsigned integers (32 bit).
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/sitcp_fifo.py#L61-L72
SiLab-Bonn/basil
basil/HL/sitcp_fifo.py
sitcp_fifo.set_data
def set_data(self, data): ''' Sending data to via TCP. Parameters ---------- data : array Array of unsigned integers (32 bit). ''' data = array.array('B', struct.unpack("{}B".format(len(data) * 4), struct.pack("{}I".format(len(data)), *data))) self._i...
python
def set_data(self, data): ''' Sending data to via TCP. Parameters ---------- data : array Array of unsigned integers (32 bit). ''' data = array.array('B', struct.unpack("{}B".format(len(data) * 4), struct.pack("{}I".format(len(data)), *data))) self._i...
Sending data to via TCP. Parameters ---------- data : array Array of unsigned integers (32 bit).
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/sitcp_fifo.py#L74-L83
SiLab-Bonn/basil
examples/mio_pixel/pixel.py
Pixel.program_global_reg
def program_global_reg(self): """ Send the global register to the chip. Loads the values of self['GLOBAL_REG'] onto the chip. Includes enabling the clock, and loading the Control (CTR) and DAC shadow registers. """ self._clear_strobes() gr_size = len(s...
python
def program_global_reg(self): """ Send the global register to the chip. Loads the values of self['GLOBAL_REG'] onto the chip. Includes enabling the clock, and loading the Control (CTR) and DAC shadow registers. """ self._clear_strobes() gr_size = len(s...
Send the global register to the chip. Loads the values of self['GLOBAL_REG'] onto the chip. Includes enabling the clock, and loading the Control (CTR) and DAC shadow registers.
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/examples/mio_pixel/pixel.py#L24-L44
SiLab-Bonn/basil
examples/mio_pixel/pixel.py
Pixel.program_pixel_reg
def program_pixel_reg(self, enable_receiver=True): """ Send the pixel register to the chip and store the output. Loads the values of self['PIXEL_REG'] onto the chip. Includes enabling the clock, and loading the Control (CTR) and DAC shadow registers. if(enable_receiver)...
python
def program_pixel_reg(self, enable_receiver=True): """ Send the pixel register to the chip and store the output. Loads the values of self['PIXEL_REG'] onto the chip. Includes enabling the clock, and loading the Control (CTR) and DAC shadow registers. if(enable_receiver)...
Send the pixel register to the chip and store the output. Loads the values of self['PIXEL_REG'] onto the chip. Includes enabling the clock, and loading the Control (CTR) and DAC shadow registers. if(enable_receiver), stores the output (by byte) in self['DATA'], retrievable via ...
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/examples/mio_pixel/pixel.py#L46-L68
SiLab-Bonn/basil
examples/mio_pixel/pixel.py
Pixel._run_seq
def _run_seq(self, size): """ Send the contents of self['SEQ'] to the chip and wait until it finishes. """ # Write the sequence to the sequence generator (hw driver) self['SEQ'].write(size) # write pattern to memory self['SEQ'].set_size(size) # set size self[...
python
def _run_seq(self, size): """ Send the contents of self['SEQ'] to the chip and wait until it finishes. """ # Write the sequence to the sequence generator (hw driver) self['SEQ'].write(size) # write pattern to memory self['SEQ'].set_size(size) # set size self[...
Send the contents of self['SEQ'] to the chip and wait until it finishes.
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/examples/mio_pixel/pixel.py#L70-L84
SiLab-Bonn/basil
basil/HL/i2c.py
i2c.write
def write(self, addr, data): '''Write access. :param addr: i2c slave address :type addr: char :param data: array/list of bytes :type data: iterable :rtype: None ''' self.set_addr(addr & 0xfe) self.set_data(data) self.set_size(...
python
def write(self, addr, data): '''Write access. :param addr: i2c slave address :type addr: char :param data: array/list of bytes :type data: iterable :rtype: None ''' self.set_addr(addr & 0xfe) self.set_data(data) self.set_size(...
Write access. :param addr: i2c slave address :type addr: char :param data: array/list of bytes :type data: iterable :rtype: None
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/i2c.py#L93-L108
SiLab-Bonn/basil
basil/HL/i2c.py
i2c.read
def read(self, addr, size): '''Read access. :param addr: i2c slave address :type addr: char :param size: size of transfer :type size: int :returns: data byte array :rtype: array.array('B') ''' self.set_addr(addr | 0x01) self.s...
python
def read(self, addr, size): '''Read access. :param addr: i2c slave address :type addr: char :param size: size of transfer :type size: int :returns: data byte array :rtype: array.array('B') ''' self.set_addr(addr | 0x01) self.s...
Read access. :param addr: i2c slave address :type addr: char :param size: size of transfer :type size: int :returns: data byte array :rtype: array.array('B')
https://github.com/SiLab-Bonn/basil/blob/99052482d9334dd1f5598eb2d2fb4d5399a32291/basil/HL/i2c.py#L110-L127
riga/law
law/parser.py
full_parser
def full_parser(): """ Returns the full *ArgumentParser* used by the luigi ``CmdlineParser``. The returned instance is cached. """ global _full_parser if _full_parser: return _full_parser luigi_parser = luigi.cmdline_parser.CmdlineParser.get_instance() if not luigi_parser: ...
python
def full_parser(): """ Returns the full *ArgumentParser* used by the luigi ``CmdlineParser``. The returned instance is cached. """ global _full_parser if _full_parser: return _full_parser luigi_parser = luigi.cmdline_parser.CmdlineParser.get_instance() if not luigi_parser: ...
Returns the full *ArgumentParser* used by the luigi ``CmdlineParser``. The returned instance is cached.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/parser.py#L27-L47
riga/law
law/parser.py
root_task_parser
def root_task_parser(): """ Returns a new *ArgumentParser* instance that only contains paremeter actions of the root task. The returned instance is cached. """ global _root_task_parser if _root_task_parser: return _root_task_parser luigi_parser = luigi.cmdline_parser.CmdlineParser....
python
def root_task_parser(): """ Returns a new *ArgumentParser* instance that only contains paremeter actions of the root task. The returned instance is cached. """ global _root_task_parser if _root_task_parser: return _root_task_parser luigi_parser = luigi.cmdline_parser.CmdlineParser....
Returns a new *ArgumentParser* instance that only contains paremeter actions of the root task. The returned instance is cached.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/parser.py#L50-L80
riga/law
law/parser.py
global_cmdline_args
def global_cmdline_args(): """ Returns the list of command line arguments that do not belong to the root task. The returned list is cached. Example: .. code-block:: python global_cmdline_args() # -> ["--local-scheduler"] """ global _global_cmdline_args if _global_cmdline_a...
python
def global_cmdline_args(): """ Returns the list of command line arguments that do not belong to the root task. The returned list is cached. Example: .. code-block:: python global_cmdline_args() # -> ["--local-scheduler"] """ global _global_cmdline_args if _global_cmdline_a...
Returns the list of command line arguments that do not belong to the root task. The returned list is cached. Example: .. code-block:: python global_cmdline_args() # -> ["--local-scheduler"]
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/parser.py#L83-L104
riga/law
law/parser.py
global_cmdline_values
def global_cmdline_values(): """ Returns a dictionary of global command line arguments (computed with :py:func:`global_cmdline_args`) to their current values. The returnd dictionary is cached. Example: .. code-block:: python global_cmdline_values() # -> {"core_local_scheduler": Tru...
python
def global_cmdline_values(): """ Returns a dictionary of global command line arguments (computed with :py:func:`global_cmdline_args`) to their current values. The returnd dictionary is cached. Example: .. code-block:: python global_cmdline_values() # -> {"core_local_scheduler": Tru...
Returns a dictionary of global command line arguments (computed with :py:func:`global_cmdline_args`) to their current values. The returnd dictionary is cached. Example: .. code-block:: python global_cmdline_values() # -> {"core_local_scheduler": True}
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/parser.py#L107-L136
riga/law
law/parser.py
add_cmdline_arg
def add_cmdline_arg(args, arg, *values): """ Adds a command line argument *arg* to a list of argument *args*, e.g. as returned from :py:func:`global_cmdline_args`. When *arg* exists, *args* is returned unchanged. Otherwise, *arg* is appended to the end with optional argument *values*. Example: .. c...
python
def add_cmdline_arg(args, arg, *values): """ Adds a command line argument *arg* to a list of argument *args*, e.g. as returned from :py:func:`global_cmdline_args`. When *arg* exists, *args* is returned unchanged. Otherwise, *arg* is appended to the end with optional argument *values*. Example: .. c...
Adds a command line argument *arg* to a list of argument *args*, e.g. as returned from :py:func:`global_cmdline_args`. When *arg* exists, *args* is returned unchanged. Otherwise, *arg* is appended to the end with optional argument *values*. Example: .. code-block:: python args = global_cmdline_val...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/parser.py#L139-L158
riga/law
law/parser.py
remove_cmdline_arg
def remove_cmdline_arg(args, arg, n=1): """ Removes the command line argument *args* from a list of arguments *args*, e.g. as returned from :py:func:`global_cmdline_args`. When *n* is 1 or less, only the argument is removed. Otherwise, the following *n-1* values are removed. Example: .. code-block:...
python
def remove_cmdline_arg(args, arg, n=1): """ Removes the command line argument *args* from a list of arguments *args*, e.g. as returned from :py:func:`global_cmdline_args`. When *n* is 1 or less, only the argument is removed. Otherwise, the following *n-1* values are removed. Example: .. code-block:...
Removes the command line argument *args* from a list of arguments *args*, e.g. as returned from :py:func:`global_cmdline_args`. When *n* is 1 or less, only the argument is removed. Otherwise, the following *n-1* values are removed. Example: .. code-block:: python args = global_cmdline_values() ...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/parser.py#L161-L182
riga/law
law/target/file.py
split_transfer_kwargs
def split_transfer_kwargs(kwargs, skip=None): """ Takes keyword arguments *kwargs*, splits them into two separate dictionaries depending on their content, and returns them in a tuple. The first one will contain arguments related to potential file transfer operations (e.g. ``"cache"`` or ``"retries"``), ...
python
def split_transfer_kwargs(kwargs, skip=None): """ Takes keyword arguments *kwargs*, splits them into two separate dictionaries depending on their content, and returns them in a tuple. The first one will contain arguments related to potential file transfer operations (e.g. ``"cache"`` or ``"retries"``), ...
Takes keyword arguments *kwargs*, splits them into two separate dictionaries depending on their content, and returns them in a tuple. The first one will contain arguments related to potential file transfer operations (e.g. ``"cache"`` or ``"retries"``), while the second one will contain all remaining argume...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/target/file.py#L323-L337
riga/law
law/workflow/remote.py
SubmissionData.job_data
def job_data(cls, job_id=dummy_job_id, branches=None, **kwargs): """ Returns a dictionary containing default job submission information such as the *job_id* and task *branches* covered by the job. """ return dict(job_id=job_id, branches=branches or [])
python
def job_data(cls, job_id=dummy_job_id, branches=None, **kwargs): """ Returns a dictionary containing default job submission information such as the *job_id* and task *branches* covered by the job. """ return dict(job_id=job_id, branches=branches or [])
Returns a dictionary containing default job submission information such as the *job_id* and task *branches* covered by the job.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L51-L56
riga/law
law/workflow/remote.py
StatusData.job_data
def job_data(cls, job_id=dummy_job_id, status=None, code=None, error=None, **kwargs): """ Returns a dictionary containing default job status information such as the *job_id*, a job *status* string, a job return code, and an *error* message. """ return dict(job_id=job_id, status=s...
python
def job_data(cls, job_id=dummy_job_id, status=None, code=None, error=None, **kwargs): """ Returns a dictionary containing default job status information such as the *job_id*, a job *status* string, a job return code, and an *error* message. """ return dict(job_id=job_id, status=s...
Returns a dictionary containing default job status information such as the *job_id*, a job *status* string, a job return code, and an *error* message.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L91-L96
riga/law
law/workflow/remote.py
BaseRemoteWorkflowProxy._get_task_attribute
def _get_task_attribute(self, name, fallback=False): """ Return an attribute of the actial task named ``<workflow_type>_<name>``. When the attribute does not exist and *fallback* is *True*, try to return the task attribute simply named *name*. In any case, if a requested task attribute i...
python
def _get_task_attribute(self, name, fallback=False): """ Return an attribute of the actial task named ``<workflow_type>_<name>``. When the attribute does not exist and *fallback* is *True*, try to return the task attribute simply named *name*. In any case, if a requested task attribute i...
Return an attribute of the actial task named ``<workflow_type>_<name>``. When the attribute does not exist and *fallback* is *True*, try to return the task attribute simply named *name*. In any case, if a requested task attribute is eventually not found, an AttributeError is raised.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L258-L270
riga/law
law/workflow/remote.py
BaseRemoteWorkflowProxy.output
def output(self): """ Returns the default workflow outputs in an ordered dictionary. At the moment, this is the collection of outputs of the branch tasks (key ``"collection"``), the submission file (key ``"submission"``), and the status file (key ``"status"``). These two *control outputs...
python
def output(self): """ Returns the default workflow outputs in an ordered dictionary. At the moment, this is the collection of outputs of the branch tasks (key ``"collection"``), the submission file (key ``"submission"``), and the status file (key ``"status"``). These two *control outputs...
Returns the default workflow outputs in an ordered dictionary. At the moment, this is the collection of outputs of the branch tasks (key ``"collection"``), the submission file (key ``"submission"``), and the status file (key ``"status"``). These two *control outputs* are optional, i.e., they are...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L282-L313
riga/law
law/workflow/remote.py
BaseRemoteWorkflowProxy.dump_submission_data
def dump_submission_data(self): """ Dumps the current submission data to the submission file. """ # renew the dashboard config self.submission_data["dashboard_config"] = self.dashboard.get_persistent_config() # write the submission data to the output file self._o...
python
def dump_submission_data(self): """ Dumps the current submission data to the submission file. """ # renew the dashboard config self.submission_data["dashboard_config"] = self.dashboard.get_persistent_config() # write the submission data to the output file self._o...
Dumps the current submission data to the submission file.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L315-L323
riga/law
law/workflow/remote.py
BaseRemoteWorkflowProxy.run
def run(self): """ Actual run method that starts the processing of jobs and initiates the status polling, or performs job cancelling or cleaning, depending on the task parameters. """ task = self.task self._outputs = self.output() # create the job dashboard inter...
python
def run(self): """ Actual run method that starts the processing of jobs and initiates the status polling, or performs job cancelling or cleaning, depending on the task parameters. """ task = self.task self._outputs = self.output() # create the job dashboard inter...
Actual run method that starts the processing of jobs and initiates the status polling, or performs job cancelling or cleaning, depending on the task parameters.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L326-L400
riga/law
law/workflow/remote.py
BaseRemoteWorkflowProxy.cancel
def cancel(self): """ Cancels running jobs. The job ids are read from the submission file which has to exist for obvious reasons. """ task = self.task # get job ids from submission data job_ids = [ d["job_id"] for d in self.submission_data.jobs.values...
python
def cancel(self): """ Cancels running jobs. The job ids are read from the submission file which has to exist for obvious reasons. """ task = self.task # get job ids from submission data job_ids = [ d["job_id"] for d in self.submission_data.jobs.values...
Cancels running jobs. The job ids are read from the submission file which has to exist for obvious reasons.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L402-L436
riga/law
law/workflow/remote.py
BaseRemoteWorkflowProxy.cleanup
def cleanup(self): """ Cleans up jobs on the remote run location. The job ids are read from the submission file which has to exist for obvious reasons. """ task = self.task # get job ids from submission data job_ids = [ d["job_id"] for d in self.submi...
python
def cleanup(self): """ Cleans up jobs on the remote run location. The job ids are read from the submission file which has to exist for obvious reasons. """ task = self.task # get job ids from submission data job_ids = [ d["job_id"] for d in self.submi...
Cleans up jobs on the remote run location. The job ids are read from the submission file which has to exist for obvious reasons.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L438-L468
riga/law
law/workflow/remote.py
BaseRemoteWorkflowProxy.submit
def submit(self, retry_jobs=None): """ Submits all jobs. When *retry_jobs* is *None*, a new job list is built. Otherwise, previously failed jobs defined in the *retry_jobs* dictionary, which maps job numbers to lists of branch numbers, are used. """ task = self.task ...
python
def submit(self, retry_jobs=None): """ Submits all jobs. When *retry_jobs* is *None*, a new job list is built. Otherwise, previously failed jobs defined in the *retry_jobs* dictionary, which maps job numbers to lists of branch numbers, are used. """ task = self.task ...
Submits all jobs. When *retry_jobs* is *None*, a new job list is built. Otherwise, previously failed jobs defined in the *retry_jobs* dictionary, which maps job numbers to lists of branch numbers, are used.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L470-L597
riga/law
law/workflow/remote.py
BaseRemoteWorkflowProxy.poll
def poll(self): """ Initiates the job status polling loop. """ task = self.task # total job count n_jobs = len(self.submission_data) # store the number of consecutive polling failures and get the maximum number of polls n_poll_fails = 0 if task.w...
python
def poll(self): """ Initiates the job status polling loop. """ task = self.task # total job count n_jobs = len(self.submission_data) # store the number of consecutive polling failures and get the maximum number of polls n_poll_fails = 0 if task.w...
Initiates the job status polling loop.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L599-L781
riga/law
law/workflow/remote.py
BaseRemoteWorkflowProxy.touch_control_outputs
def touch_control_outputs(self): """ Creates and saves dummy submission and status files. This method is called in case the collection of branch task outputs exists. """ task = self.task # create the parent directory self._outputs["submission"].parent.touch() ...
python
def touch_control_outputs(self): """ Creates and saves dummy submission and status files. This method is called in case the collection of branch task outputs exists. """ task = self.task # create the parent directory self._outputs["submission"].parent.touch() ...
Creates and saves dummy submission and status files. This method is called in case the collection of branch task outputs exists.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L783-L814
riga/law
law/workflow/remote.py
BaseRemoteWorkflow.forward_dashboard_event
def forward_dashboard_event(self, dashboard, job_data, event, job_num): """ Hook to preprocess and publish dashboard events. By default, every event is passed to the dashboard's :py:meth:`law.job.dashboard.BaseJobDashboard.publish` method unchanged. """ # possible events: ...
python
def forward_dashboard_event(self, dashboard, job_data, event, job_num): """ Hook to preprocess and publish dashboard events. By default, every event is passed to the dashboard's :py:meth:`law.job.dashboard.BaseJobDashboard.publish` method unchanged. """ # possible events: ...
Hook to preprocess and publish dashboard events. By default, every event is passed to the dashboard's :py:meth:`law.job.dashboard.BaseJobDashboard.publish` method unchanged.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/workflow/remote.py#L973-L987
riga/law
law/target/local.py
LocalFileTarget.localize
def localize(self, mode="r", perm=None, parent_perm=None, **kwargs): """ localize(mode="r", perm=None, parent_perm=None, skip_copy=False, is_tmp=None, **kwargs) """ if mode not in ("r", "w"): raise Exception("unknown mode '{}', use r or w".format(mode)) # get additional argu...
python
def localize(self, mode="r", perm=None, parent_perm=None, **kwargs): """ localize(mode="r", perm=None, parent_perm=None, skip_copy=False, is_tmp=None, **kwargs) """ if mode not in ("r", "w"): raise Exception("unknown mode '{}', use r or w".format(mode)) # get additional argu...
localize(mode="r", perm=None, parent_perm=None, skip_copy=False, is_tmp=None, **kwargs)
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/target/local.py#L252-L309
riga/law
law/cli/index.py
setup_parser
def setup_parser(sub_parsers): """ Sets up the command line parser for the *index* subprogram and adds it to *sub_parsers*. """ parser = sub_parsers.add_parser("index", prog="law index", description="Create or update the" " (human-readable) law task index file ({}). This is only required for the...
python
def setup_parser(sub_parsers): """ Sets up the command line parser for the *index* subprogram and adds it to *sub_parsers*. """ parser = sub_parsers.add_parser("index", prog="law index", description="Create or update the" " (human-readable) law task index file ({}). This is only required for the...
Sets up the command line parser for the *index* subprogram and adds it to *sub_parsers*.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/cli/index.py#L22-L36
riga/law
law/cli/index.py
execute
def execute(args): """ Executes the *index* subprogram with parsed commandline *args*. """ index_file = Config.instance().get_expanded("core", "index_file") # just print the file location? if args.location: print(index_file) return # just remove the index file? if args....
python
def execute(args): """ Executes the *index* subprogram with parsed commandline *args*. """ index_file = Config.instance().get_expanded("core", "index_file") # just print the file location? if args.location: print(index_file) return # just remove the index file? if args....
Executes the *index* subprogram with parsed commandline *args*.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/cli/index.py#L39-L155
riga/law
law/cli/index.py
get_global_parameters
def get_global_parameters(config_names=("core", "scheduler", "worker", "retcode")): """ Returns a list of global, luigi-internal configuration parameters. Each list item is a 4-tuple containing the configuration class, the parameter instance, the parameter name, and the full parameter name in the cli. W...
python
def get_global_parameters(config_names=("core", "scheduler", "worker", "retcode")): """ Returns a list of global, luigi-internal configuration parameters. Each list item is a 4-tuple containing the configuration class, the parameter instance, the parameter name, and the full parameter name in the cli. W...
Returns a list of global, luigi-internal configuration parameters. Each list item is a 4-tuple containing the configuration class, the parameter instance, the parameter name, and the full parameter name in the cli. When *config_names* is set, it should be a list of configuration class names that are exclusi...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/cli/index.py#L158-L181
riga/law
law/util.py
rel_path
def rel_path(anchor, *paths): """ Returns a path made of framgment *paths* relativ to an *anchor* path. When *anchor* is a file, its absolute directory is used instead. """ anchor = os.path.abspath(os.path.expandvars(os.path.expanduser(anchor))) if os.path.exists(anchor) and os.path.isfile(ancho...
python
def rel_path(anchor, *paths): """ Returns a path made of framgment *paths* relativ to an *anchor* path. When *anchor* is a file, its absolute directory is used instead. """ anchor = os.path.abspath(os.path.expandvars(os.path.expanduser(anchor))) if os.path.exists(anchor) and os.path.isfile(ancho...
Returns a path made of framgment *paths* relativ to an *anchor* path. When *anchor* is a file, its absolute directory is used instead.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L54-L62
riga/law
law/util.py
law_home_path
def law_home_path(*paths): """ Returns the law home directory (``$LAW_HOME``) that defaults to ``"$HOME/.law"``, optionally joined with *paths*. """ home = os.getenv("LAW_HOME", "$HOME/.law") home = os.path.expandvars(os.path.expanduser(home)) return os.path.normpath(os.path.join(home, *path...
python
def law_home_path(*paths): """ Returns the law home directory (``$LAW_HOME``) that defaults to ``"$HOME/.law"``, optionally joined with *paths*. """ home = os.getenv("LAW_HOME", "$HOME/.law") home = os.path.expandvars(os.path.expanduser(home)) return os.path.normpath(os.path.join(home, *path...
Returns the law home directory (``$LAW_HOME``) that defaults to ``"$HOME/.law"``, optionally joined with *paths*.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L72-L79
riga/law
law/util.py
print_err
def print_err(*args, **kwargs): """ print_err(*args, flush=False) Same as *print*, but outputs to stderr. If *flush* is *True*, stderr is flushed after printing. """ sys.stderr.write(" ".join(str(arg) for arg in args) + "\n") if kwargs.get("flush", False): sys.stderr.flush()
python
def print_err(*args, **kwargs): """ print_err(*args, flush=False) Same as *print*, but outputs to stderr. If *flush* is *True*, stderr is flushed after printing. """ sys.stderr.write(" ".join(str(arg) for arg in args) + "\n") if kwargs.get("flush", False): sys.stderr.flush()
print_err(*args, flush=False) Same as *print*, but outputs to stderr. If *flush* is *True*, stderr is flushed after printing.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L82-L88
riga/law
law/util.py
abort
def abort(msg=None, exitcode=1): """ Aborts the process (*sys.exit*) with an *exitcode*. If *msg* is not *None*, it is printed first to stdout if *exitcode* is 0 or *None*, and to stderr otherwise. """ if msg is not None: if exitcode in (None, 0): print(msg) else: ...
python
def abort(msg=None, exitcode=1): """ Aborts the process (*sys.exit*) with an *exitcode*. If *msg* is not *None*, it is printed first to stdout if *exitcode* is 0 or *None*, and to stderr otherwise. """ if msg is not None: if exitcode in (None, 0): print(msg) else: ...
Aborts the process (*sys.exit*) with an *exitcode*. If *msg* is not *None*, it is printed first to stdout if *exitcode* is 0 or *None*, and to stderr otherwise.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L91-L101
riga/law
law/util.py
colored
def colored(msg, color=None, background=None, style=None, force=False): """ Return the colored version of a string *msg*. For *color*, *background* and *style* options, see https://misc.flogisoft.com/bash/tip_colors_and_formatting. Unless *force* is *True*, the *msg* string is returned unchanged in case...
python
def colored(msg, color=None, background=None, style=None, force=False): """ Return the colored version of a string *msg*. For *color*, *background* and *style* options, see https://misc.flogisoft.com/bash/tip_colors_and_formatting. Unless *force* is *True*, the *msg* string is returned unchanged in case...
Return the colored version of a string *msg*. For *color*, *background* and *style* options, see https://misc.flogisoft.com/bash/tip_colors_and_formatting. Unless *force* is *True*, the *msg* string is returned unchanged in case the output is not a tty.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L157-L176
riga/law
law/util.py
query_choice
def query_choice(msg, choices, default=None, descriptions=None, lower=True): """ Interactively query a choice from the prompt until the input matches one of the *choices*. The prompt can be configured using *msg* and *descriptions*, which, if set, must have the same length as *choices*. When *default* i...
python
def query_choice(msg, choices, default=None, descriptions=None, lower=True): """ Interactively query a choice from the prompt until the input matches one of the *choices*. The prompt can be configured using *msg* and *descriptions*, which, if set, must have the same length as *choices*. When *default* i...
Interactively query a choice from the prompt until the input matches one of the *choices*. The prompt can be configured using *msg* and *descriptions*, which, if set, must have the same length as *choices*. When *default* is not *None* it must be one of the choices and is used when the input is empty. When ...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L186-L218
riga/law
law/util.py
multi_match
def multi_match(name, patterns, mode=any, regex=False): """ Compares *name* to multiple *patterns* and returns *True* in case of at least one match (*mode* = *any*, the default), or in case all patterns matched (*mode* = *all*). Otherwise, *False* is returned. When *regex* is *True*, *re.match* is used ...
python
def multi_match(name, patterns, mode=any, regex=False): """ Compares *name* to multiple *patterns* and returns *True* in case of at least one match (*mode* = *any*, the default), or in case all patterns matched (*mode* = *all*). Otherwise, *False* is returned. When *regex* is *True*, *re.match* is used ...
Compares *name* to multiple *patterns* and returns *True* in case of at least one match (*mode* = *any*, the default), or in case all patterns matched (*mode* = *all*). Otherwise, *False* is returned. When *regex* is *True*, *re.match* is used instead of *fnmatch.fnmatch*.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L221-L230
riga/law
law/util.py
is_lazy_iterable
def is_lazy_iterable(obj): """ Returns whether *obj* is iterable lazily, such as generators, range objects, etc. """ return isinstance(obj, (types.GeneratorType, collections.MappingView, six.moves.range, enumerate))
python
def is_lazy_iterable(obj): """ Returns whether *obj* is iterable lazily, such as generators, range objects, etc. """ return isinstance(obj, (types.GeneratorType, collections.MappingView, six.moves.range, enumerate))
Returns whether *obj* is iterable lazily, such as generators, range objects, etc.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L233-L238
riga/law
law/util.py
make_list
def make_list(obj, cast=True): """ Converts an object *obj* to a list and returns it. Objects of types *tuple* and *set* are converted if *cast* is *True*. Otherwise, and for all other types, *obj* is put in a new list. """ if isinstance(obj, list): return list(obj) elif is_lazy_iterable...
python
def make_list(obj, cast=True): """ Converts an object *obj* to a list and returns it. Objects of types *tuple* and *set* are converted if *cast* is *True*. Otherwise, and for all other types, *obj* is put in a new list. """ if isinstance(obj, list): return list(obj) elif is_lazy_iterable...
Converts an object *obj* to a list and returns it. Objects of types *tuple* and *set* are converted if *cast* is *True*. Otherwise, and for all other types, *obj* is put in a new list.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L241-L253
riga/law
law/util.py
make_tuple
def make_tuple(obj, cast=True): """ Converts an object *obj* to a tuple and returns it. Objects of types *list* and *set* are converted if *cast* is *True*. Otherwise, and for all other types, *obj* is put in a new tuple. """ if isinstance(obj, tuple): return tuple(obj) elif is_lazy_iter...
python
def make_tuple(obj, cast=True): """ Converts an object *obj* to a tuple and returns it. Objects of types *list* and *set* are converted if *cast* is *True*. Otherwise, and for all other types, *obj* is put in a new tuple. """ if isinstance(obj, tuple): return tuple(obj) elif is_lazy_iter...
Converts an object *obj* to a tuple and returns it. Objects of types *list* and *set* are converted if *cast* is *True*. Otherwise, and for all other types, *obj* is put in a new tuple.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L256-L268
riga/law
law/util.py
flatten
def flatten(struct): """ Flattens and returns a complex structured object *struct*. """ if isinstance(struct, dict): return flatten(struct.values()) elif isinstance(struct, (list, tuple, set)) or is_lazy_iterable(struct): objs = [] for obj in struct: objs.extend(f...
python
def flatten(struct): """ Flattens and returns a complex structured object *struct*. """ if isinstance(struct, dict): return flatten(struct.values()) elif isinstance(struct, (list, tuple, set)) or is_lazy_iterable(struct): objs = [] for obj in struct: objs.extend(f...
Flattens and returns a complex structured object *struct*.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L271-L283
riga/law
law/util.py
merge_dicts
def merge_dicts(*dicts, **kwargs): """ merge_dicts(*dicts, cls=None) Takes multiple *dicts* and returns a single merged dict. The merging takes place in order of the passed dicts and therefore, values of rear objects have precedence in case of field collisions. The class of the returned merged dict is c...
python
def merge_dicts(*dicts, **kwargs): """ merge_dicts(*dicts, cls=None) Takes multiple *dicts* and returns a single merged dict. The merging takes place in order of the passed dicts and therefore, values of rear objects have precedence in case of field collisions. The class of the returned merged dict is c...
merge_dicts(*dicts, cls=None) Takes multiple *dicts* and returns a single merged dict. The merging takes place in order of the passed dicts and therefore, values of rear objects have precedence in case of field collisions. The class of the returned merged dict is configurable via *cls*. If it is *None*, the...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L286-L309
riga/law
law/util.py
which
def which(prog): """ Pythonic ``which`` implementation. Returns the path to an executable *prog* by searching in *PATH*, or *None* when it could not be found. """ executable = lambda path: os.path.isfile(path) and os.access(path, os.X_OK) # prog can also be a path dirname, _ = os.path.split...
python
def which(prog): """ Pythonic ``which`` implementation. Returns the path to an executable *prog* by searching in *PATH*, or *None* when it could not be found. """ executable = lambda path: os.path.isfile(path) and os.access(path, os.X_OK) # prog can also be a path dirname, _ = os.path.split...
Pythonic ``which`` implementation. Returns the path to an executable *prog* by searching in *PATH*, or *None* when it could not be found.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L312-L330
riga/law
law/util.py
map_verbose
def map_verbose(func, seq, msg="{}", every=25, start=True, end=True, offset=0, callback=None): """ Same as the built-in map function but prints a *msg* after chunks of size *every* iterations. When *start* (*stop*) is *True*, the *msg* is also printed after the first (last) iteration. Note that *msg* is...
python
def map_verbose(func, seq, msg="{}", every=25, start=True, end=True, offset=0, callback=None): """ Same as the built-in map function but prints a *msg* after chunks of size *every* iterations. When *start* (*stop*) is *True*, the *msg* is also printed after the first (last) iteration. Note that *msg* is...
Same as the built-in map function but prints a *msg* after chunks of size *every* iterations. When *start* (*stop*) is *True*, the *msg* is also printed after the first (last) iteration. Note that *msg* is supposed to be a template string that will be formatted with the current iteration number (starting at...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L333-L368
riga/law
law/util.py
map_struct
def map_struct(func, struct, cls=None, map_dict=True, map_list=True, map_tuple=False, map_set=False): """ Applies a function *func* to each value of a complex structured object *struct* and returns the output in the same structure. Example: .. code-block:: python struct = {"foo": [123, ...
python
def map_struct(func, struct, cls=None, map_dict=True, map_list=True, map_tuple=False, map_set=False): """ Applies a function *func* to each value of a complex structured object *struct* and returns the output in the same structure. Example: .. code-block:: python struct = {"foo": [123, ...
Applies a function *func* to each value of a complex structured object *struct* and returns the output in the same structure. Example: .. code-block:: python struct = {"foo": [123, 456], "bar": [{"1": 1}, {"2": 2}]} def times_two(i): return i * 2 map_struct(struct, times_two) ...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L371-L451
riga/law
law/util.py
mask_struct
def mask_struct(mask, struct, replace=no_value): """ Masks a complex structured object *struct* with a *mask* and returns the remaining values. When *replace* is set, masked values are replaced with that value instead of being removed. The *mask* can have a complex structure as well. Examples: .. c...
python
def mask_struct(mask, struct, replace=no_value): """ Masks a complex structured object *struct* with a *mask* and returns the remaining values. When *replace* is set, masked values are replaced with that value instead of being removed. The *mask* can have a complex structure as well. Examples: .. c...
Masks a complex structured object *struct* with a *mask* and returns the remaining values. When *replace* is set, masked values are replaced with that value instead of being removed. The *mask* can have a complex structure as well. Examples: .. code-block:: python struct = {"a": [1, 2], "b": [3, [...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L454-L513
riga/law
law/util.py
tmp_file
def tmp_file(*args, **kwargs): """ Context manager that generates a temporary file, yields the file descriptor number and temporary path, and eventually removes the files. All *args* and *kwargs* are passed to :py:meth:`tempfile.mkstemp`. """ fileno, path = tempfile.mkstemp(*args, **kwargs) ...
python
def tmp_file(*args, **kwargs): """ Context manager that generates a temporary file, yields the file descriptor number and temporary path, and eventually removes the files. All *args* and *kwargs* are passed to :py:meth:`tempfile.mkstemp`. """ fileno, path = tempfile.mkstemp(*args, **kwargs) ...
Context manager that generates a temporary file, yields the file descriptor number and temporary path, and eventually removes the files. All *args* and *kwargs* are passed to :py:meth:`tempfile.mkstemp`.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L517-L534
riga/law
law/util.py
interruptable_popen
def interruptable_popen(*args, **kwargs): """ Shorthand to :py:class:`Popen` followed by :py:meth:`Popen.communicate`. All *args* and *kwargs* are forwatded to the :py:class:`Popen` constructor. The return code, standard output and standard error are returned in a tuple. The call :py:meth:`Popen.communi...
python
def interruptable_popen(*args, **kwargs): """ Shorthand to :py:class:`Popen` followed by :py:meth:`Popen.communicate`. All *args* and *kwargs* are forwatded to the :py:class:`Popen` constructor. The return code, standard output and standard error are returned in a tuple. The call :py:meth:`Popen.communi...
Shorthand to :py:class:`Popen` followed by :py:meth:`Popen.communicate`. All *args* and *kwargs* are forwatded to the :py:class:`Popen` constructor. The return code, standard output and standard error are returned in a tuple. The call :py:meth:`Popen.communicate` is interruptable by the user.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L537-L560
riga/law
law/util.py
readable_popen
def readable_popen(*args, **kwargs): """ Shorthand to :py:class:`Popen` which yields the output live line-by-line. All *args* and *kwargs* are forwatded to the :py:class:`Popen` constructor. When EOF is reached, ``communicate()`` is called on the subprocess and it is yielded. Example: .. code-block...
python
def readable_popen(*args, **kwargs): """ Shorthand to :py:class:`Popen` which yields the output live line-by-line. All *args* and *kwargs* are forwatded to the :py:class:`Popen` constructor. When EOF is reached, ``communicate()`` is called on the subprocess and it is yielded. Example: .. code-block...
Shorthand to :py:class:`Popen` which yields the output live line-by-line. All *args* and *kwargs* are forwatded to the :py:class:`Popen` constructor. When EOF is reached, ``communicate()`` is called on the subprocess and it is yielded. Example: .. code-block:: python for line in readable_popen(["s...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L563-L592
riga/law
law/util.py
create_hash
def create_hash(inp, l=10, algo="sha256"): """ Takes an input *inp* and creates a hash based on an algorithm *algo*. For valid algorithms, see python's hashlib. *l* corresponds to the maximum length of the returned hash. Internally, the string representation of *inp* is used. """ return getattr(...
python
def create_hash(inp, l=10, algo="sha256"): """ Takes an input *inp* and creates a hash based on an algorithm *algo*. For valid algorithms, see python's hashlib. *l* corresponds to the maximum length of the returned hash. Internally, the string representation of *inp* is used. """ return getattr(...
Takes an input *inp* and creates a hash based on an algorithm *algo*. For valid algorithms, see python's hashlib. *l* corresponds to the maximum length of the returned hash. Internally, the string representation of *inp* is used.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L595-L601
riga/law
law/util.py
copy_no_perm
def copy_no_perm(src, dst): """ Copies a file from *src* to *dst* including meta data except for permission bits. """ shutil.copy(src, dst) perm = os.stat(dst).st_mode shutil.copystat(src, dst) os.chmod(dst, perm)
python
def copy_no_perm(src, dst): """ Copies a file from *src* to *dst* including meta data except for permission bits. """ shutil.copy(src, dst) perm = os.stat(dst).st_mode shutil.copystat(src, dst) os.chmod(dst, perm)
Copies a file from *src* to *dst* including meta data except for permission bits.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L604-L611
riga/law
law/util.py
makedirs_perm
def makedirs_perm(path, perm=None): """ Recursively creates directory up to *path*. If *perm* is set, the permissions of all newly created directories are set to its value. """ if not os.path.exists(path): if perm is None: os.makedirs(path) else: umask = os.um...
python
def makedirs_perm(path, perm=None): """ Recursively creates directory up to *path*. If *perm* is set, the permissions of all newly created directories are set to its value. """ if not os.path.exists(path): if perm is None: os.makedirs(path) else: umask = os.um...
Recursively creates directory up to *path*. If *perm* is set, the permissions of all newly created directories are set to its value.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L614-L627
riga/law
law/util.py
user_owns_file
def user_owns_file(path, uid=None): """ Returns whether a file located at *path* is owned by the user with *uid*. When *uid* is *None*, the user id of the current process is used. """ if uid is None: uid = os.getuid() path = os.path.expandvars(os.path.expanduser(path)) return os.stat...
python
def user_owns_file(path, uid=None): """ Returns whether a file located at *path* is owned by the user with *uid*. When *uid* is *None*, the user id of the current process is used. """ if uid is None: uid = os.getuid() path = os.path.expandvars(os.path.expanduser(path)) return os.stat...
Returns whether a file located at *path* is owned by the user with *uid*. When *uid* is *None*, the user id of the current process is used.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L630-L638
riga/law
law/util.py
iter_chunks
def iter_chunks(l, size): """ Returns a generator containing chunks of *size* of a list, integer or generator *l*. A *size* smaller than 1 results in no chunking at all. """ if isinstance(l, six.integer_types): l = six.moves.range(l) if is_lazy_iterable(l): if size < 1: ...
python
def iter_chunks(l, size): """ Returns a generator containing chunks of *size* of a list, integer or generator *l*. A *size* smaller than 1 results in no chunking at all. """ if isinstance(l, six.integer_types): l = six.moves.range(l) if is_lazy_iterable(l): if size < 1: ...
Returns a generator containing chunks of *size* of a list, integer or generator *l*. A *size* smaller than 1 results in no chunking at all.
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L641-L669
riga/law
law/util.py
human_bytes
def human_bytes(n, unit=None): """ Takes a number of bytes *n*, assigns the best matching unit and returns the respective number and unit string in a tuple. When *unit* is set, that unit is used. Example: .. code-block:: python human_bytes(3407872) # -> (3.25, "MB") human_byte...
python
def human_bytes(n, unit=None): """ Takes a number of bytes *n*, assigns the best matching unit and returns the respective number and unit string in a tuple. When *unit* is set, that unit is used. Example: .. code-block:: python human_bytes(3407872) # -> (3.25, "MB") human_byte...
Takes a number of bytes *n*, assigns the best matching unit and returns the respective number and unit string in a tuple. When *unit* is set, that unit is used. Example: .. code-block:: python human_bytes(3407872) # -> (3.25, "MB") human_bytes(3407872, "kB") # -> (3328.0, "kB"...
https://github.com/riga/law/blob/479f84ce06ecf3bafe9d33cb7b8fc52e39fb80a1/law/util.py#L675-L695