def get_pep_518_info(self): """Get a list of the packages required to build the project, if any, and a flag indicating whether pyproject.toml is present, indicating that the build should be isolated. Build requirements can be specified in a pyproject.toml, as described in PEP 518. If this file exists but doesn't specify build requirements, pip will default to installing setuptools and wheel. """ if os.path.isfile(self.pyproject_toml): with open(self.pyproject_toml) as f: pp_toml = pytoml.load(f) build_sys = pp_toml.get('build-system', {}) return (build_sys.get('requires', ['setuptools', 'wheel']), True) return (['setuptools', 'wheel'], False)
def read_pyproject_toml(path): # type: (str) -> Optional[Dict[str, str]] """ Read a project's pyproject.toml file. :param path: The path to the pyproject.toml file. :return: The "build_system" value specified in the project's pyproject.toml file. """ with io.open(path, encoding="utf-8") as f: pp_toml = pytoml.load(f) build_system = pp_toml.get("build-system") return build_system
def get_pep_518_info(self): """Get PEP 518 build-time requirements. Returns the list of the packages required to build the project, specified as per PEP 518 within the package. If `pyproject.toml` is not present, returns None to signify not using the same. """ if not os.path.isfile(self.pyproject_toml): return None with io.open(self.pyproject_toml, encoding="utf-8") as f: pp_toml = pytoml.load(f) # Extract the build requirements requires = pp_toml.get("build-system", {}).get("requires", None) template = ( "%s does not comply with PEP 518 since pyproject.toml " "does not contain a valid '[build-system].requires' key: %s" ) if requires is None: logging.warn(template, self, "it is missing.") warnings.warn( "Future versions of pip may reject packages with " "pyproject.toml files that do not contain the [build-system]" "table and the requires key, as specified in PEP 518.", RemovedInPip12Warning, ) # Currently, we're isolating the build based on the presence of the # pyproject.toml file. If the user doesn't specify # build-system.requires, assume they intended to use setuptools and # wheel for now. return ["setuptools", "wheel"] else: # Error out if it's not a list of strings is_list_of_str = isinstance(requires, list) and all( isinstance(req, six.string_types) for req in requires ) if not is_list_of_str: raise InstallationError( template % (self, "it is not a list of strings.") ) # If control flow reaches here, we're good to go. return requires
def build(source_dir, dist, dest=None): pyproject = os.path.join(source_dir, 'pyproject.toml') dest = os.path.join(source_dir, dest or 'dist') mkdir_p(dest) with open(pyproject) as f: pyproject_data = pytoml.load(f) # Ensure the mandatory data can be loaded buildsys = pyproject_data['build-system'] requires = buildsys['requires'] backend = buildsys['build-backend'] hooks = Pep517HookCaller(source_dir, backend) with BuildEnvironment() as env: env.pip_install(requires) _do_build(hooks, env, dist, dest)
def get_pep_518_info(self): """Get PEP 518 build-time requirements. Returns the list of the packages required to build the project, specified as per PEP 518 within the package. If `pyproject.toml` is not present, returns None to signify not using the same. """ # If pyproject.toml does not exist, don't do anything. if not os.path.isfile(self.pyproject_toml): return None error_template = ( "{package} has a pyproject.toml file that does not comply " "with PEP 518: {reason}" ) with io.open(self.pyproject_toml, encoding="utf-8") as f: pp_toml = pytoml.load(f) # If there is no build-system table, just use setuptools and wheel. if "build-system" not in pp_toml: return ["setuptools", "wheel"] # Specifying the build-system table but not the requires key is invalid build_system = pp_toml["build-system"] if "requires" not in build_system: raise InstallationError( error_template.format(package=self, reason=( "it has a 'build-system' table but not " "'build-system.requires' which is mandatory in the table" )) ) # Error out if it's not a list of strings requires = build_system["requires"] if not _is_list_of_str(requires): raise InstallationError(error_template.format( package=self, reason="'build-system.requires' is not a list of strings.", )) return requires
def load_pyproject_toml( use_pep517, # type: Optional[bool] pyproject_toml, # type: str setup_py, # type: str req_name # type: str ): # type: (...) -> Optional[Tuple[List[str], str, List[str]]] """Load the pyproject.toml file. Parameters: use_pep517 - Has the user requested PEP 517 processing? None means the user hasn't explicitly specified. pyproject_toml - Location of the project's pyproject.toml file setup_py - Location of the project's setup.py file req_name - The name of the requirement we're processing (for error reporting) Returns: None if we should use the legacy code path, otherwise a tuple ( requirements from pyproject.toml, name of PEP 517 backend, requirements we should check are installed after setting up the build environment ) """ has_pyproject = os.path.isfile(pyproject_toml) has_setup = os.path.isfile(setup_py) if has_pyproject: with io.open(pyproject_toml, encoding="utf-8") as f: pp_toml = pytoml.load(f) build_system = pp_toml.get("build-system") else: build_system = None # The following cases must use PEP 517 # We check for use_pep517 being non-None and falsey because that means # the user explicitly requested --no-use-pep517. The value 0 as # opposed to False can occur when the value is provided via an # environment variable or config file option (due to the quirk of # strtobool() returning an integer in pip's configuration code). if has_pyproject and not has_setup: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project does not have a setup.py" ) use_pep517 = True elif build_system and "build-backend" in build_system: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project specifies a build backend of {} " "in pyproject.toml".format( build_system["build-backend"] ) ) use_pep517 = True # If we haven't worked out whether to use PEP 517 yet, # and the user hasn't explicitly stated a preference, # we do so if the project has a pyproject.toml file. elif use_pep517 is None: use_pep517 = has_pyproject # At this point, we know whether we're going to use PEP 517. assert use_pep517 is not None # If we're using the legacy code path, there is nothing further # for us to do here. if not use_pep517: return None if build_system is None: # Either the user has a pyproject.toml with no build-system # section, or the user has no pyproject.toml, but has opted in # explicitly via --use-pep517. # In the absence of any explicit backend specification, we # assume the setuptools backend, and require wheel and a version # of setuptools that supports that backend. build_system = { "requires": ["setuptools>=40.2.0", "wheel"], "build-backend": "setuptools.build_meta", } # If we're using PEP 517, we have build system information (either # from pyproject.toml, or defaulted by the code above). # Note that at this point, we do not know if the user has actually # specified a backend, though. assert build_system is not None # Ensure that the build-system section in pyproject.toml conforms # to PEP 518. error_template = ( "{package} has a pyproject.toml file that does not comply " "with PEP 518: {reason}" ) # Specifying the build-system table but not the requires key is invalid if "requires" not in build_system: raise InstallationError( error_template.format(package=req_name, reason=( "it has a 'build-system' table but not " "'build-system.requires' which is mandatory in the table" )) ) # Error out if requires is not a list of strings requires = build_system["requires"] if not _is_list_of_str(requires): raise InstallationError(error_template.format( package=req_name, reason="'build-system.requires' is not a list of strings.", )) backend = build_system.get("build-backend") check = [] # type: List[str] if backend is None: # If the user didn't specify a backend, we assume they want to use # the setuptools backend. But we can't be sure they have included # a version of setuptools which supplies the backend, or wheel # (which is neede by the backend) in their requirements. So we # make a note to check that those requirements are present once # we have set up the environment. # This is quite a lot of work to check for a very specific case. But # the problem is, that case is potentially quite common - projects that # adopted PEP 518 early for the ability to specify requirements to # execute setup.py, but never considered needing to mention the build # tools themselves. The original PEP 518 code had a similar check (but # implemented in a different way). backend = "setuptools.build_meta" check = ["setuptools>=40.2.0", "wheel"] return (requires, backend, check)
from sysconfig import get_paths from tempfile import mkdtemp <<<<<<< HEAD from .wrappers import Pep517HookCaller ======= from .wrappers import Pep517HookCaller, LoggerWrapper >>>>>>> development log = logging.getLogger(__name__) def _load_pyproject(source_dir): with open(os.path.join(source_dir, 'pyproject.toml')) as f: <<<<<<< HEAD pyproject_data = pytoml.load(f) buildsys = pyproject_data['build-system'] return buildsys['requires'], buildsys['build-backend'] ======= pyproject_data = toml.load(f) buildsys = pyproject_data['build-system'] return ( buildsys['requires'], buildsys['build-backend'], buildsys.get('backend-path'), ) >>>>>>> development class BuildEnvironment(object): """Context manager to install build deps in a simple temporary environment
def load_pyproject_toml(self): """Load pyproject.toml. We cache the loaded data, so we only load and parse the file once. Also, we extract the two values we care about (requires and build-backend) and discard the rest. """ if self._pyproject_toml_loaded: return # Don't do this processing twice self._pyproject_toml_loaded = True has_pyproject = os.path.isfile(self.pyproject_toml) has_setup = os.path.isfile(self.setup_py) if has_pyproject: with io.open(self.pyproject_toml, encoding="utf-8") as f: pp_toml = pytoml.load(f) build_system = pp_toml.get("build-system") else: build_system = None # The following cases must use PEP 517 # We check for use_pep517 equalling False because that # means the user explicitly requested --no-use-pep517 if has_pyproject and not has_setup: if self.use_pep517 is False: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project does not have a setup.py") self.use_pep517 = True if (build_system and "build-backend" in build_system): if self.use_pep517 is False: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project specifies a build backend of {} " "in pyproject.toml".format(build_system["build-backend"])) self.use_pep517 = True # If we haven't worked out whether to use PEP 517 yet, # and the user hasn't explicitly stated a preference, # we do so if the project has a pyproject.toml file. if self.use_pep517 is None: self.use_pep517 = has_pyproject if build_system is None: if self.use_pep517: build_system = { # Require a version of setuptools that includes # the PEP 517 build backend "requires": ["setuptools>=38.2.5", "wheel"], "build-backend": "setuptools.build_meta", } else: build_system = { "requires": ["setuptools", "wheel"], } assert self.use_pep517 is not None assert build_system is not None error_template = ( "{package} has a pyproject.toml file that does not comply " "with PEP 518: {reason}") # Specifying the build-system table but not the requires key is invalid if "requires" not in build_system: raise InstallationError( error_template.format( package=self, reason= ("it has a 'build-system' table but not " "'build-system.requires' which is mandatory in the table" ))) # Error out if requires is not a list of strings requires = build_system["requires"] if not _is_list_of_str(requires): raise InstallationError( error_template.format( package=self, reason="'build-system.requires' is not a list of strings.", )) self._pyproject_requires = requires self._pyproject_backend = build_system.get("build-backend")
def _load_pyproject(source_dir): with open(os.path.join(source_dir, 'pyproject.toml')) as f: pyproject_data = pytoml.load(f) buildsys = pyproject_data['build-system'] return buildsys['requires'], buildsys['build-backend']
def __init__(self, block_num, device, settings): super().__init__() lang = settings['language'] translation_path = os.path.join(settings['translation_dir'], 'individual_differences.toml') with open(translation_path, 'r', encoding='utf8') as f: translation = toml.load(f) # separate out the translation we care about translation = {k: translation[k][lang] for k in translation.keys()} self.block_num = block_num self.settings = settings self.device = device # just to disable it self.qs = [] # localization locale = settings['locale'] locale_path = os.path.join(settings['locale_dir'], 'individual_differences.toml') with open(locale_path, 'r', encoding='utf8') as f: locale_settings = toml.load(f) layout = qtw.QVBoxLayout() if locale_settings['height'] == 'inches': h_min, h_max = 47, 83 else: h_min, h_max = 120, 210 if locale_settings['weight'] == 'pounds': w_min, w_max = 66, 353 else: w_min, w_max = 30, 160 lt, gt = translation['less_than'], translation['more_than'] no_resp = translation['q_sex_ans'][0] # prefer not to respond try: height = locale_settings['height'][locale] except KeyError: # use default locale (US) height = locale_settings['height']['us'] try: weight = locale_settings['weight'][locale] except KeyError: # use default locale (US) weight = locale_settings['weight']['us'] height_opts = [no_resp, '%s %i %s' % (lt, h_min, height)] height_opts.extend(range(h_min + 1, h_max)) height_opts.append('%s %i %s' % (gt, h_max, height)) h_name = translation['q_tall'] + (' (%s)' % height) self.qs.append(h_name) self.q_height = DropDownQuestion(h_name, height_opts) weight_opts = [no_resp, '%s %i %s' % (lt, w_min, weight)] weight_opts.extend(range(w_min + 1, w_max)) weight_opts.append('%s %i %s' % (gt, w_max, weight)) w_name = translation['q_weight'] + (' (%s)' % weight) self.qs.append(w_name) self.q_weight = DropDownQuestion(w_name, weight_opts) self.q_lang = NameInput(translation['q_lang'], []) self.q_sex = RadioGroupQ(translation['q_sex'], translation['q_sex_ans']) age_range = [str(x) for x in range(18, 100)] age_range.append('100+') self.q_age = DropDownQuestion(translation['q_age'], age_range) self.relationship = RadioGroupQ(translation['q_relationship'], translation['q_relationship_ans']) self.q_tobacco = RadioGroupQ(translation['q_tobacco'], translation['q_tobacco_ans']) num_cigs = list(range(0, 100)) num_cigs.append('100+') self.q_tobacco2 = DropDownQuestion(translation['q_tobacco_2'], num_cigs) self.q_tobacco_grp = ConditionalWidget(self.q_tobacco, self.q_tobacco2, translation['q_tobacco_ans'][0]) layout.addWidget(self.q_height) layout.addWidget(self.q_weight) layout.addWidget(self.q_lang) layout.addWidget(self.q_sex) layout.addWidget(self.q_age) layout.addWidget(self.relationship) layout.addWidget(self.q_tobacco_grp) self.qs.extend([ translation[x] for x in [ 'q_lang', 'q_sex', 'q_age', 'q_relationship', 'q_tobacco', 'q_tobacco_2' ] ]) self.setLayout(layout)
def __init__(self, block_num, device, settings): super().__init__() lang = settings['language'] translation_path = os.path.join(settings['translation_dir'], 'individual_differences.toml') with open(translation_path, 'r', encoding='utf8') as f: translation = toml.load(f) # separate out the translation we care about translation = {k: translation[k][lang] for k in translation.keys()} self.translation = translation self.block_num = block_num self.settings = settings self.device = device # just to disable it layout = qtw.QVBoxLayout() layout.addWidget(JustText( translation['instructions'])) # this questionnaire... self.q1 = RadioGroupQ(translation['q1'], translation['q1_ans']) # marital self.q2 = RadioGroupQ(translation['q2'], translation['q2_ans']) # children self.q2a = RadioGroupQ(translation['q2a'], translation['q2_ans']) # talk to them # whenever q2 is clicked, check if index is valid; if so, show q2a self.q2grp = ConditionalWidget(self.q2, self.q2a, translation['q2_ans'][1:]) self.q3 = RadioGroupQ(translation['q3'], translation['q3_ans']) self.q3a = RadioGroupQ(translation['q3a'], translation['q3_ans']) self.q3grp = ConditionalWidget(self.q3, self.q3a, translation['q3_ans'][1:]) self.q4 = RadioGroupQ(translation['q4'], translation['q4_ans']) self.q4a = RadioGroupQ(translation['q4a'], translation['q3_ans']) self.q4grp = ConditionalWidget(self.q4, self.q4a, translation['q4_ans'][1:-1]) self.q5 = RadioGroupQ(translation['q5'], translation['q2_ans']) self.q5a = RadioGroupQ(translation['q5a'], translation['q2_ans']) self.q5grp = ConditionalWidget(self.q5, self.q5a, translation['q2_ans'][1:]) self.q6 = RadioGroupQ(translation['q6'], translation['q2_ans']) self.q6a = RadioGroupQ(translation['q6a'], translation['q2_ans']) self.q6grp = ConditionalWidget(self.q6, self.q6a, translation['q2_ans'][1:]) self.q7 = RadioGroupQ(translation['q7'], translation['q7_ans']) self.q7a = RadioGroupQ(translation['q7a'], translation['q2_ans']) self.q7grp = ConditionalWidget(self.q7, self.q7a, translation['q7_ans'][1]) self.q8 = RadioGroupQ(translation['q8'], translation['q7_ans']) self.q8a = RadioGroupQ(translation['q8a'], translation['q2_ans']) self.q8grp = ConditionalWidget(self.q8, self.q8a, translation['q7_ans'][1]) # q9 is special (*two* optional responses) self.q9 = RadioGroupQ(translation['q9'], translation['q9_ans']) self.q9a = RadioGroupQ(translation['q9a'], translation['q2_ans']) self.q9b = RadioGroupQ(translation['q9b'], translation['q2_ans']) self.q9grp = ConditionalWidget2(self.q9, self.q9a, self.q9b, translation['q2_ans'][1:]) self.q10 = RadioGroupQ(translation['q10'], translation['q2_ans']) self.q11 = RadioGroupQ(translation['q11'], translation['q7_ans']) self.q11a = RadioGroupQ(translation['q11a'], translation['q2_ans']) self.q11grp = ConditionalWidget(self.q11, self.q11a, translation['q7_ans'][1]) self.q12 = RadioGroupQ(translation['q12'], translation['q7_ans']) self.q12a = Question12(translation['q12a'], translation['q12a_header'], 6) self.q12grp = ConditionalWidget(self.q12, self.q12a, translation['q7_ans'][1]) layout.addWidget(self.q1) layout.addWidget(self.q2grp) layout.addWidget(self.q3grp) layout.addWidget(self.q4grp) layout.addWidget(self.q5grp) layout.addWidget(self.q6grp) layout.addWidget(self.q7grp) layout.addWidget(self.q8grp) layout.addWidget(self.q9grp) layout.addWidget(self.q10) layout.addWidget(self.q11grp) layout.addWidget(self.q12grp) self.setLayout(layout)
def __init__(self): super().__init__() self._window = None # patched in later (reference to MainWindow) self._device = DummyWave() self._is_connected = False if not gatt_ble: self.pre_embr = DummyPreEmbr() else: self.pre_embr = PreEmbr() # id, language, locale self.settings = {} self.settings['translation_dir'] = os.path.join( application_path, 'translations/') self.settings['locale_dir'] = os.path.join(application_path, 'locale/') self.settings[ 'app_path'] = application_path # allows searching relative # to the location of the executable # check all translation files, and list only complete ones translation_files = glob( os.path.join(self.settings['translation_dir'], '*.toml')) # figure out complete translations, using english as ref languages = count_language_keys(translation_files, 'en') # now same with localization # I think it's "more" ok to have missing keys in localization files, # and if the locale has *any* keys it should be allowed (and the default # subbed in if missing) locale_files = glob(os.path.join(self.settings['locale_dir'], '*.toml')) locales = check_locale_keys(locale_files, 'us') # translations for *this* widget translation_path = os.path.join(self.settings['translation_dir'], 'misc.toml') with open(translation_path, 'r', encoding='utf8') as f: self.translations = toml.load(f) # widgets and layout layout = qtw.QGridLayout() self.id = qtw.QLineEdit() self.lang = qtw.QComboBox() fnt = self.lang.font() fnt.setPointSize(26) self.lang.setFont(fnt) self.lang.currentIndexChanged.connect(partial(on_activated, self)) self.locale = qtw.QComboBox() self.locale.setFont(fnt) self.device = qtw.QComboBox() self.device.setFont(fnt) self.device.addItems(self.pre_embr.addrs) self.id.setFont(fnt) # TODO: these *also* need to be translated... self.id_label = JustText(self.translations['participant']['en']) self.lang_label = JustText(self.translations['language']['en']) self.locale_label = JustText(self.translations['locale']['en']) self.device_label = JustText('Embr Wave ID') self.dev_instr = JustText(self.translations['dev_instr']['en']) # default to english/us, which *should* exist & be complete self.lang.addItems(languages) self.lang.setCurrentText('en') self.locale.addItems(locales) self.locale.setCurrentText('us') self.blinker = qtw.QPushButton('Blink') self.blinker.clicked.connect(partial(on_blink, self)) self.connector = qtw.QPushButton('Connect (will freeze\ntemporarily)') self.connector.clicked.connect(self.try_connect) self.blinker.setStyleSheet(base_style) self.connector.setStyleSheet(base_style) layout.addWidget(self.id_label, 0, 0, Qt.AlignCenter) layout.addWidget(self.id, 0, 1, Qt.AlignCenter | Qt.AlignLeft) layout.addWidget(self.lang_label, 1, 0, Qt.AlignCenter) layout.addWidget(self.lang, 1, 1, Qt.AlignCenter | Qt.AlignLeft) layout.addWidget(self.locale_label, 2, 0, Qt.AlignCenter) layout.addWidget(self.locale, 2, 1, Qt.AlignCenter | Qt.AlignLeft) layout.addWidget(self.device_label, 3, 0, Qt.AlignCenter) layout.addWidget(self.device, 3, 1, Qt.AlignCenter | Qt.AlignLeft) layout.addWidget(self.dev_instr, 5, 0, Qt.AlignCenter) layout.addWidget(self.blinker, 5, 1, Qt.AlignCenter | Qt.AlignLeft) layout.addWidget(self.connector, 5, 1, Qt.AlignCenter) self.setLayout(layout)
def __init__(self, block_num, device, temperature, settings): super().__init__(block_num, device, temperature, settings) lang = settings['language'] locale = settings['locale'] translation_path = os.path.join(settings['translation_dir'], '%s.toml' % self.name) with open(translation_path, 'r', encoding='utf8') as f: translation = toml.load(f) locale_path = os.path.join(settings['locale_dir'], '%s.toml' % self.name) with open(locale_path, 'r', encoding='utf8') as f: locale_settings = toml.load(f) # read in all images try: images = locale_settings['house_photos'][locale] except KeyError: # use default locale (US) images = locale_settings['house_photos']['us'] # now handle localized image location for count, img in enumerate(images): # if locale has path specified, look relative to exe location if os.path.split(img)[0] != '': # TODO: verify this is the right pattern images[count] = os.path.join(application_path, img) else: # no path for locale, assume it's one of the baked-in ones images[count] = resource_filename('embr_survey', 'images/%s' % img) # read in translations, also plugging in locale-specific info self.prompt = translation['prompt'][lang] self.preprompt = translation['preprompt'][lang] self.big_title = translation['big_title'][lang] try: cost = locale_settings['house_cost'][locale] except KeyError: cost = locale_settings['house_cost']['us'] self.background = translation['background'][lang] % cost self.subtitle = translation['subtitle'][lang] self.floor1 = translation['f1'][lang] try: floor_label = locale_settings['floor_label'][locale] except KeyError: floor_label = locale_settings['floor_label']['us'] self.floor2 = translation['f2'][lang] % floor_label[0] self.floor3 = translation['f3'][lang] % floor_label[1] prompt2 = translation['prompt2'][lang] header = translation['header'][lang] self.questions = [('q%i' % i, q[lang]) for i, q in enumerate(translation['question'])] random.shuffle(self.questions) # now set up gui self.images = {os.path.basename(n): QPixmap(n) for n in images} for img in self.images: ql = qtw.QLabel() ql.setPixmap(self.images[img].scaled(800, 500, Qt.KeepAspectRatio, Qt.SmoothTransformation)) self.images[img] = ql layout = qtw.QVBoxLayout() layout.addWidget(JustText( self.prompt)) # next, we are going to present... layout.addWidget(JustText(self.preprompt)) # what do you think.. layout.addWidget(self.images['dv5_1.png'], alignment=Qt.AlignCenter) # initial image layout.addWidget(JustText('<b>%s</b>' % self.big_title)) # general info layout.addWidget(JustText(self.background)) # General info... layout.addWidget(JustText(self.subtitle)) # the resale value... layout.addWidget(JustText(self.floor1)) layout.addWidget(JustText(self.floor2)) layout.addWidget(JustText(self.floor3)) imgs = [('dv5_2.png', 'dv5_3.png'), ('dv5_4.png', 'dv5_5.png'), ('dv5_6.png', 'dv5_7.png'), ('dv5_8.png', 'dv5_9.png')] for im1, im2 in imgs: r1 = qtw.QHBoxLayout() r1.addWidget(self.images[im1]) r1.addWidget(self.images[im2]) w1 = qtw.QWidget() w1.setLayout(r1) layout.addWidget(w1, alignment=Qt.AlignCenter) layout.addWidget(self.images['dv5_10.png'], alignment=Qt.AlignCenter) layout.addWidget(JustText(prompt2)) self.qs = MultiQuestion(header, [q[1] for q in self.questions]) layout.addWidget(self.qs) self.setLayout(layout)
user_settings['recipe_dir'] = recipe_dir user_settings['data_dir'] = os.path.join(application_path, 'data/') # dump the recipe into a folder now = datetime.now().strftime('%y%m%d_%H%M%S') user_settings['datetime'] = now subj_path = os.path.join(user_settings['data_dir'], user_settings['id'], 'blocks_' + now) user_settings['subj_path'] = subj_path # this shouldn't exist yet, as this date & time have never existed os.makedirs(subj_path) # copy the recipe file directly to the base path shutil.copy2(user_settings['recipe'], subj_path) # now make a json copy with open(user_settings['recipe'], 'r') as f: dct = toml.load(f) strip_name = os.path.splitext(os.path.basename(user_settings['recipe']))[0] json_name = os.path.join(subj_path, strip_name) with open(json_name + '.json', 'w+') as f: json.dump(dct, f, indent=2) # write the recipe-level settings file dct_md5 = md5(json.dumps(dct).encode('utf-8')).hexdigest() recipe_level_sets = { 'recipe_md5': dct_md5, 'os': platform.platform(), 'py_version': platform.python_version(), 'rush_allowed': can_rush, 'fps': int(1/win.frame_period), 'gpu': win.context.info['GL_RENDERER'], 'device': device_type,
def _load_pyproject(source_dir): with open(os.path.join(source_dir, "pyproject.toml")) as f: pyproject_data = pytoml.load(f) buildsys = pyproject_data["build-system"] return buildsys["requires"], buildsys["build-backend"]
def resolve_settings(recipe_path, default_path='settingsstuff/defaults/'): defaults = {} # load default recipe for left_right (example) for fn in glob.glob(default_path + '*.toml'): with open(fn) as f: defaults.update(toml.load(f)) # load overridden version # seems like the order matters, not particular keys with open(recipe_path) as f: dat_over = toml.load(f) # join default recipe with overridden version, # keeping the changes from the overridden out_dict = OrderedDict() for key in dat_over.keys(): dat_over[key]['block_key'] = key exp_name = dat_over[key]['name'] if exp_name not in defaults.keys(): # no defaults available, terminate early raise ValueError( 'Defaults not found for experiment %s, is there a name key?' % key) out_dict[key] = defaults[exp_name].copy() # override defaults now out_dict[key].update(dat_over[key]) # convert to list for consumption (dictionary version is less convenient) out_dict = list(out_dict.values()) proto_block = [] # what we actually return (list of settings dicts) # generate all the trial tables now, based off settings # pull locals (or globals? maybe if this ends up being a function) locs = globals() loc_keys = locs.keys() filename = None # set to None by default, and only fill in if the key is there name = None trials = None for block_num, block in enumerate(out_dict): out_set = {} for key in block: setting = block[key] # retrieve the value if key.lower() == 'file': filename = setting # process file last elif key.lower() == 'trials': # trials may be overridden by file later trials = setting elif key.lower() == 'name': # name needs no gen name = setting out_set['name'] = name elif key.lower() == 'multi': # multi-setting generator pass # if dictionary, then we have a {fun: 'function', kwargs: {foo...}} setup elif isinstance(setting, dict): # we'll be strict about this sort of thing for now if 'fun' not in setting.keys(): raise ValueError( """For fancy generators, the blessed class must be specified in `fun`.""" ) blessed_gen_name = setting['fun'] lowkeys = [l.lower() for l in loc_keys] # retrieve the blessed generator # a little tricky b/c we try not to enforce matching case try: blessed_gen = next( locs[x] for x in loc_keys if x.lower() == blessed_gen_name.lower()) except StopIteration: raise ValueError( 'Specified generator "%s" not amongst the Blessed.' % blessed_gen_name) # we don't strictly *need* kwargs, but tell the user it may be funky try: kwargs = setting['kwargs'] except KeyError: warn('No kwargs found for %s, may fail?' % blessed_gen_name) kwargs = {} # TODO: append frame period, number of trials to kwargs here? # We don't instantiate just yet; we let the BlockHandler do that # doing it later lets us overwrite things that files may nuke, like # number of trials # we also need to give kwargs all the shared lists out_set[key.lower()] = (blessed_gen, kwargs) else: # some sort of scalar out_set[key.lower()] = (Fixed, {'value': setting}) if name is None: raise ValueError('Must specify the name of the experiment.') # done processing all generators, stuff # now if we have a file, use that to modify number of trials & overwrite redundant things if filename is not None: # fancy pants stuff for file import fn, extension = os.path.splitext(filename) if extension != '.csv': warn(( 'If file in block %i is a not a csv, further steps may fail ' '(Unless this file *is* comma separated).') % block_num) datafile = read_csv( filename ) # try to read the file (using our own csv machinery, not pandas) # TODO: is there a way to verify datafile.keys? # I suppose later in the process we can check against the settings # the experiment is expecting for key in datafile.keys(): # even if the key already exists, we'll nuke it out_set[key.lower()] = (TgtColumn, {'column': datafile[key]}) trials = len(datafile[key]) if trials is None: warn(( 'I recommend setting the number of trials either directly in the TOML ' 'file or indirectly by specifying a `file` key. ' 'Setting trials to be 10, tops. ' 'This warning was for block %i.' % block_num)) trials = 10 out_set['trials'] = trials block['trials'] = trials # update plain dict proto_block.append(out_set) # now we should have {'key': (GenClass, kwargs)} per block # again, we delay instantiation so that we can plug in shared lists return proto_block, out_dict
def load_pyproject_toml( use_pep517, # type: Optional[bool] pyproject_toml, # type: str setup_py, # type: str req_name # type: str ): # type: (...) -> Optional[BuildSystemDetails] """Load the pyproject.toml file. Parameters: use_pep517 - Has the user requested PEP 517 processing? None means the user hasn't explicitly specified. pyproject_toml - Location of the project's pyproject.toml file setup_py - Location of the project's setup.py file req_name - The name of the requirement we're processing (for error reporting) Returns: None if we should use the legacy code path, otherwise a tuple ( requirements from pyproject.toml, name of PEP 517 backend, requirements we should check are installed after setting up the build environment directory paths to import the backend from (backend-path), relative to the project root. ) """ has_pyproject = os.path.isfile(pyproject_toml) has_setup = os.path.isfile(setup_py) if has_pyproject: with io.open(pyproject_toml, encoding="utf-8") as f: pp_toml = pytoml.load(f) build_system = pp_toml.get("build-system") else: build_system = None # The following cases must use PEP 517 # We check for use_pep517 being non-None and falsey because that means # the user explicitly requested --no-use-pep517. The value 0 as # opposed to False can occur when the value is provided via an # environment variable or config file option (due to the quirk of # strtobool() returning an integer in pip's configuration code). if has_pyproject and not has_setup: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project does not have a setup.py" ) use_pep517 = True elif build_system and "build-backend" in build_system: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project specifies a build backend of {} " "in pyproject.toml".format( build_system["build-backend"] ) ) use_pep517 = True # If we haven't worked out whether to use PEP 517 yet, # and the user hasn't explicitly stated a preference, # we do so if the project has a pyproject.toml file. elif use_pep517 is None: use_pep517 = has_pyproject # At this point, we know whether we're going to use PEP 517. assert use_pep517 is not None # If we're using the legacy code path, there is nothing further # for us to do here. if not use_pep517: return None if build_system is None: # Either the user has a pyproject.toml with no build-system # section, or the user has no pyproject.toml, but has opted in # explicitly via --use-pep517. # In the absence of any explicit backend specification, we # assume the setuptools backend that most closely emulates the # traditional direct setup.py execution, and require wheel and # a version of setuptools that supports that backend. build_system = { "requires": ["setuptools>=40.8.0", "wheel"], "build-backend": "setuptools.build_meta:__legacy__", } # If we're using PEP 517, we have build system information (either # from pyproject.toml, or defaulted by the code above). # Note that at this point, we do not know if the user has actually # specified a backend, though. assert build_system is not None # Ensure that the build-system section in pyproject.toml conforms # to PEP 518. error_template = ( "{package} has a pyproject.toml file that does not comply " "with PEP 518: {reason}" ) # Specifying the build-system table but not the requires key is invalid if "requires" not in build_system: raise InstallationError( error_template.format(package=req_name, reason=( "it has a 'build-system' table but not " "'build-system.requires' which is mandatory in the table" )) ) # Error out if requires is not a list of strings requifrom __future__ import absolute_import
def __init__(self, device, settings): super().__init__(15, device, 0, settings, None) lang = settings['language'] locale = settings['locale'] translation_path = os.path.join(settings['translation_dir'], '%s.toml' % self.name) with open(translation_path, 'r', encoding='utf8') as f: translation = toml.load(f) translation_path = os.path.join(self.settings['translation_dir'], 'misc.toml') with open(translation_path, 'r', encoding='utf8') as f: misc_translations = toml.load(f) locale_path = os.path.join(settings['locale_dir'], '%s.toml' % self.name) with open(locale_path, 'r', encoding='utf8') as f: locale_settings = toml.load(f) try: temperature_units = locale_settings['units'][locale] except KeyError: temperature_units = locale_settings['units']['us'] first = random.choice([-9, 7]) second = [-9, 7] second.remove(first) second = second[0] temp_q = translation['temp_q'][lang] temp_header = translation['temp_header'][lang] room_q = translation['room_q'][lang] hot_cold = translation['hot_cold'][lang] hot_cold_header = translation['hot_cold_header'][lang] comfort_q = translation['comfort_q'][lang] comfort_header = translation['comfort_header'][lang] self.comfort1 = SingleQuestion(temp_header, temp_q) self.wait1 = EmbrSection2(misc_translations['wait_until_green'][lang], device, first, 10000) self.current_temp1 = CurrentTempQuestion(room_q, temperature_units, device) # resets to 0 at end self.heatqs1 = HeatQuestions(hot_cold_header, hot_cold, comfort_header, comfort_q) self.idle1 = EmbrSection2(misc_translations['wait_until_green'][lang], device, 0, 5000) # part 2 (opposite temperature) self.comfort2 = SingleQuestion(temp_header, temp_q) self.wait2 = EmbrSection2(misc_translations['wait_until_green'][lang], device, second, 10000) self.current_temp2 = CurrentTempQuestion(room_q, temperature_units, device) # resets to 0 at end self.heatqs2 = HeatQuestions(hot_cold_header, hot_cold, comfort_header, comfort_q) self.add_widgets([ self.comfort1, self.wait1, self.current_temp1, self.heatqs1, self.idle1, self.comfort2, self.wait2, self.current_temp2, self.heatqs2 ]) self.q_temp_pairs = [(temp_q, first), (room_q, first), (hot_cold, first), (comfort_q, first), (temp_q, second), (room_q, second), (hot_cold, second), (comfort_q, second)]
def load_pyproject_toml( use_pep517, # type: Optional[bool] pyproject_toml, # type: str setup_py, # type: str req_name # type: str ): # type: (...) -> Optional[Tuple[List[str], str, List[str]]] """Load the pyproject.toml file. Parameters: use_pep517 - Has the user requested PEP 517 processing? None means the user hasn't explicitly specified. pyproject_toml - Location of the project's pyproject.toml file setup_py - Location of the project's setup.py file req_name - The name of the requirement we're processing (for error reporting) Returns: None if we should use the legacy code path, otherwise a tuple ( requirements from pyproject.toml, name of PEP 517 backend, requirements we should check are installed after setting up the build environment ) """ has_pyproject = os.path.isfile(pyproject_toml) has_setup = os.path.isfile(setup_py) if has_pyproject: with io.open(pyproject_toml, encoding="utf-8") as f: pp_toml = pytoml.load(f) build_system = pp_toml.get("build-system") else: build_system = None # The following cases must use PEP 517 # We check for use_pep517 being non-None and falsey because that means # the user explicitly requested --no-use-pep517. The value 0 as # opposed to False can occur when the value is provided via an # environment variable or config file option (due to the quirk of # strtobool() returning an integer in pip's configuration code). if has_pyproject and not has_setup: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project does not have a setup.py" ) use_pep517 = True elif build_system and "build-backend" in build_system: if use_pep517 is not None and not use_pep517: raise InstallationError( "Disabling PEP 517 processing is invalid: " "project specifies a build backend of {} " "in pyproject.toml".format( build_system["build-backend"] ) ) use_pep517 = True # If we haven't worked out whether to use PEP 517 yet, # and the user hasn't explicitly stated a preference, # we do so if the project has a pyproject.toml file. elif use_pep517 is None: use_pep517 = has_pyproject # At this point, we know whether we're going to use PEP 517. assert use_pep517 is not None # If we're using the legacy code path, there is nothing further # for us to do here. if not use_pep517: return None if build_system is None: # Either the user has a pyproject.toml with no build-system # section, or the user has no pyproject.toml, but has opted in # explicitly via --use-pep517. # In the absence of any explicit backend specification, we # assume the setuptools backend that most closely emulates the # traditional direct setup.py execution, and require wheel and # a version of setuptools that supports that backend. build_system = { "requires": ["setuptools>=40.8.0", "wheel"], "build-backend": "setuptools.build_meta:__legacy__", } # If we're using PEP 517, we have build system information (either # from pyproject.toml, or defaulted by the code above). # Note that at this point, we do not know if the user has actually # specified a backend, though. assert build_system is not None # Ensure that the build-system section in pyproject.toml conforms # to PEP 518. error_template = ( "{package} has a pyproject.toml file that does not comply " "with PEP 518: {reason}" ) # Specifying the build-system table but not the requires key is invalid if "requires" not in build_system: raise InstallationError( error_template.format(package=req_name, reason=( "it has a 'build-system' table but not " "'build-system.requires' which is mandatory in the table" )) ) # Error out if requires is not a list of strings requires = build_system["requires"] if not _is_list_of_str(requires): raise InstallationError(error_template.format( package=req_name, reason="'build-system.requires' is not a list of strings.", )) backend = build_system.get("build-backend") check = [] # type: List[str] if backend is None: # If the user didn't specify a backend, we assume they want to use # the setuptools backend. But we can't be sure they have included # a version of setuptools which supplies the backend, or wheel # (which is needed by the backend) in their requirements. So we # make a note to check that those requirements are present once # we have set up the environment. # This is quite a lot of work to check for a very specific case. But # the problem is, that case is potentially quite common - projects that # adopted PEP 518 early for the ability to specify requirements to # execute setup.py, but never considered needing to mention the build # tools themselves. The original PEP 518 code had a similar check (but # implemented in a different way). backend = "setuptools.build_meta:__legacy__" check = ["setuptools>=40.8.0", "wheel"] return (requires, backend, check)
from pip._vendor import pytoml from setuptools import setup, find_packages with open('Pipfile', 'r') as _pipfile: _PIPFILE_CONTENTS = pytoml.load(_pipfile) setup( name='cronosfera', version='0.0', url='https://nanoporetech.com', author='Eric Palanques', author_email='*****@*****.**', description='Project to visualise the history of the world', long_description='Locate events in three dimensions: eras, location and biology', packages=find_packages( exclude=[], include=['time*']), data_files=[('.', ['Pipfile']), ], install_requires=list(_PIPFILE_CONTENTS['packages'].keys()))
requirements we should check are installed after setting up the build environment <<<<<<< HEAD ======= directory paths to import the backend from (backend-path), relative to the project root. >>>>>>> development ) """ has_pyproject = os.path.isfile(pyproject_toml) has_setup = os.path.isfile(setup_py) if has_pyproject: with io.open(pyproject_toml, encoding="utf-8") as f: <<<<<<< HEAD pp_toml = pytoml.load(f) ======= pp_toml = toml.load(f) >>>>>>> development build_system = pp_toml.get("build-system") else: build_system = None # The following cases must use PEP 517 # We check for use_pep517 being non-None and falsey because that means # the user explicitly requested --no-use-pep517. The value 0 as # opposed to False can occur when the value is provided via an # environment variable or config file option (due to the quirk of # strtobool() returning an integer in pip's configuration code). if has_pyproject and not has_setup: if use_pep517 is not None and not use_pep517: