def test_child_program(self): child_program = 'tests/test_files/req_module.py' d = main.consolidate_dependencies(needs_ipython=False, child_program=child_program, requirement_files=None, manual_dependencies=None) self.assertDictEqual(d, {'pypi': {Requirement.parse('foo'), Requirement.parse('bar')}})
def populate_source(self, source, dependency=False): super(SetupEggSubRecipe, self).populate_source( source, load_options=not dependency) if 'egg' not in source: source['egg'] = self.name source['requirement'] = Requirement.parse(source['egg']) source['egg'] = str(source['requirement']) source['find-requirement'] = Requirement.parse(source['find-egg']) \ if 'find-egg' in source else source['requirement'] source['find-egg'] = str(source['find-requirement']) source.setdefault('build', True) egg_directories = [] if 'develop-eggs-directory' in self.recipe.buildout['buildout']: egg_directories.append(self.recipe.buildout['buildout']['develop-eggs-directory']) if 'eggs-directory' in self.recipe.buildout['buildout']: egg_directories.append(self.recipe.buildout['buildout']['eggs-directory']) source.setdefault('egg-path', [source['location']] if 'location' in source else [] + source.get('extra-paths', []) + egg_directories + buildout_and_setuptools_path) source.setdefault('location', self.default_eggs_directory(develop=source.get('develop', False))) source['egg-environment'] = Environment(source['egg-path']) source['build-options'] = {} if not dependency: for src_key, dst_key in [(key, re.sub('-', '_', key)) for key in [option for option in self.options if option in BUILD_EXT_OPTIONS]]: source['build-options'][dst_key] = self.options[src_key] source.setdefault('signature', self.resolve_signature(source))
def runtestMulti(tmpdir,name,threshMLBL,threshLG,threshOG): infile = resource_filename(Requirement.parse("molSimplify"),"tests/inputs/"+name+".in") newinfile = parse4test(infile,tmpdir,True) args =['main.py','-i', newinfile] #Need to make the ligand file visible to the input file startgen(args,False,False) myjobdir=jobdir(infile)+"/" print "Test input file: ", newinfile print "Test output files are generated in ",myjobdir refdir = resource_filename(Requirement.parse("molSimplify"),"tests/refs/"+name+"/") [passMultiFileCheck,myfiles]=checkMultiFileGen(myjobdir,refdir) pass_structures=[] if passMultiFileCheck==False: print "Test failed for checking number and names of generated files. Test ends" else: print "Checking each generated structure..." for f in myfiles: if ".xyz" in f: r=f.replace(".xyz",".report") output_xyz = output_xyz = myjobdir +f ref_xyz = refdir+f output_report = myjobdir+r ref_report = refdir+r print "Output xyz file: ", output_xyz print "Reference xyz file: ", ref_xyz print "Test report file: ", output_report print "Reference report file: ", ref_report pass_xyz=compareGeo(output_xyz,ref_xyz,threshMLBL,threshLG,threshOG) [passNumAtoms,passMLBL,passLG,passOG] = pass_xyz pass_report = compare_report_new(output_report,ref_report) pass_structures.append([f,passNumAtoms, passMLBL, passLG, passOG, pass_report]) return [passMultiFileCheck,pass_structures]
def __init__(self, host, database, username, password): self.host = host self.database = database self.username = username self.password = password self.liquibaseJar = resource_filename(Requirement.parse('liquipy'), 'externals/liquibase.jar') self.mysqlJar = resource_filename(Requirement.parse('liquipy'), 'externals/mysql-connector-java-5.1.17-bin.jar')
def test_show_distributions_multiple_w_only_best(self): import re from pkg_resources import Requirement logged = [] target, path, cheeseshop_path = self._makeDirs() nose = Requirement.parse('nose') nose2 = Requirement.parse('nose') cheeseshop = self._makeIndex(nose, nose2, target=cheeseshop_path, ) def _factory(index_url, search_path=None): assert index_url == 'http://pypi.python.org/simple' assert search_path is None return cheeseshop informer = self._makeOne('--verbose', '--show-only-best', 'nose', logger=logged.append) informer.index_factory = _factory informer.tmpdir = target informer.show_distributions() log = '\n'.join(logged) found = re.findall(r'nose: /tmp/.*/cheeseshop/nose', log) self.assertEqual(len(found), 1)
def read_release_version(): try: filename = os.path.join(sys.prefix, "share", "MyCluster", "RELEASE-VERSION") if os.path.isfile(filename): f = open(filename, 'r') else: filename = os.path.join(sys.prefix, "local", "share", "MyCluster", "RELEASE-VERSION") if os.path.isfile(filename): f = open(filename, 'r') else: filename = resource_filename(Requirement.parse("MyCluster"), "share/MyCluster/RELEASE-VERSION") if os.path.isfile(filename): f = open(filename, 'r') else: filename = resource_filename( Requirement.parse("MyCluster"), "RELEASE-VERSION") f = open(filename, 'r') try: version = f.readlines()[0] return version.strip() finally: f.close() except: return None
def test_show_distributions_skips_develop_dists(self): import re from pkg_resources import Requirement logged = [] target, path, cheeseshop_path = self._makeDirs() compoze = Requirement.parse("compoze") nose = Requirement.parse("nose") cheeseshop = self._makeIndex(compoze, nose, target=cheeseshop_path, develop=("compoze",)) local = self._makeIndex(compoze, target=target) def _factory(index_url, search_path=None): if index_url == "http://pypi.python.org/simple": assert search_path is None return cheeseshop if index_url == target: assert search_path is () return local raise ValueError(index_url) informer = self._makeOne("--verbose", "compoze", "nose", logger=logged.append) informer.index_factory = _factory informer.tmpdir = target informer.show_distributions() log = "\n".join(logged) skipped = re.compile(r"Skipping.*<compoze") found = re.compile(r"nose: /tmp/.*/cheeseshop/nose") self.assertTrue(skipped.search(log)) self.assertTrue(found.search(log))
def read_release_version(): try: filename = os.path.join(sys.prefix, "share", __application__, "RELEASE-VERSION") if os.path.isfile(filename): f = open(filename, 'r') else: filename = os.path.join(sys.prefix, "local", "share", __application__, "RELEASE-VERSION") if os.path.isfile(filename): f = open(filename, 'r') else: filename = resource_filename( Requirement.parse(__application__), "share/"+__application__+"/RELEASE-VERSION" ) if os.path.isfile(filename): f = open(filename, 'r') else: filename = resource_filename( Requirement.parse(__application__), "RELEASE-VERSION") f = open(filename, 'r') try: version = f.readlines()[0] return version.strip() finally: f.close() except Exception, e: print 'read_release_version exception: '+e return None
def get_all_valid_reqs(cls, requirements, requirements_txt): from collections import namedtuple from pkg_resources import Requirement import re numbered_item = namedtuple("numbered_item", ["position", "data"]) numbered_list = lambda dataset: [numbered_item(*ni) for ni in enumerate(dataset)] named_dataset = namedtuple("named_dataset", ["name", "dataset"]) inputs = [ named_dataset(name="command line", dataset=numbered_list(requirements)), ] if requirements_txt is not None: file_lines = re.split("[\n\r]", open(requirements_txt).read()) inputs.append(named_dataset( name="file: {0}".format(requirements_txt), dataset=numbered_list(file_lines) )) valid_reqs = [] whitespace = re.compile("^\s*$") for name, dataset in inputs: for position, req in dataset: try: Requirement.parse(req) valid_reqs.append(req) except ValueError: if whitespace.match(req) is None: # Don't warn if empty string or whitespace cls.logger.warn("Invalid requirement \"{0}\" at " \ "position {1} from {2}\n".format(req, position + 1, name)) return valid_reqs
def find_required(venv, file_): pkgdir = os.path.join(os.path.abspath(venv), "lib/python2.7/site-packages") working_set = WorkingSet([pkgdir]) #We need a version of nose & pylint, preferably our version, but if someone # insists on adding it to requirements.txt, we should accomodate them. nose_fulfilled = False pylint_fulfilled = False with open(file_, 'r') as fp: required = [Requirement.parse(req) for req in fp \ if not req.startswith("#")] requested = [] for requirement in required: if requirement.project_name == 'nose': nose_fulfilled = True if requirement.project_name == 'pylint': pylint_fulfilled = True if not version_in_working_set(requirement, working_set): requested.append(requirement) if not nose_fulfilled: requirement = Requirement.parse('nose==1.2.1') if not version_in_working_set(requirement, working_set): requested.append(requirement) if not pylint_fulfilled: requirement = Requirement.parse('pylint==0.26.0') if not version_in_working_set(requirement, working_set): requested.append(requirement) return requested
def copyConfig(): '''copyConfig() Copies samples configuration if necessary to /etc/odinsys directory.''' from pkg_resources import Requirement, resource_filename # Get our file. filename_odinsys = resource_filename(Requirement.parse("odinsys"), "config/odinsys.sample.conf") filename_odinsys_log = resource_filename(Requirement.parse("odinsys"), "config/odinsyslogger.sample.conf") try: import shutil # Create the directory. if not os.path.exists("/opt/odinsys"): os.mkdir("/opt/odinsys") # Copy the configuration. Don't clobber existing files. if not os.path.exists("/etc/odinsys/odinsys.conf"): shutil.copyfile(filename_odinsys, "/etc/odinsys/odinsys.conf") if not os.path.exists("/etc/odinsys/odinsyslogger.conf"): shutil.copyfile(filename_odinsys_log, "/etc/odinsys/odinsyslogger.conf") except IOError: print "Unable to copy configuration file to /etc/odinsys directory."
def test_show_distributions_skips_multi_develop_dists(self): import re from pkg_resources import Requirement logged = [] target, path, cheeseshop_path = self._makeDirs() compoze = Requirement.parse('compoze') nose = Requirement.parse('nose') cheeseshop = self._makeIndex(compoze, compoze, nose, target=cheeseshop_path, develop=('compoze',)) local = self._makeIndex(compoze, target=target) def _factory(index_url, search_path=None): if index_url == 'http://pypi.python.org/simple': assert search_path is None return cheeseshop if index_url == target: assert search_path is () return local raise ValueError(index_url) informer = self._makeOne('--verbose', 'compoze', 'nose', logger=logged.append) informer.index_factory = _factory informer.tmpdir = target informer.show_distributions() log = '\n'.join(logged) skipped = re.compile(r'Skipping.*<compoze') found = re.compile(r'nose: /tmp/.*/cheeseshop/nose') self.failUnless(skipped.search(log)) self.failUnless(found.search(log))
def listContributors(session): """Return a list of Contributor Identifier, Contributor Name tuples. Pickle file caching equivalent of:: list(iterContributors(session)) """ index_filename = resource_filename( Requirement.parse('archiveshub'), 'dbs/ead/indexes/idx-vdbid/idx-vdbid.index_TERMIDS' ) pickle_filename = resource_filename( Requirement.parse('archiveshub'), 'www/ead/html/searchContributors.pickle' ) if ( os.path.exists(pickle_filename) and os.stat(index_filename).st_mtime < os.stat(pickle_filename).st_mtime ): with open(pickle_filename, 'rb') as pfh: try: return pickle.load(pfh) except: pass # Generate and cache the list contributorCache = list(iterContributors(session)) with open(pickle_filename, 'wb') as pfh: pickle.dump(contributorCache, pfh) return contributorCache
def testOptionsAndHashing(self): r1 = Requirement.parse("Twisted[foo,bar]>=1.2") r2 = Requirement.parse("Twisted[bar,FOO]>=1.2") assert r1 == r2 assert r1.extras == ("foo", "bar") assert r2.extras == ("bar", "foo") # extras are normalized assert hash(r1) == hash(r2) assert hash(r1) == hash(("twisted", packaging.specifiers.SpecifierSet(">=1.2"), frozenset(["foo", "bar"])))
def copy_resources_to_log_dir(log_dir): """Copies the necessary static assets to the log_dir and returns the path of the main css file.""" css_path = resource_filename(Requirement.parse("egat"), "/egat/data/default.css") header_path = resource_filename(Requirement.parse("egat"), "/egat/data/egat_header.png") shutil.copyfile(css_path, log_dir + "/style.css") shutil.copyfile(header_path, log_dir + "/egat_header.png") return log_dir + os.sep + "style.css"
def load_plugins(build_configuration, plugins, working_set): """Load named plugins from the current working_set into the supplied build_configuration "Loading" a plugin here refers to calling registration methods -- it is assumed each plugin is already on the path and an error will be thrown if it is not. Plugins should define their entrypoints in the `pantsbuild.plugin` group when configuring their distribution. Like source backends, the `build_file_aliases`, `global_subsystems` and `register_goals` methods are called if those entry points are defined. * Plugins are loaded in the order they are provided. * This is important as loading can add, remove or replace existing tasks installed by other plugins. If a plugin needs to assert that another plugin is registered before it, it can define an entrypoint "load_after" which can return a list of plugins which must have been loaded before it can be loaded. This does not change the order or what plugins are loaded in any way -- it is purely an assertion to guard against misconfiguration. :param BuildConfiguration build_configuration: The BuildConfiguration (for adding aliases). :param list<str> plugins: A list of plugin names optionally with versions, in requirement format. eg ['widgetpublish', 'widgetgen==1.2']. :param WorkingSet working_set: A pkg_resources.WorkingSet to load plugins from. """ loaded = {} for plugin in plugins: req = Requirement.parse(plugin) dist = working_set.find(req) if not dist: raise PluginNotFound('Could not find plugin: {}'.format(req)) entries = dist.get_entry_map().get('pantsbuild.plugin', {}) if 'load_after' in entries: deps = entries['load_after'].load()() for dep_name in deps: dep = Requirement.parse(dep_name) if dep.key not in loaded: raise PluginLoadOrderError('Plugin {0} must be loaded after {1}'.format(plugin, dep)) if 'build_file_aliases' in entries: aliases = entries['build_file_aliases'].load()() build_configuration.register_aliases(aliases) if 'register_goals' in entries: entries['register_goals'].load()() if 'global_subsystems' in entries: subsystems = entries['global_subsystems'].load()() build_configuration.register_optionables(subsystems) if 'rules' in entries: rules = entries['rules'].load()() build_configuration.register_rules(rules) loaded[dist.as_requirement().key] = dist
def testBasics(self): r = Requirement.parse("Twisted>=1.2") self.assertEqual(str(r),"Twisted>=1.2") self.assertEqual(repr(r),"Requirement.parse('Twisted>=1.2')") self.assertEqual(r, Requirement("Twisted", [('>=','1.2')], ())) self.assertEqual(r, Requirement("twisTed", [('>=','1.2')], ())) self.assertNotEqual(r, Requirement("Twisted", [('>=','2.0')], ())) self.assertNotEqual(r, Requirement("Zope", [('>=','1.2')], ())) self.assertNotEqual(r, Requirement("Zope", [('>=','3.0')], ())) self.assertNotEqual(r, Requirement.parse("Twisted[extras]>=1.2"))
def testBasics(self): r = Requirement.parse("Twisted>=1.2") assert str(r) == "Twisted>=1.2" assert repr(r) == "Requirement.parse('Twisted>=1.2')" assert r == Requirement("Twisted", [('>=','1.2')], ()) assert r == Requirement("twisTed", [('>=','1.2')], ()) assert r != Requirement("Twisted", [('>=','2.0')], ()) assert r != Requirement("Zope", [('>=','1.2')], ()) assert r != Requirement("Zope", [('>=','3.0')], ()) assert r != Requirement.parse("Twisted[extras]>=1.2")
def test_empty_iteration(): crawler_mock = mock.create_autospec(Crawler, spec_set=True) crawler_mock.crawl.return_value = [] iterator = Iterator(crawler=crawler_mock) assert list(iterator.iter(Requirement.parse('foo'))) == [] assert len(crawler_mock.crawl.mock_calls) == 1 _, args, kwargs = crawler_mock.crawl.mock_calls[0] assert list(args[0]) == list(PyPIFetcher().urls(Requirement.parse('foo'))) assert kwargs == {'follow_links': False}
def testSetuptoolsProjectName(self): """ The setuptools project should implement the setuptools package. """ assert Requirement.parse("setuptools").project_name == "setuptools" # setuptools 0.7 and higher means setuptools. assert Requirement.parse("setuptools == 0.7").project_name == "setuptools" assert Requirement.parse("setuptools == 0.7a1").project_name == "setuptools" assert Requirement.parse("setuptools >= 0.7").project_name == "setuptools"
def test_get_requirements(self): """ It is possible to get a list of requirements from a requirements.txt file. """ requirements_path = FilePath(self.mktemp()) requirements_path.setContent("\n".join(["eliot==0.7.0", "Twisted==15.2.0"])) requirements = get_requirements(requirements_path) self.assertEqual(requirements, [Requirement.parse("eliot==0.7.0"), Requirement.parse("Twisted==15.2.0")])
def testOptionsAndHashing(self): r1 = Requirement.parse("Twisted[foo,bar]>=1.2") r2 = Requirement.parse("Twisted[bar,FOO]>=1.2") self.assertEqual(r1,r2) self.assertEqual(r1.extras, ("foo","bar")) self.assertEqual(r2.extras, ("bar","foo")) # extras are normalized self.assertEqual(hash(r1), hash(r2)) self.assertEqual( hash(r1), hash(("twisted", packaging.specifiers.SpecifierSet(">=1.2"), frozenset(["foo","bar"]))) )
def _setuptools_req(self, req_rhs): """Counter distribute's hack that replaces setuptools requirements. if distribute is not around, this is simply a normal requirement parsing. """ if not DISTRIBUTE: return Requirement.parse('setuptools' + req_rhs) req = Requirement.parse('willbesetuptools' + req_rhs) req.key = req.project_name = 'setuptools' return req
def __init__(self, config, logger=None): self._path = config.get('python-setup', 'interpreter_cache') setuptools_req = 'setuptools==%s' % config.get('python-setup', 'setuptools_version') try: self._setuptools_requirement = Requirement.parse(setuptools_req, replacement=False) except TypeError: self._setuptools_requirement = Requirement.parse(setuptools_req) safe_mkdir(self._path) self._fetchers = MultiResolver.fetchers(config) self._crawler = MultiResolver.crawler(config) self._interpreters = set() self._logger = logger or (lambda msg: True)
def test_two_different(self): requirement_files = [create_tempfile(self, ['1', '2'])] manual_dependencies = ['vcs::3', 'vcs::4'] d = main.consolidate_dependencies(needs_ipython=False, child_program=None, requirement_files=requirement_files, manual_dependencies=manual_dependencies) self.assertEqual(d, { 'pypi': {Requirement.parse('1'), Requirement.parse('2')}, 'vcs': {parsing.VCSDependency('3'), parsing.VCSDependency('4')} })
def test_two_same_repo(self): requirement_files = [create_tempfile(self, ['1', '2'])] manual_dependencies = ['3', '4'] d = main.consolidate_dependencies(needs_ipython=False, child_program=None, requirement_files=requirement_files, manual_dependencies=manual_dependencies) self.assertDictEqual(d, { 'pypi': {Requirement.parse('1'), Requirement.parse('2'), Requirement.parse('3'), Requirement.parse('4')} })
def grab_distrib(req, index=None, dest='.', search_pypi=True): """\ Downloads a distribution from the given package index(s) based on the given requirement string(s). Downloaded distributions are placed in the specified destination or the current directory if no destination is specified. If a distribution cannot be found in the given index(s), the Python Package Index will be searched as a last resort unless search_pypi is False. This does NOT install the distribution. """ # allow multiple package indexes to be specified if index is None: index = [] elif isinstance(index, basestring): index = [index] # else just assume it's some iterator of indexes # add PyPI as last place to search if it wasn't already specified if search_pypi and _pypi not in index and (_pypi+'/') not in index: index.append(_pypi) # allow specification of single or multiple requirements if isinstance(req, basestring): reqs = [Requirement.parse(req)] elif isinstance(req, Requirement): reqs = [req] else: reqs = [] for rr in req: if isinstance(rr, basestring): reqs.append(Requirement.parse(rr)) elif isinstance(rr, Requirement): reqs.append(rr) else: raise TypeError("supplied requirement arg must be a string"+ " or a Requirement, but given type is %s" % type(rr)) index_list = [PackageIndex(idx,search_path=[]) for idx in index] for req in reqs: fetched = None for idx in index_list: _logger.info('Looking for %s at package index %s' % (req, idx.index_url)) fetched = idx.download(req, dest) if fetched: _logger.info(' %s successfully downloaded' % fetched) break else: _logger.error("couldn't find distrib for %s" % req) return fetched
def testVersionEquality(self): r1 = Requirement.parse("foo==0.3a2") r2 = Requirement.parse("foo!=0.3a4") d = Distribution.from_filename assert d("foo-0.3a4.egg") not in r1 assert d("foo-0.3a1.egg") not in r1 assert d("foo-0.3a4.egg") not in r2 assert d("foo-0.3a2.egg") in r1 assert d("foo-0.3a2.egg") in r2 assert d("foo-0.3a3.egg") in r2 assert d("foo-0.3a5.egg") in r2
def testOptionsAndHashing(self): r1 = Requirement.parse("Twisted[foo,bar]>=1.2") r2 = Requirement.parse("Twisted[bar,FOO]>=1.2") r3 = Requirement.parse("Twisted[BAR,FOO]>=1.2.0") self.assertEqual(r1,r2) self.assertEqual(r1,r3) self.assertEqual(r1.extras, ("foo","bar")) self.assertEqual(r2.extras, ("bar","foo")) # extras are normalized self.assertEqual(hash(r1), hash(r2)) self.assertEqual( hash(r1), hash(("twisted", ((">=",parse_version("1.2")),), frozenset(["foo","bar"]))) )
def current_week_pdf(self): """Lucky numbers for current or next week in pdf format.""" change_hour = 15 numbers = LuckyNumber.current_week(change_hour) if len(numbers) == 0: return redirect(url('lucky_week')) # Register fonts ubuntu_r = resource_filename(Requirement.parse("SIS"), "resources/Ubuntu-R.ttf") ubuntu_b = resource_filename(Requirement.parse("SIS"), "resources/Ubuntu-B.ttf") pdfmetrics.registerFont(TTFont('Ubuntu', ubuntu_r)) pdfmetrics.registerFont(TTFont('Ubuntu Bold', ubuntu_b)) numbers_pdf = StringIO.StringIO() doc = SimpleDocTemplate(numbers_pdf, pagesize=A4, topMargin=A4[1]*0.26) doc.author = 'SIS' doc.title = 'Szczęśliwy numerek' data = [] for number in numbers: date = number.date.strftime("%d.%m.%y") data.append(('{0} -'.format(date), str(number.number))) table = Table(data) table.setStyle(TableStyle([ ('FONT', (0, 0), (0, -1), 'Ubuntu', 80), ('FONT', (1, 0), (1, -1), 'Ubuntu Bold', 80), ])) def header_and_footer(canvas, document): canvas.saveState() size = document.pagesize center = size[0] / 2 canvas.setFont('Ubuntu', 80) canvas.drawCentredString(center, size[1] - document.topMargin / 2, "SZCZĘŚLIWY") canvas.drawCentredString(center, size[1] - document.topMargin + 20, 'NUMEREK') canvas.setFont('Ubuntu', 15) canvas.drawRightString(size[0] - document.rightMargin, document.bottomMargin - 20, "Samorząd Uczniowski") canvas.restoreState() doc.build([table], onFirstPage=header_and_footer, onLaterPages=header_and_footer) response.headers['Content-type'] = 'application/pdf' return numbers_pdf.getvalue()
from pkg_resources import Requirement, resource_filename import os.path import config #### ADDITIONAL FILES #### CONFIG_PATH = resource_filename(Requirement.parse('tweepyutils'), 'tweepyutils-data') CONFIG_FILE = os.path.join(CONFIG_PATH, 'tweepyutils_config.json') config = config.Config(CONFIG_FILE) #### CONFIG KEYS #### ACCOUNTS = 'accounts' CONSUMER_KEY = 'consumer_key' CONSUMER_SECRET = 'consumer_secret' ACCESS_TOKEN = 'access_token' ACCESS_TOKEN_SECRET = 'access_token_secret' IS_MAIN_ACCOUNT = 'is_main_account' IS_DEV_ACCOUNT = 'is_dev_account'
def testSimpleRequirements(self): assert (list(parse_requirements('Twis-Ted>=1.2-1')) == [ Requirement('Twis-Ted>=1.2-1') ]) assert (list(parse_requirements('Twisted >=1.2, \ # more\n<2.0')) == [ Requirement('Twisted>=1.2,<2.0') ]) assert (Requirement.parse("FooBar==1.99a3") == Requirement( "FooBar==1.99a3")) with pytest.raises(ValueError): Requirement.parse(">=2.3") with pytest.raises(ValueError): Requirement.parse("x\\") with pytest.raises(ValueError): Requirement.parse("x==2 q") with pytest.raises(ValueError): Requirement.parse("X==1\nY==2") with pytest.raises(ValueError): Requirement.parse("#")
BKW_PATH = config_file.get("PATHS", "BKW_PATH", fallback=os.path.join(CORPORA_BASE_PATH, "BKW-speaker-ids_2/")) EN_WORDS_PATH = config_file.get("PATHS", "EN_WORDS_PATH", fallback=os.path.join(CORPORA_BASE_PATH, "english-words/words.txt")) # The directory where the preprocessed data will be held. TGT_DIR = config_file.get("PATHS", "TARGET", fallback="./data") # The path for experiments EXP_DIR = config_file.get("PATHS", "EXPERIMENTS", fallback="./exp") TEST_ROOT = config_file.get("PATHS", "TEST_ROOT", fallback="./testing/") TEST_EXP_PATH = os.path.join(TEST_ROOT, "exp/") TEST_DATA_PATH = os.path.join(TEST_ROOT, "data/") # The path to the sox tool; currently used for splitting WAVs, but we can # replace with pydub. Actually, the pydub approach is slow so now # wav.trim_wav_ms tries to use sox and then fallsback to pydub/ffmpeg SOX_PATH = config_file.get("PATHS", "SOX_PATH", fallback="sox") # FFMPEG is used for normalizing WAVs FFMPEG_PATH = config_file.get("PATHS", "FFMPEG_PATH", fallback="ffmpeg") # Kaldi is used for pitch extraction KALDI_ROOT = config_file.get("PATHS", "KALDI_ROOT_PATH", fallback="/home/oadams/tools/kaldi") # Used for lattice output OPENFST_BIN_PATH = config_file.get("PATHS", "OPEN_FST_BIN_PATH", fallback="/home/oadams/tools/openfst-1.6.2/src/bin") # Fetch the path of the logging.ini file installed by setuptools. from pkg_resources import Requirement, resource_filename logging_ini_path = resource_filename(Requirement.parse("persephone"), "persephone/logging.ini") LOGGING_INI_PATH = config_file.get("PATHS", "log_ini_path", fallback=logging_ini_path)
def init(self, inventory, config, initial_limit=None): # Config validation # # If no config, create one using the defaults if config is None: config = Config() # Error if our min version is not met if config.MIN_PYINFRA_VERSION is not None: if config.REQUIRE_PYINFRA_VERSION is None: config.REQUIRE_PYINFRA_VERSION = '>={0}'.format( config.MIN_PYINFRA_VERSION) logger.warning( '`MIN_PYINFRA_VERSION` is deprecated, please use `REQUIRE_PYINFRA_VERSION`.', ) else: logger.warning( 'Ignoring legacy `MIN_PYINFRA_VERSION` because ' '`REQUIRE_PYINFRA_VERSION` also exists.', ) if config.REQUIRE_PYINFRA_VERSION is not None: running_version = parse_version(__version__) required_versions = Requirement.parse( 'pyinfra{0}'.format(config.REQUIRE_PYINFRA_VERSION), ) if running_version not in required_versions: raise PyinfraError(('pyinfra version requirement not met ' '(requires {0}, running {1})').format( config.REQUIRE_PYINFRA_VERSION, __version__, )) if not config.PARALLEL: # TODO: benchmark this # In my own tests the optimum number of parallel SSH processes is # ~20 per CPU core - no science here yet, needs benchmarking! cpus = cpu_count() ideal_parallel = cpus * 20 config.PARALLEL = (min(ideal_parallel, len(inventory), MAX_PARALLEL) if MAX_PARALLEL is not None else min(ideal_parallel, len(inventory))) # If explicitly set, just issue a warning elif MAX_PARALLEL is not None and config.PARALLEL > MAX_PARALLEL: logger.warning(( 'Parallel set to {0}, but this may hit the open files limit of {1}.\n' ' Max recommended value: {2}').format( config.PARALLEL, nofile_limit, MAX_PARALLEL)) # Actually initialise the state object # self.callback_handlers = [] # Setup greenlet pools self.pool = Pool(config.PARALLEL) self.fact_pool = Pool(config.PARALLEL) # Connection storage self.ssh_connections = {} self.sftp_connections = {} # Private keys self.private_keys = {} # Facts storage self.facts = {} self.fact_locks = {} # Assign inventory/config self.inventory = inventory self.config = config # Hosts we've activated at any time self.activated_hosts = set() # Active hosts that *haven't* failed yet self.active_hosts = set() # Hosts that are ready to be deployed to self.ready_hosts = set() # Hosts that have failed self.failed_hosts = set() # Limit hosts changes dynamically to limit operations to a subset of hosts self.limit_hosts = initial_limit # Op basics self.op_line_numbers_to_hash = {} self.op_meta = {} # maps operation hash -> names/etc self.ops_run = set() # list of ops which have been started/run # Op dict for each host self.ops = {host: {} for host in inventory} # Facts dict for each host self.facts = {host: {} for host in inventory} # Meta dict for each host self.meta = { host: { 'ops': 0, # one function call in a deploy file 'commands': 0, # actual # of commands to run 'op_hashes': set(), } for host in inventory } # Results dict for each host self.results = { host: { 'ops': 0, # success_ops + failed ops w/ignore_errors 'success_ops': 0, 'error_ops': 0, 'commands': 0, } for host in inventory } # Assign state back references to inventory & config inventory.state = config.state = self for host in inventory: host.state = self self.initialised = True
spec = ('==', dist.py_version) if spec not in py_deps[name]: py_deps[name].append(spec) deps = dist.requires() if Recommends: depsextras = dist.requires(extras=dist.extras) if not Requires: for dep in reversed(depsextras): if dep in deps: depsextras.remove(dep) deps = depsextras # console_scripts/gui_scripts entry points need pkg_resources from setuptools if (dist.get_entry_map('console_scripts') or dist.get_entry_map('gui_scripts')): # stick them first so any more specific requirement overrides it deps.insert(0, Requirement.parse('setuptools')) # add requires/recommends based on egg/dist metadata for dep in deps: if legacy: name = 'pythonegg({})({})'.format(pyver_major, dep.key) else: if PyMajorVer_Deps: name = 'python{}dist({})'.format(pyver_major, dep.key) else: name = 'python{}dist({})'.format( dist.py_version, dep.key) for spec in dep.specs: while spec[1].endswith('.0'): spec = (spec[0], spec[1][:-2]) if name not in py_deps: py_deps[name] = []
"""Load configuration from guesslang `config` directory""" import json import logging.config from pathlib import Path import platform from pkg_resources import (Requirement, resource_string, resource_filename, DistributionNotFound) import tensorflow as tf LOGGER = logging.getLogger(__name__) PACKAGE = Requirement.parse('guesslang') DATADIR = 'guesslang/data/{}' DATA_FALLBACK = Path(__file__).parent.joinpath('data') class ColorLogFormatter(logging.Formatter): """Logging formatter that prints pretty colored log messages""" STYLE = { # Log messages styles 'DEBUG': '\033[94m', 'INFO': '\033[0m', 'WARNING': '\033[93m', 'ERROR': '\033[1;91m', 'CRITICAL': '\033[1;95m', # Other styles 'LEVEL': '\033[1m',
from pkg_resources import Requirement, resource_filename from typing import Mapping, Union, Tuple, List import numpy as np from glk import ffi, lib from io import StringIO import textworld from textworld.generator.game import Game, GameProgression from textworld.generator.inform7 import Inform7Game from textworld.logic import Action, State from textworld.core import GameNotRunningError GLULX_PATH = resource_filename(Requirement.parse('textworld'), 'textworld/thirdparty/glulx/Git-Glulx') class MissingGameInfosError(NameError): """ Thrown if an action requiring GameInfos is used on a game without GameInfos, such as a Frotz game or a Glulx game not generated by TextWorld. """ def __init__(self): msg = ("Can only use GitGlulxMLEnvironment with games generated by " " TextWorld. Make sure the generated .json file is in the same " " folder as the .ulx game file.") super().__init__(msg)
# variable SAGE_DOC_MATHJAX is set to "no" or "False". (Note that if # the user does not set this variable, then the script sage-env sets # it to "True".) if (os.environ.get('SAGE_DOC_MATHJAX', 'no') != 'no' and os.environ.get('SAGE_DOC_MATHJAX', 'no') != 'False'): extensions.append('sphinx.ext.mathjax') mathjax_path = 'MathJax.js?config=TeX-AMS_HTML-full,../mathjax_sage.js' from sage.misc.latex_macros import sage_mathjax_macros # this is broken for now # html_theme_options['mathjax_macros'] = sage_mathjax_macros() from pkg_resources import Requirement, working_set sagenb_path = working_set.find(Requirement.parse('sagenb')).location mathjax_relative = os.path.join('sagenb', 'data', 'mathjax') # It would be really nice if sphinx would copy the entire mathjax directory, # (so we could have a _static/mathjax directory), rather than the contents of the directory mathjax_static = os.path.join(sagenb_path, mathjax_relative) html_static_path.append(mathjax_static) exclude_patterns = [ '**/' + os.path.join(mathjax_relative, i) for i in ('docs', 'README*', 'test', 'unpacked', 'LICENSE') ] else: extensions.append('sphinx.ext.pngmath') # This is to make the verbatim font smaller;
modules = [ 'database', 'documentFactory', 'documentStore', 'extractor', 'index', 'indexStore', 'logger', 'normalizer', 'objectStore', 'parser', 'postgres', 'preParser', 'protocolMap', 'queryFactory', 'queryStore', 'recordStore', 'resultSetStore', 'server', 'transformer', 'workflow', 'xpathProcessor', 'textmining.tmNormalizer', 'textmining.tmDocumentFactory', 'textmining.tmPreParser', 'textmining.tmTransformer', 'datamining.dmPreParser', 'datamining.dmTransformer', 'grid.srbIndex', 'grid.srbStore' ] cheshire3Version = (1, 0, 0) # Find Cheshire3 environment cheshire3Home = os.environ.get( 'C3HOME', resource_filename(Requirement.parse('cheshire3'), '')) cheshire3Root = os.path.join(cheshire3Home, "cheshire3") cheshire3Code = os.path.join(cheshire3Root) cheshire3Dbs = os.path.join(cheshire3Home, "dbs") cheshire3Www = os.path.join(cheshire3Home, "www") CONFIG_NS = "http://www.cheshire3.org/schemas/config/" def get_api(object, all=False): if all: base = object.__class__ else: l = inspect.getmro(object.__class__) base = None
Image, ClippingPath, \ NUMBER, TEXT, BOOLEAN, BUTTON, \ ShoebotError, \ RGB, HSB, \ CENTER, CORNER, CORNERS from .grammar import Grammar from pkg_resources import resource_filename, Requirement from glob import glob import random as r import locale import gettext SBOT_ROOT = resource_filename(Requirement.parse("shoebot"), "") APP = 'shoebot' DIR = sys.prefix + '/share/shoebot/locale' locale.setlocale(locale.LC_ALL, '') gettext.bindtextdomain(APP, DIR) # gettext.bindtextdomain(APP) gettext.textdomain(APP) _ = gettext.gettext LIB_DIRS = [ os.path.join(SBOT_ROOT, 'local', 'share', 'shoebot', 'lib'), os.path.join(SBOT_ROOT, 'lib'), os.path.join(SBOT_ROOT, 'share', 'shoebot', 'lib'), os.path.join(sys.prefix, 'share', 'shoebot', 'lib') ] for LIB_DIR in LIB_DIRS:
def test_install_scripts_soft_deps_missing_dist_exc(self): req = Requirement.parse("zztest-softreq") self.do_test_install_scripts_soft_deps( exc=MissingDistribution(req, []))
def requirements(requirements_filename): with open(requirements_filename) as requirements_file: for line in requirements_file: if line.strip() and not line.startswith(('#', '-e')): yield Requirement.parse(line.strip())
t.append(x) return '\n'.join(t) try: from sage.misc.preparser import strip_string_literals except ImportError: def strip_string_literals(code, state=None): # todo -- do we need this? return code try: from pkg_resources import Requirement, working_set SAGENB_VERSION = working_set.find(Requirement.parse('sagenb')).version except AttributeError: SAGENB_VERSION = "" try: import sage.version SAGE_VERSION = sage.version.version except ImportError: SAGE_VERSION = "" try: from sage.plot.colors import Color except ImportError: class Color: def __init__(self, *args, **kwds):
def normalize_package(value): # Strips the version and normalizes name requirement = Requirement.parse(value) return requirement.project_name.lower()
# RestAuth is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along with RestAuth. If not, # see <http://www.gnu.org/licenses/>. from __future__ import unicode_literals import os import sys from pkg_resources import DistributionNotFound from pkg_resources import Requirement from pkg_resources import resource_filename try: req = Requirement.parse("RestAuth") path = resource_filename(req, 'RestAuth') if os.path.exists(path): # pragma: no cover sys.path.insert(0, path) except DistributionNotFound: pass # we're run in a not-installed environment if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "RestAuth.settings") from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
def _find_pyopencl_include_path(): from pkg_resources import Requirement, resource_filename return resource_filename(Requirement.parse("pyopencl"), "pyopencl/cl")
def parse_requirement_arg(spec): try: return Requirement.parse(spec)
# Irish Earth Observation (IEO) Python Module # version 1.3 import os, sys, shutil, datetime from osgeo import osr from pkg_resources import resource_stream, resource_string, resource_filename, Requirement if sys.version_info[0] == 2: import ConfigParser as configparser else: import configparser # Read in config information global prjval, projinfo, mapinfostr, gcsstring, prj config = configparser.ConfigParser() config_location = resource_filename(Requirement.parse('ieo'), 'config/ieo.ini') config.read(config_location) # config_path # Spatial variables prjvalstr = config['Projection']['proj'] if ':' in prjvalstr: i = prjvalstr.find(':') + 1 prjval = int(prjvalstr[i:]) else: prjval = int(prjvalstr) # This assumes that the config value contains on the EPSG value. prj = osr.SpatialReference() prj.ImportFromEPSG(prjval) # "EPSG:2157" # Shamelessly copied from http://pydoc.net/Python/spectral/0.17/spectral.io.envi/ # import numpy as np
# The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- import os from pkg_resources import Requirement from PyInstaller.utils.hooks import qt5_menu_nib_dir, exec_statement from PyInstaller.compat import getsitepackages, is_darwin, is_win # On Windows system PATH has to be extended to point to the PyQt5 directory. # The PySide directory contains Qt dlls. We need to avoid including different # version of Qt libraries when there is installed another application (e.g. QtCreator) if is_win: from PyInstaller.utils.win32.winutils import extend_system_path extend_system_path([os.path.join(x, 'PyQt5') for x in getsitepackages()]) # In the new consolidated mode any PyQt depends on _qt hiddenimports = ['sip', 'PyQt5.Qt'] # For Qt<5.4 to work on Mac OS X it is necessary to include `qt_menu.nib`. # This directory contains some resource files necessary to run PyQt or PySide # app. qt_version = exec_statement(""" from PyQt5.QtCore import QT_VERSION_STR print(QT_VERSION_STR) """) if is_darwin and qt_version in Requirement.parse("QT<5.4"): datas = [ (qt5_menu_nib_dir(), ''), ]
def _check_failure(self, req, vers_and_locs): self.failUnlessRaises(PackagingError, check_requirement, req, vers_and_locs) for pkg, ver in vers_and_locs.items(): self.failIf(ver[0] in Requirement.parse(req), str((ver, req)))
def _show_toast( self, title: str, msg: str = "No msg", icon_path: Path = None, duration: float = None, sound_path=None, callback_on_click: callable = None, tooltip: Optional[str] = None, ) -> None: """Notification settings. :param title: notification title :param msg: notification message :param icon_path: path to the .ico file to custom notification :param duration: delay in seconds before notification self-destruction, None for no-self-destruction :param sound_path: path to the .wav file to custom notification """ self.duration = duration def callback(): """ """ self.duration = 0 if callback_on_click is not None: callback_on_click() if tooltip is None: tooltip = PROJECT_NAME # Register the window class. self.window_class = WNDCLASS() self.instance_handle = self.window_class.hInstance = GetModuleHandle( None) self.window_class.lpszClassName = f"{PROJECT_NAME}-{title}" # must be a string self.window_class.lpfnWndProc = self._decorator( self.wnd_proc, callback) # could instead specify simple mapping try: self.classAtom = RegisterClass(self.window_class) except Exception as e: logging.error("Some trouble with classAtom (%s)", e) style = WS_OVERLAPPED | WS_SYSMENU button_style = WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON # TODO: Unused for now self.window_handle = CreateWindow( self.classAtom, "Taskbar", style, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, self.instance_handle, None, ) UpdateWindow(self.window_handle) # icon new_name = "" if icon_path is not None: icon_path = path.realpath(icon_path) converted = False if Image is not None and icon_path.split(".")[-1] != ".ico": img = Image.open(icon_path) new_name = f'{str(icon_path.split(".")[:-1])}.ico' img.save(new_name) icon_path = new_name converted = True else: icon_path = resource_filename( Requirement.parse(PROJECT_NAME), str(Path(PROJECT_NAME) / "data" / "python.ico"), ) converted = False try: hicon = LoadImage( self.instance_handle, icon_path, IMAGE_ICON, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE, ) if Image and path.exists(new_name and converted): remove(new_name) except Exception as e: logging.error("Some trouble with the icon (%s): %s", icon_path, e) hicon = LoadIcon(0, IDI_APPLICATION) # Set the duration """ buff = create_unicode_buffer(10) windll.user32.SystemParametersInfoW(SPI_GETMESSAGEDURATION, 0, buff, 0) try: oldlength = int(buff.value.encode("unicode_escape").decode().replace("\\", "0"), 16) except ValueError: oldlength = 5 # Default notification length duration_output = windll.user32.SystemParametersInfoW(SPI_SETMESSAGEDURATION, 0, self.duration, SPIF_SENDCHANGE) windll.user32.SystemParametersInfoW(SPI_GETMESSAGEDURATION, 0, buff, 0) duration_error = False try: int(buff.value.encode("unicode_escape").decode().replace("\\", "0"), 16) except ValueError: duration_error = True if duration_output == 0 or self.duration > 255 or duration_error: windll.user32.SystemParametersInfoW(SPI_SETMESSAGEDURATION, 0, oldlength, SPIF_SENDCHANGE) self.active = False raise RuntimeError(f"Some trouble with the duration ({self.duration})" ": Invalid duration length") """ title += " " * randint(0, 63 - len(title)) msg += " " * randint(0, 128 - len(msg)) Shell_NotifyIcon( NIM_ADD, ( self.window_handle, 0, NIF_ICON | NIF_MESSAGE | NIF_TIP, WM_USER + 20, hicon, tooltip, ), ) Shell_NotifyIcon( NIM_MODIFY, ( self.window_handle, 0, NIF_INFO, WM_USER + 20, hicon, tooltip, msg, 200, title, 0 if sound_path is None else NIIF_NOSOUND, ), ) if sound_path is not None: # play the custom sound sound_path = path.realpath(sound_path) if not path.exists(sound_path): logging.error( f"Some trouble with the sound file ({sound_path}): [Errno 2] No such file" ) try: PlaySound(sound_path, SND_FILENAME) except Exception as e: logging.error( f"Some trouble with the sound file ({sound_path}): {e}") PumpMessages() """ # Put the notification duration back to normal SystemParametersInfoW(SPI_SETMESSAGEDURATION, 0, oldlength, SPIF_SENDCHANGE) """ if duration is not None: # take a rest then destroy # sleep(duration) while self.duration > 0: sleep(0.1) self.duration -= 0.1 DestroyWindow(self.window_handle) UnregisterClass(self.window_class.lpszClassName, self.instance_handle) try: # Sometimes the try icon sticks around until you click it - this should stop that Shell_NotifyIcon(NIM_DELETE, (self.window_handle, 0)) except WinTypesException: pass self.active = False
def _check_success(self, req, vers_and_locs): check_requirement(req, vers_and_locs) for pkg, ver in vers_and_locs.items(): self.failUnless(ver[0] in Requirement.parse(req), str((ver, req)))
def failsafe_parse(requirement): try: return Requirement.parse(requirement, replacement=False) except TypeError: return Requirement.parse(requirement)
def parse_req(req): req_object = Requirement.parse(req) pkg_name = req_object.key spec = SpecifierSet(str(req_object).replace(pkg_name, "")) return pkg_name, spec
def main(ctx): """ Create demo data """ req = Requirement.parse('odoo-brasil') setup_company(ctx, req) setup_language(ctx)
import os.path as op import os from glob import glob from time import time import shutil import subprocess import sys from pkg_resources import Requirement, resource_filename import logging from command import * import nibabel as ni import numpy as np import networkx as nx import math # Path to the data graphml_path = resource_filename(Requirement.parse("easy_lausanne"), "data/parcellation/lausanne2008") # Path to the installed versions of the Freesurfer .gcs files gcs_path = resource_filename(Requirement.parse("easy_lausanne"), "data/colortable_and_gcs/my_atlas_gcs") lausanne_spec = { 'scale33': { 'number_of_regions': 83, # contains name, url, color, freesurfer_label, etc. used for connection matrix 'node_information_graphml': op.join(graphml_path, 'resolution83', 'resolution83.graphml'), # scalar node values on fsaverage? or atlas? 'surface_parcellation': None,
assert (len(attr_paths) <= 1) if attr_paths: return attr_paths[0] else: return None version = get_version() print('Generating component-packages.nix for version {}'.format(version)) requirements = fetch_reqs(version=version) build_inputs = {} for component, reqs in OrderedDict(sorted(requirements.items())).items(): attr_paths = [] for req in reqs: try: name = Requirement.parse(req).project_name attr_path = name_to_attr_path(name) if attr_path is not None: # Add attribute path without "python3Packages." prefix attr_paths.append(attr_path[len(PKG_SET + '.'):]) except RequirementParseError: continue else: build_inputs[component] = attr_paths # Only select components which have any dependency #build_inputs = {k: v for k, v in build_inputs.items() if len(v) > 0} with open(os.path.dirname(sys.argv[0]) + '/component-packages.nix', 'w') as f: f.write('# Generated from parse-requirements.py\n') f.write('# Do not edit!\n\n')
def _create_os_path(self, os_path, resource_path): if not os.path.exists(os_path): # stage from the conf templates lookup_path = resource_filename(Requirement.parse("mktxp"), resource_path) shutil.copy(lookup_path, os_path)
import logging import os from pkg_resources import resource_filename, Requirement import pandas as pd from pytz.exceptions import NonExistentTimeError from solarforecastarbiter.datamodel import Observation from solarforecastarbiter.io.fetch import pvdaq from solarforecastarbiter.io.reference_observations import (common, default_forecasts) logger = logging.getLogger('reference_data') DEFAULT_SITEFILE = resource_filename( Requirement.parse('solarforecastarbiter'), 'solarforecastarbiter/io/reference_observations/' 'pvdaq_reference_sites.json') def adjust_site_parameters(site): """Kludge the extra metadata in a json file into the metadata dict derived from a csv file. Parameters ---------- site: dict Returns ------- dict
def parse_requirement_arg(spec): try: return Requirement.parse(spec) except ValueError: raise DistutilsError( "Not a URL, existing file, or requirement spec: %r" % (spec, ))