Best Python code snippet using pandera_python
rpmspecfile.py
Source:rpmspecfile.py  
1#2# Copyright (C) 2015-2016 Red Hat, Inc.3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8#      http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15'''Basic rpm spec file parsing to be able to get the package names and16the dependencies.17'''18from __future__ import print_function19import os20import re21import sys22name_regexp = re.compile(r'^Name:\s*(.+)\s*$')23package_regexp = re.compile(r'^(Provides:|%package)\s+(-n)?\s*(.+)\s*$')24define_regexp = re.compile(r'[^#]*%(?:define|global)\s+(.+)\s+(.+)\s*$')25build_requires_regexp = re.compile(r'^(?:Build)?Requires(?:\([^\)]+\))?:'26                                   r'\s*(.+)\s*$')27class RpmSpecFile(object):28    def __init__(self, content):29        self._defines = {}30        self._packages = []31        self._build_requires = []32        self.name = '<none>'33        self._provided = {}34        for line in content.split('\n'):35            # lookup macros36            res = define_regexp.search(line)37            if res:38                self._defines[res.group(1)] = res.group(2)39            else:40                # lookup Name:41                res = name_regexp.search(line)42                if res:43                    if self.name == '<none>':44                        self.name = self._expand_defines(res.group(1))45                        self._packages.append(self.name)46                        self._defines['name'] = self.name47                else:48                    # lookup package49                    res = package_regexp.search(line)50                    if res:51                        pkg = re.split(r'\s+|[><=]',52                                       self._expand_defines(res.group(3)))[0]53                        if res.group(2) or res.group(1) == 'Provides:':54                            pkg_name = pkg55                        else:56                            pkg_name = self.name + '-' + pkg57                        self._packages.append(pkg_name)58                        self._provided[pkg_name] = self.name59                    else:60                        # lookup BuildRequires:61                        res = build_requires_regexp.search(line)62                        if res:63                            # split requires on the same lines and64                            # remove >=, <= or = clauses65                            self._build_requires.extend(66                                [re.split(r'\s+|[><=]',67                                          self._expand_defines(req))[0]68                                 for req in re.split(r'\s*,\s*',69                                                     res.group(1))])70        # remove dups71        self._build_requires = list(set(self._build_requires))72    def _expand_defines(self, content):73        lookup_start = content.find('%{')74        lookup_end = content.find('}', lookup_start)75        if (content[lookup_start:lookup_start + 2] ==76           '%{' and content[lookup_end] == '}'):77            return self._expand_defines(78                content[:lookup_start] +79                self._defines.get(content[lookup_start + 2:lookup_end], '') +80                content[lookup_end + 1:])81        return content82    def packages(self):83        return self._packages84    def build_requires(self):85        return self._build_requires86    def __lt__(self, other):87        return self.name < other.name88    def __eq__(self, other):89        return self.name == other.name90class RpmSpecCollection(object):91    def __init__(self, initial_list=None, debug=False):92        if initial_list:93            self.specs = initial_list94        else:95            self.specs = []96        self.debug = debug97    def compute_order(self):98        # sub-package to package associative array99        self.pkg = {}100        # list to return the computed order101        self.order = []102        # keep status of the progress by103        # package: 0 not processed, 1104        # processing dependencies, 2 already105        # processed106        self.color = {}107        for spec in sorted(self.specs):108            self.pkg[spec.name] = spec109            self.color[spec.name] = 0110            for pkg_name in spec.packages():111                self.pkg[pkg_name] = spec112        for spec in self.specs:113            if self.color[spec.name] == 0:114                self._visit(spec)115        return self.order116    def _visit(self, spec):117        if self.color[spec.name] == 1:118            sys.stderr.write('cycle detected on %s\n' %119                             ', '.join([k for k in self.color120                                        if self.color[k] == 1]))121        elif self.color[spec.name] == 2:122            return123        else:124            self.color[spec.name] = 1125            for breq in spec.build_requires():126                if breq in spec.packages():127                    continue128                if breq in self.pkg:129                    self._visit(self.pkg[breq])130        self.color[spec.name] = 2131        self.order.append(spec.name)132def _main():133    if len(sys.argv) > 2:134        # output the graph in a graphviz compliant format if -g is passed135        if sys.argv[1] == '-g':136            specs = RpmSpecCollection([RpmSpecFile(open(arg).read(-1))137                                       for arg in sys.argv[2:]],138                                      debug=os.getenv('DEBUG'))139            specnames = specs.compute_order()140            print('digraph G {')141            for spec in specs.specs:142                if spec.name not in specnames:143                    continue144                for breq in spec.build_requires():145                    if breq not in spec.packages() and breq in specs.pkg:146                        print('  "%s" -> "%s";' %147                              (spec.name, specs.pkg[breq].name))148            print('}')149        else:150            specs = RpmSpecCollection([RpmSpecFile(open(arg).read(-1))151                                       for arg in sys.argv[1:]],152                                      debug=os.getenv('DEBUG'))153            print('Build order:')154            print('\n'.join(specs.compute_order()))155    else:156        spec = RpmSpecFile(open(sys.argv[1]).read(-1))157        print('Packages:', ', '.join(spec.packages()))158        print('BuildRequires:', ', '.join(spec.build_requires()))159if __name__ == "__main__":160    _main()...cmsgemos.setupTemplate.py
Source:cmsgemos.setupTemplate.py  
1import os, sys2from distutils.core import setup3from os.path import join4_rpmVersion       = '__version__'5_name             = '__packagename__'6_author           = '__author__'7_author_email     = '__email__'8_description      = '__summary__'9_long_description = '__description__'10_url              = '__url__'11# _requires         = __requires__12# _build_requires   = __build_requires__13_packages         = __python_packages__14_license          = 'MIT'15def readme():16    with open('README.md') as f:17        return f.read()18def getreqs():19    with open('requirements.txt') as f:20        reqs = f.readlines()21        return [x.strip() for x in reqs]22setup(name=_name,23      version          = _rpmVersion,24      description      = __description__,25      long_description = __long_description__,26      # long_description = readme(),27      author = 'GEM Online Systems Group',28      author_email = 'cms-gem-online-sw@cern.ch',29      url = 'https://cmsgemdaq.web.cern.ch/cmsgemdaq/',30      # author           = __author__,31      # author_email     = __author_email__,32      # url              = __url__,33      license          = _license,34      requires         = getreqs(),35      # build_requires   = _build_requires,36      packages         = _packages,37      package_dir      = {'' : ''},38      package_data     = dict((pkg,['*.so']) for pkg in _packages)...__init__.py
Source:__init__.py  
...34class ParseError(LocatedError):35    def __init__(self, *args, loc=None):36        super().__init__(*args, loc=loc, phase="parse")37parse_assert = _build_assert(ParseError)38parse_requires = _build_requires(ParseError)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
