def update_minor_dependency(package): """update_minor_dependency is a trivial approach to update the given package to it's current stable release. This release will be locked in the Gemfile""" logging.info("updating %s to %s" % (package['name'], package['distributions']['stable'])) OWD = os.getcwd() os.chdir(LOCAL_WORK_COPY) parser = GemfileParser('Gemfile', 'manageiq') deps = parser.parse() # lets loop thru all dependencies and if we found the thing we wanna change # open the Gemfile, walk thru all lines and change the thing for key in deps: if deps[key]: for dependency in deps[key]: if dependency.name == package['name']: with fileinput.input(files=('Gemfile'), inplace=True, backup='.swp') as Gemfile: for line in Gemfile: if '"' + dependency.name + '"' in line: line = line.replace( dependency.requirement, package['distributions']['stable'], 1) print(line.replace('\n', '', 1)) # no new line! os.chdir(OWD)
def bump_minor(package): logging.info("updating %s to %s" % (package['name'], package['distributions']['stable'])) OWD = os.getcwd() os.chdir(LOCAL_WORK_COPY) parser = GemfileParser('Gemfile', 'manageiq') deps = parser.parse() for key in deps: if deps[key]: for dependency in deps[key]: if dependency.name == package['name']: print(dependency.__dict__) with fileinput.input(files=('Gemfile'), inplace=True, backup='.swp') as f: for line in f: if '"' + dependency.name + '"' in line: line = line.replace( dependency.requirement, package['distributions']['stable'], 1) print(line) os.chdir(OWD)
def test_source_only_gemfile(): gemparser = GemfileParser('tests/Gemfile') expected = { 'development': [], 'test': [], 'runtime': [], 'metrics': [], 'production': [] } dependencies = gemparser.parse() assert_equal(dependencies, expected)
def check_gemparser_results(test_file, regen=False): """ Run GemfileParser.parse on `test_file` and check against a JSON file that contains expected results with the same name as the `test_file` with a "-expected.json" suffix appended. """ import json gemparser = GemfileParser(test_file) dependencies = { group: [dep.to_dict() for dep in deps] for group, deps in gemparser.parse().items() } expected_file = test_file + '-expected.json' if regen: with open(expected_file, 'w') as o: json.dump(dependencies, o, indent=2) with open(expected_file) as o: expected = json.load(o) assert expected == dependencies
def parse_spec(self, location): """ Return dictionary contains podspec or gemspec file data. """ with io.open(location, encoding='utf-8', closefd=True) as data: lines = data.readlines() spec_data = {} for line in lines: line = pre_process(line) match = self.parse_name.match(line) if match: name = match.group('name') spec_data['name'] = get_stripped_data(name) match = self.parse_version.match(line) if match: version = match.group('version') spec_data['version'] = get_stripped_data(version) match = self.parse_license.match(line) if match: license_value = match.group('license') spec_data['license'] = get_stripped_data(license_value) match = self.parse_summary.match(line) if match: summary = match.group('summary') spec_data['summary'] = get_stripped_data(summary) match = self.parse_homepage.match(line) if match: homepage = match.group('homepage') spec_data['homepage_url'] = get_stripped_data(homepage) match = self.parse_source.match(line) if match: source = re.sub(r'/*.*source.*?>', '', line) stripped_source = re.sub(r',.*', '', source) spec_data['source'] = get_stripped_data(stripped_source) match = self.parse_description.match(line) if match: if location.endswith('.gemspec'): # FIXME: description can be in single or multi-lines # There are many different ways to write description. description = match.group('description') spec_data['description'] = get_stripped_data(description) else: spec_data['description'] = get_description(location) if '.email' in line: _key, _sep, value = line.rpartition('=') stripped_emails = get_stripped_data(value) stripped_emails = stripped_emails.strip() stripped_emails = stripped_emails.split(',') spec_data['email'] = stripped_emails elif '.author' in line: authors = re.sub(r'/*.*author.*?=', '', line) stripped_authors = get_stripped_data(authors) stripped_authors = re.sub(r'(\s*=>\s*)', '=>', stripped_authors) stripped_authors = stripped_authors.strip() stripped_authors = stripped_authors.split(',') spec_data['author'] = stripped_authors parser = GemfileParser(location) deps = parser.parse() dependencies = {} for key in deps: depends = deps.get(key, []) or [] for dep in depends: dependencies[dep.name] = dep.requirement spec_data['dependencies'] = dependencies return spec_data
def parse_file(self, fname, file_content): parser = GemfileParser(fname) return parser.parse()
def test_gemspec(): gemparser = GemfileParser('tests/Gemfile_2') dependencies = gemparser.parse() assert_in('rails', [x.name for x in dependencies['runtime']]) assert_in('responders', [x.name for x in dependencies['development']])
def test_source(): gemparser = GemfileParser('tests/Gemfile_2') dependencies = gemparser.parse() assert_equal(dependencies['runtime'][0].source, 'http://www.example.com')
def test_group_block(): gemparser = GemfileParser('tests/Gemfile_2') dependencies = gemparser.parse() assert_equal(dependencies['development'][0].requirement, '3.0.0') assert_equal(dependencies['runtime'][0].requirement, '4.2.4')
def test_group(): gemparser = GemfileParser('tests/Gemfile_3') dependencies = gemparser.parse() assert_equal(dependencies['development'][0].requirement, '4.2.4')
def test_requirement(): gemparser = GemfileParser('tests/Gemfile_2') dependencies = gemparser.parse() assert_equal(dependencies['runtime'][0].requirement, '4.2.4')
def test_name(): gemparser = GemfileParser('tests/Gemfile_2') dependencies = gemparser.parse() assert_equal(dependencies['runtime'][0].name, 'rails')