From b8414e1341f26fa15429b1dfc0cf2bb7e13800b5 Mon Sep 17 00:00:00 2001 From: satwikkansal Date: Sat, 1 Jul 2017 23:17:25 +0530 Subject: [PATCH 01/32] setup.py: Move 'nose' to tests_require Moves 'nose' from ``install_requires`` field to ``tests_require`` field of config object as 'nose' is not required for installation of the package but only for running the tests. Fixes https://gitlab.com/balasankarc/gemfileparser/issues/1 --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 68af29e..7ab43dc 100644 --- a/setup.py +++ b/setup.py @@ -82,7 +82,8 @@ .. _GNU GPL version 3 (or above) License: http://www.gnu.org/licenses/gpl ''', - 'install_requires': ['nose'], + 'install_requires': [], + 'tests_require': ['nose'], 'packages': ['gemfileparser'], 'scripts': [], 'name': 'gemfileparser' From fc21e53cf1f1e95271cb824a229d5f953c789918 Mon Sep 17 00:00:00 2001 From: "Balasankar \"Balu\" C" Date: Sat, 25 Jul 2020 12:59:03 +0530 Subject: [PATCH 02/32] Update metadata to reflect project maintainership changes Signed-off-by: Balasankar "Balu" C --- AUTHORS | 7 +++++++ LICENSE.GPLv3 | 3 +++ LICENSE.MIT | 3 ++- README.md | 11 +++++++---- setup.py | 4 ++-- 5 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..d91450a --- /dev/null +++ b/AUTHORS @@ -0,0 +1,7 @@ +# This file lists contributors who made significant contribution to +# gemfileparser. This file is not intended to list every contributor to the +# project, though. For that, check the Git revision history. +# +# Names are in alphabetical order, for the sanity of mind. + +1. Balasankar C diff --git a/LICENSE.GPLv3 b/LICENSE.GPLv3 index 733c072..67fbccd 100644 --- a/LICENSE.GPLv3 +++ b/LICENSE.GPLv3 @@ -1,3 +1,6 @@ +Copyright (c) 2020 Gemfileparser authors (listed in AUTHORS file) + 2015-2018 Balasankar C + GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 diff --git a/LICENSE.MIT b/LICENSE.MIT index c8c60e0..1b71000 100644 --- a/LICENSE.MIT +++ b/LICENSE.MIT @@ -1,6 +1,7 @@ MIT License -Copyright (c) 2018 Balasankar C +Copyright (c) 2020 Gemfileparser authors (listed in AUTHORS file) + 2015-2018 Balasankar C Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index d3bee9a..b644d8e 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,14 @@ for key in deps: ``` ### Copyright +2020 Gemfileparser authors (listed in AUTHORS file) 2015-2018 Balasankar C ### License -gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License](http://www.gnu.org/licenses/gpl) and [MIT License](https://opensource.org/licenses/MIT). -Personally, I prefer anyone using this to respect the GPL license and use that -itself for derivative works - thus making them also Free Software. But, your -call. +gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License](http://www.gnu.org/licenses/gpl) +and [MIT License](https://opensource.org/licenses/MIT). + +It is preferred anyone using this project to respect the GPL-3+ license and use +that itself for derivative works - thus making them also Free Software. But, +your call. diff --git a/setup.py b/setup.py index fb27414..53fe9dc 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +7,8 @@ config = { 'description': "Parse Ruby's Gemfiles", 'author': 'Balasankar C', - 'url': 'https://gitlab.com/balasankarc/gemfileparser', - 'download_url': 'https://gitlab.com/balasankarc/gemfileparser', + 'url': 'https://github.com/gemfileparser/gemfileparser', + 'download_url': 'https://github.com/gemfileparser/gemfileparser', 'author_email': 'balasankarc@autistici.org', 'version': '0.7.0', 'license': 'GPL-3+ and MIT', From 363d8a586c3749254eeba78056f73a5db7740b3a Mon Sep 17 00:00:00 2001 From: "Balasankar \"Balu\" C" Date: Sat, 25 Jul 2020 13:02:53 +0530 Subject: [PATCH 03/32] Further cleanup to match new maintainership reality Signed-off-by: Balasankar "Balu" C --- README.md | 6 +++--- gemfileparser/__init__.py | 14 -------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b644d8e..e735769 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Parse Ruby Gemfile's using Python. Supports Gemfiles and .gemspec files. If using pip, use the command `sudo pip install gemfileparser` Else use the following commands ``` -git clone https://github.com/balasankarc/gemfileparser.git +git clone https://github.com/gemfileparser/gemfileparser.git cd gemfileparser python setup.py install ``` @@ -48,8 +48,8 @@ for key in deps: ``` ### Copyright -2020 Gemfileparser authors (listed in AUTHORS file) -2015-2018 Balasankar C +* 2020 Gemfileparser authors (listed in AUTHORS file) +* 2015-2018 Balasankar C ### License diff --git a/gemfileparser/__init__.py b/gemfileparser/__init__.py index 84b82f4..4c61dba 100644 --- a/gemfileparser/__init__.py +++ b/gemfileparser/__init__.py @@ -1,18 +1,4 @@ #!/usr/bin/env python -# -# Copyright 2015 Balasankar C -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# . -# This program 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 this program. If not, see . '''Python library to parse Ruby's Gemfiles and gemspec files.''' From 58f72a5b3ab7b118f9bc4d4f78897873eabb83e9 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Sat, 25 Jul 2020 19:31:12 +0200 Subject: [PATCH 04/32] Clarify license metadata Do not use ambiguous classifier. Use instead an SPDX license expression. Signed-off-by: Philippe Ombredanne --- setup.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 53fe9dc..b9232a0 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ 'download_url': 'https://github.com/gemfileparser/gemfileparser', 'author_email': 'balasankarc@autistici.org', 'version': '0.7.0', - 'license': 'GPL-3+ and MIT', + 'license': 'GPL-3.0-or-later OR MIT', 'long_description': ''' Installation ~~~~~~~~~~~~ @@ -78,7 +78,8 @@ License ~~~~~~~ -gemfileparser is released under two licenses: `GNU GPL version 3 (or above) License` and `MIT License`_. +gemfileparser is released under a choice of two licenses: `GNU GPL version 3 (or above) License` +or `MIT License`_. .. _GNU GPL version 3 (or above) License: http://www.gnu.org/licenses/gpl ''', @@ -93,8 +94,6 @@ classifiers=[ # Indicate who your project is intended for 'Intended Audience :: Developers', - 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', - 'License :: OSI Approved :: MIT', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.4', ], **config) From b2333dd56829a10f8087fd33ff4789728b07e436 Mon Sep 17 00:00:00 2001 From: rpotter12 Date: Sun, 26 Jul 2020 00:03:26 +0530 Subject: [PATCH 05/32] add regex to detect all types of dependency Signed-off-by: rpotter12 --- gemfileparser/__init__.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/gemfileparser/__init__.py b/gemfileparser/__init__.py index 4c61dba..bce603d 100644 --- a/gemfileparser/__init__.py +++ b/gemfileparser/__init__.py @@ -47,9 +47,11 @@ def __init__(self): group_block_regex = re.compile( r"group[ ]?:[ ]?(?P.*?) do") add_dvtdep_regex = re.compile( - r".*add_development_dependency (?P.*)") + r".*add_development_dependency(?P.*)") add_rundep_regex = re.compile( - r".*add_runtime_dependency (?P.*)") + r".*add_runtime_dependency(?P.*)") + add_dep_regex = re.compile( + r".*dependency(?P.*)") def __init__(self, filepath, appname=''): self.filepath = filepath # Required when calls to gemspec occurs @@ -58,12 +60,14 @@ def __init__(self, filepath, appname=''): self.dependencies = { 'development': [], 'runtime': [], + 'dependency': [], 'test': [], 'production': [], 'metrics': [] } self.contents = self.gemfile.readlines() - if filepath.endswith('gemspec'): + path = ('gemspec', 'podspec') + if filepath.endswith(path): self.gemspec = True else: self.gemspec = False @@ -96,6 +100,11 @@ def parse_line(self, line): for column in line: stripped_column = column.replace("'", "") stripped_column = stripped_column.replace('"', "") + stripped_column = stripped_column.replace("%q<", "") + stripped_column = stripped_column.replace("(", "") + stripped_column = stripped_column.replace(")", "") + stripped_column = stripped_column.replace("[", "") + stripped_column = stripped_column.replace("]", "") stripped_column = stripped_column.strip() column_list.append(stripped_column) dep = self.Dependency() @@ -165,6 +174,10 @@ def parse_gemspec(self, path=''): match = GemfileParser.add_rundep_regex.match(line) if match: GemfileParser.global_group = 'runtime' + else: + match = GemfileParser.add_dep_regex.match(line) + if match: + GemfileParser.global_group = 'dependency' if match: line = match.group('line') self.parse_line(line) @@ -176,4 +189,4 @@ def parse(self): if self.gemspec: return self.parse_gemspec() else: - return self.parse_gemfile() + return self.parse_gemfile() \ No newline at end of file From 6c2e97f9283ece1817a4a3a360cec25584c610e7 Mon Sep 17 00:00:00 2001 From: rpotter12 Date: Sun, 26 Jul 2020 00:05:50 +0530 Subject: [PATCH 06/32] add contributor Signed-off-by: rpotter12 --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index d91450a..5ee62e0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,3 +5,4 @@ # Names are in alphabetical order, for the sanity of mind. 1. Balasankar C +2. Rohit Potter \ No newline at end of file From 537c9c59c7ad9b724ad49b46c6e74368fb93652c Mon Sep 17 00:00:00 2001 From: rpotter12 Date: Sun, 26 Jul 2020 14:49:33 +0530 Subject: [PATCH 07/32] remove unnecessary path variable name Signed-off-by: rpotter12 --- gemfileparser/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gemfileparser/__init__.py b/gemfileparser/__init__.py index bce603d..d2221e4 100644 --- a/gemfileparser/__init__.py +++ b/gemfileparser/__init__.py @@ -66,8 +66,7 @@ def __init__(self, filepath, appname=''): 'metrics': [] } self.contents = self.gemfile.readlines() - path = ('gemspec', 'podspec') - if filepath.endswith(path): + if filepath.endswith(('.gemspec', '.podspec')): self.gemspec = True else: self.gemspec = False From cec4ff00138af733fef537c14269ff42c0d4b567 Mon Sep 17 00:00:00 2001 From: rpotter12 Date: Sun, 26 Jul 2020 14:57:59 +0530 Subject: [PATCH 08/32] remove nose install require Signed-off-by: rpotter12 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 53fe9dc..b422a71 100644 --- a/setup.py +++ b/setup.py @@ -83,7 +83,7 @@ .. _GNU GPL version 3 (or above) License: http://www.gnu.org/licenses/gpl ''', 'install_requires': [], - 'tests_require': ['nose'], + 'tests_require': [], 'packages': ['gemfileparser'], 'scripts': [], 'name': 'gemfileparser' From f96996e171f0188d79850e78f53b0500bd866aeb Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Tue, 18 Aug 2020 13:46:49 +0200 Subject: [PATCH 09/32] Clarify license in README (#12) Clarify that: * this is a choice of license * contributions are also made under that dual license Signed-off-by: Philippe Ombredanne --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e735769..36992de 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,13 @@ for key in deps: ### License -gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License](http://www.gnu.org/licenses/gpl) -and [MIT License](https://opensource.org/licenses/MIT). +gemfileparser is dual-licensed under your choice of the +[GNU GPL version 3 (or later) License](http://www.gnu.org/licenses/gpl) +or the [MIT License](https://opensource.org/licenses/MIT). It is preferred anyone using this project to respect the GPL-3+ license and use that itself for derivative works - thus making them also Free Software. But, your call. + +When making contributions to gemfileparser you agree to license these contributions +under the same choice of licenses. From 032664b0a647f9fc92e7cffbb87c043d38c1d5cf Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 12:42:08 +0200 Subject: [PATCH 10/32] Add license header Signed-off-by: Philippe Ombredanne --- gemfileparser/__init__.py | 44 ++++++++++++++++++++++++++++++++++++ tests/gemfileparser_tests.py | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/gemfileparser/__init__.py b/gemfileparser/__init__.py index d2221e4..1b6f900 100644 --- a/gemfileparser/__init__.py +++ b/gemfileparser/__init__.py @@ -1,4 +1,48 @@ #!/usr/bin/env python +# +# Copyright 2015 Balasankar C + +# gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License] +# (http://www.gnu.org/licenses/gpl) +# and [MIT License](https://opensource.org/licenses/MIT). + +# Personally, I prefer anyone using this to respect the GPL license and use that +# itself for derivative works - thus making them also Free Software. But, your +# call. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# . +# This program 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 this program. If not, see . + + +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. '''Python library to parse Ruby's Gemfiles and gemspec files.''' diff --git a/tests/gemfileparser_tests.py b/tests/gemfileparser_tests.py index 73c5d7d..78a6e89 100644 --- a/tests/gemfileparser_tests.py +++ b/tests/gemfileparser_tests.py @@ -1,4 +1,48 @@ #!/usr/bin/env python +# +# Copyright 2015 Balasankar C + +# gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License] +# (http://www.gnu.org/licenses/gpl) +# and [MIT License](https://opensource.org/licenses/MIT). + +# Personally, I prefer anyone using this to respect the GPL license and use that +# itself for derivative works - thus making them also Free Software. But, your +# call. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# . +# This program 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 this program. If not, see . + + +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. from nose.tools import assert_equal, assert_in from gemfileparser import GemfileParser From e0bd8a6c9fbc164ca3a33bee3385664c08e3c0c2 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 12:45:49 +0200 Subject: [PATCH 11/32] Update README Signed-off-by: Philippe Ombredanne --- README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 36992de..2f80e73 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ # gemfileparser -Parse Ruby Gemfile's using Python. Supports Gemfiles and .gemspec files. +Parse Ruby Gemfile using Python. Support Ruby Gemfiles and .gemspec files +as well as Cocoapod .podspec files. ### Installation -If using pip, use the command `sudo pip install gemfileparser` -Else use the following commands +In a virtualenv, use the command `pip install gemfileparser` + +Else if using a git clone, use the following commands: + ``` git clone https://github.com/gemfileparser/gemfileparser.git cd gemfileparser @@ -25,7 +28,7 @@ The parse() method returns a dict object of the following format . .} ``` -Each dependency object contains the following attributes +Each dependency object contains the following attributes: ``` name - Name of the gem requirement - Version requirement @@ -48,8 +51,8 @@ for key in deps: ``` ### Copyright -* 2020 Gemfileparser authors (listed in AUTHORS file) -* 2015-2018 Balasankar C +* Copyright (c) 2020 Gemfileparser authors (listed in AUTHORS file) +* Copyright (c) 2015-2018 Balasankar C ### License From 5646bf5c7ac35f78e3639557766f829fff109c86 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 12:46:25 +0200 Subject: [PATCH 12/32] Rename README.md to README.rst Signed-off-by: Philippe Ombredanne --- README.md => README.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => README.rst (100%) diff --git a/README.md b/README.rst similarity index 100% rename from README.md rename to README.rst From 4c42b84f309543c1b15caed59ae948806cedcdc1 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:01:34 +0200 Subject: [PATCH 13/32] Move bin command line script to function Next is to add a setuptools entry point Signed-off-by: Philippe Ombredanne --- gemfileparser/__init__.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/gemfileparser/__init__.py b/gemfileparser/__init__.py index 1b6f900..d050e82 100644 --- a/gemfileparser/__init__.py +++ b/gemfileparser/__init__.py @@ -1,9 +1,9 @@ #!/usr/bin/env python # -# Copyright 2015 Balasankar C +# Copyright (c) Balasankar C and others # gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License] -# (http://www.gnu.org/licenses/gpl) +# (http://www.gnu.org/licenses/gpl) # and [MIT License](https://opensource.org/licenses/MIT). # Personally, I prefer anyone using this to respect the GPL license and use that @@ -22,8 +22,8 @@ # . # You should have received a copy of the GNU General Public License # along with this program. If not, see . - - +# +# # MIT License # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -32,10 +32,10 @@ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -98,7 +98,7 @@ def __init__(self): r".*dependency(?P.*)") def __init__(self, filepath, appname=''): - self.filepath = filepath # Required when calls to gemspec occurs + self.filepath = filepath # Required when calls to gemspec occurs self.gemfile = open(filepath) self.appname = appname self.dependencies = { @@ -137,7 +137,7 @@ def parse_line(self, line): line = unicode(line) except NameError: pass - linefile = io.StringIO(line) # csv requires a file object + linefile = io.StringIO(line) # csv requires a file object for line in csv.reader(linefile, delimiter=','): column_list = [] for column in line: @@ -232,4 +232,21 @@ def parse(self): if self.gemspec: return self.parse_gemspec() else: - return self.parse_gemfile() \ No newline at end of file + return self.parse_gemfile() + + +def command_line(): + """ + A minimal command line entry point. + """ + import sys + if len(sys.argv) < 2: + print("Usage : parsegemfile ") + sys.exit(0) + + parsed = GemfileParser(sys.argv[1]) + output = parsed.parse() + for key, value in list(output.items()): + print(key, ":") + for item in value: + print("\t", item) From 00fd2c69edf87343b5bcdee7df3730e35078f6fd Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:04:28 +0200 Subject: [PATCH 14/32] Use proper ReST for README Signed-off-by: Philippe Ombredanne --- README.rst | 122 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 53 deletions(-) diff --git a/README.rst b/README.rst index 2f80e73..b3eea8a 100644 --- a/README.rst +++ b/README.rst @@ -1,64 +1,80 @@ -# gemfileparser -Parse Ruby Gemfile using Python. Support Ruby Gemfiles and .gemspec files +============= +gemfileparser +============= + +gemfileparser parses Ruby Gemfile using Python with supports Ruby Gemfiles and .gemspec files as well as Cocoapod .podspec files. -### Installation -In a virtualenv, use the command `pip install gemfileparser` - -Else if using a git clone, use the following commands: - -``` -git clone https://github.com/gemfileparser/gemfileparser.git -cd gemfileparser -python setup.py install -``` - -### Usage -``` -from gemfileparser import GemfileParser -parser = GemfileParser(, ) -dependency_dictionary = parser.parse() -``` -The parse() method returns a dict object of the following format -``` -{ -'development': [list of dependency objects inside group 'development'], -'runtime': [list of runtime dependency objects], -. -. -.} -``` + +Installation +~~~~~~~~~~~~ + +In a virtualenv, use the command:: + + pip install gemfileparser + +Otherwise from a git clone, use the following commands in a virtualenv:: + + git clone https://github.com/gemfileparser/gemfileparser.git + cd gemfileparser + python setup.py install + + +Usage +~~~~~ + +:: + + from gemfileparser import GemfileParser + parser = GemfileParser(, ) + dependency_dictionary = parser.parse() + +The parse() method returns a dict object of the following format:: + + { + 'development': [list of dependency objects inside group 'development'], + 'runtime': [list of runtime dependency objects], + . + . + .} + Each dependency object contains the following attributes: -``` -name - Name of the gem -requirement - Version requirement -autorequire - Autorequire value -source - Source URL of the gem -parent - Dependency of which gem -group - Group in which gem is a member of (default : runtime) -``` - -#### Example -``` -from gemfileparser import GemfileParser -n = GemfileParser('Gemfile', 'diaspora') -deps = n.parse() -for key in deps: - if deps[key]: - print key - for dependency in deps[key]: - print "\t", dependency -``` - -### Copyright + +- name - Name of the gem +- requirement - Version requirement +- autorequire - Autorequire value +- source - Source URL of the gem +- parent - Dependency of which gem +- group - Group that a gem is a member of (default : runtime) + + +Example +~~~~~~~ + +:: + + from gemfileparser import GemfileParser + n = GemfileParser('Gemfile', 'diaspora') + deps = n.parse() + for key in deps: + if deps[key]: + print key + for dependency in deps[key]: + print("\t", dependency) + + +Copyright +~~~~~~~~~ * Copyright (c) 2020 Gemfileparser authors (listed in AUTHORS file) * Copyright (c) 2015-2018 Balasankar C -### License + +License +~~~~~~~ gemfileparser is dual-licensed under your choice of the -[GNU GPL version 3 (or later) License](http://www.gnu.org/licenses/gpl) -or the [MIT License](https://opensource.org/licenses/MIT). +`GNU GPL version 3 (or later) License `_ +or the `MIT License `_. It is preferred anyone using this project to respect the GPL-3+ license and use that itself for derivative works - thus making them also Free Software. But, From acc88512233a9371eb337fb828cc6f04a461ea4f Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:04:49 +0200 Subject: [PATCH 15/32] Ignore tmp Signed-off-by: Philippe Ombredanne --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 203bef6..1c7a8cb 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,4 @@ docs/_build/ # PyBuilder target/ +/tmp/ From 95c5b12a2303e70a9dac0a0225d8f741cd37e8d9 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:05:15 +0200 Subject: [PATCH 16/32] Remove script that has been migrated to function Signed-off-by: Philippe Ombredanne --- bin/parsegemfile | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100755 bin/parsegemfile diff --git a/bin/parsegemfile b/bin/parsegemfile deleted file mode 100755 index 6fc82f4..0000000 --- a/bin/parsegemfile +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python - -import sys -sys.path.insert(0, '../gemfileparser') - -from gemfileparser import GemfileParser - -if len(sys.argv) < 2: - print("Usage : parsegemfile ") - sys.exit(0) - -parsed = GemfileParser(sys.argv[1]) -output = parsed.parse() -for key, value in list(output.items()): - print(key, ":") - for item in value: - print("\t", item) From 2c15ffea1df6cb542dbc708eec5b104a88401a21 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:05:34 +0200 Subject: [PATCH 17/32] Remove numbers from authors list Signed-off-by: Philippe Ombredanne --- AUTHORS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 5ee62e0..84dfeb1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,5 +4,5 @@ # # Names are in alphabetical order, for the sanity of mind. -1. Balasankar C -2. Rohit Potter \ No newline at end of file +- Balasankar C +- Rohit Potter \ No newline at end of file From 6912f965d6b7ddd0131b15420b400d58a810e2dc Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:05:46 +0200 Subject: [PATCH 18/32] Add MANIFEST.in for sdist Signed-off-by: Philippe Ombredanne --- MANIFEST.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..b0b0a2b --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,12 @@ +graft gemfileparser +graft tests + +include AUTHORS +include LICENSE.GPLv3 +include LICENSE.MIT +include MANIFEST.in +include README.rst +include setup.cfg +include setup.py + +global-exclude *.py[co] __pycache__ *.*~ From 91c2c53a4bd1193f66c9b60bfc75de5bb0c3de9e Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:06:03 +0200 Subject: [PATCH 19/32] Remove unused requirements.txt Signed-off-by: Philippe Ombredanne --- requirements.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index d691302..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -setuptools==32.0.0 -nose==1.3.7 From f127bd6a73e0327868cfcae4e9686a4340817d77 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:07:13 +0200 Subject: [PATCH 20/32] Use setup.cfg for setup metadata And also add console script entry point Signed-off-by: Philippe Ombredanne --- setup.cfg | 38 +++++++++++++++++++- setup.py | 101 ++++-------------------------------------------------- 2 files changed, 44 insertions(+), 95 deletions(-) diff --git a/setup.cfg b/setup.cfg index b88034e..d4de8d4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,38 @@ +[bdist_wheel] +universal = 1 + [metadata] -description-file = README.md +name = gemfileparser +version = 0.8.0 + +description = Parse Ruby Gemfile, .gemspec and Cocoapod .podspec files using Python. +long_description = file: README.rst + +author = Balasankar C +author_email = balasankarc@autistici.org + +keywords = Ruby Rubygem Gemfile gemspec Cocoapod podspec +url = https://github.com/gemfileparser/gemfileparser + +license = GPL-3.0-or-later OR MIT +license_files = + README.rst + LICENSE.GPLv3 + LICENSE.MIT + +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Developers + Operating System :: OS Independent + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Topic :: Utilities + +[options] +zip_safe = False +include_package_data = True +packages = find: diff --git a/setup.py b/setup.py index bd82471..2f2a4c6 100644 --- a/setup.py +++ b/setup.py @@ -1,99 +1,12 @@ # -*- coding: utf-8 -*- -try: - from setuptools import setup -except ImportError: - from distutils.core import setup -config = { - 'description': "Parse Ruby's Gemfiles", - 'author': 'Balasankar C', - 'url': 'https://github.com/gemfileparser/gemfileparser', - 'download_url': 'https://github.com/gemfileparser/gemfileparser', - 'author_email': 'balasankarc@autistici.org', - 'version': '0.7.0', - 'license': 'GPL-3.0-or-later OR MIT', - 'long_description': ''' -Installation -~~~~~~~~~~~~ +from setuptools import setup -| If using pip, use the command ``sudo pip install gemfileparser`` -| Else use the following commands - -:: - - git clone https://github.com/balasankarc/gemfileparser.git - cd gemfileparser - python setup.py install - -Usage -~~~~~ - -:: - - from gemfileparser import GemfileParser - parser = GemfileParser(, ) - dependency_dictionary = parser.parse() - -The parse() method returns a dict object of the following format - -:: - - { - 'development': [list of dependency objects inside group 'development'], - 'runtime': [list of runtime dependency objects], - . - . - .} - -Each dependency object contains the following attributes - -:: - - name - Name of the gem - requirement - Version requirement - autorequire - Autorequire value - source - Source URL of the gem - parent - Dependency of which gem - group - Group in which gem is a member of (default : runtime) - -Example -^^^^^^^ - -:: - - from gemfileparser import GemfileParser - n = GemfileParser('Gemfile', 'diaspora') - deps = n.parse() - for key in deps: - if deps[key]: - print key - for dependency in deps[key]: - print "\t", dependency - -Copyright -~~~~~~~~~ - -2015-2018 Balasankar C balasankarc@autistici.org - -License -~~~~~~~ - -gemfileparser is released under a choice of two licenses: `GNU GPL version 3 (or above) License` -or `MIT License`_. - -.. _GNU GPL version 3 (or above) License: http://www.gnu.org/licenses/gpl -''', - 'install_requires': [], - 'tests_require': [], - 'packages': ['gemfileparser'], - 'scripts': [], - 'name': 'gemfileparser' -} setup( - classifiers=[ - # Indicate who your project is intended for - 'Intended Audience :: Developers', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4', - ], **config) + entry_points={ + 'console_scripts': [ + 'parsegemfile = gemfileparser:command_line', + ], + }, +) \ No newline at end of file From 793d1834a899c352b5873f409c4f7b42f8fb939b Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:07:41 +0200 Subject: [PATCH 21/32] Remove __init__.py file that is not needed Signed-off-by: Philippe Ombredanne --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 From 90bedddbc01dd48a0a7a12fef40e66790065ba1f Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:14:41 +0200 Subject: [PATCH 22/32] Make tests pass. Remove nose dependency Signed-off-by: Philippe Ombredanne --- tests/gemfileparser_tests.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/gemfileparser_tests.py b/tests/gemfileparser_tests.py index 78a6e89..20ab6cc 100644 --- a/tests/gemfileparser_tests.py +++ b/tests/gemfileparser_tests.py @@ -3,7 +3,7 @@ # Copyright 2015 Balasankar C # gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License] -# (http://www.gnu.org/licenses/gpl) +# (http://www.gnu.org/licenses/gpl) # and [MIT License](https://opensource.org/licenses/MIT). # Personally, I prefer anyone using this to respect the GPL license and use that @@ -23,7 +23,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - # MIT License # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -32,10 +31,10 @@ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -44,56 +43,56 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from nose.tools import assert_equal, assert_in from gemfileparser import GemfileParser def test_source_only_gemfile(): gemparser = GemfileParser('tests/Gemfile') expected = { + 'dependency': [], 'development': [], 'test': [], - 'runtime': [], 'metrics': [], - 'production': []} + 'runtime': [], + 'production': [], + } dependencies = gemparser.parse() - assert_equal(dependencies, expected) + assert expected == dependencies def test_name(): gemparser = GemfileParser('tests/Gemfile_2') dependencies = gemparser.parse() - assert_equal(dependencies['runtime'][0].name, 'rails') + assert 'rails' == dependencies['runtime'][0].name def test_requirement(): gemparser = GemfileParser('tests/Gemfile_2') dependencies = gemparser.parse() - assert_equal(dependencies['runtime'][0].requirement, '4.2.4') + assert ['4.2.4'] == dependencies['runtime'][0].requirement def test_group(): gemparser = GemfileParser('tests/Gemfile_3') dependencies = gemparser.parse() - assert_equal(dependencies['development'][0].requirement, '4.2.4') + assert ['4.2.4'] == dependencies['development'][0].requirement 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') + assert ['3.0.0'] == dependencies['development'][0].requirement + assert ['4.2.4'] == dependencies['runtime'][0].requirement def test_source(): gemparser = GemfileParser('tests/Gemfile_2') dependencies = gemparser.parse() - assert_equal(dependencies['runtime'][0].source, - 'http://www.example.com') + assert 'http://www.example.com' == dependencies['runtime'][0].source 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']]) + assert 'rails' in [x.name for x in dependencies['runtime']] + assert 'responders' in [x.name for x in dependencies['development']] From f82b43e20cf64d96766bf060936a77ef4e9b7bf6 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:16:33 +0200 Subject: [PATCH 23/32] Rename test file Signed-off-by: Philippe Ombredanne --- tests/{gemfileparser_tests.py => test_gemfileparser.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{gemfileparser_tests.py => test_gemfileparser.py} (100%) diff --git a/tests/gemfileparser_tests.py b/tests/test_gemfileparser.py similarity index 100% rename from tests/gemfileparser_tests.py rename to tests/test_gemfileparser.py From 8d6832e4b2b81090e4872d63809957d8e6b02621 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:17:04 +0200 Subject: [PATCH 24/32] Add tests section to README Signed-off-by: Philippe Ombredanne --- README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.rst b/README.rst index b3eea8a..2f24d1d 100644 --- a/README.rst +++ b/README.rst @@ -63,6 +63,16 @@ Example print("\t", dependency) +Tests +~~~~~ + +Do this to run tests:: + + pip install -e . + pip install pytest + pytest -vvs tests + + Copyright ~~~~~~~~~ * Copyright (c) 2020 Gemfileparser authors (listed in AUTHORS file) From a4e29098e5b8cc8fac1bb69557fbec99e7f9661e Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:17:55 +0200 Subject: [PATCH 25/32] Ignore .pytest_cache Signed-off-by: Philippe Ombredanne --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1c7a8cb..62c6571 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,4 @@ docs/_build/ # PyBuilder target/ /tmp/ +/.pytest_cache/ From 7b5f3a5b26b648d13b2cccfaf73b6f5ce3802807 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:38:56 +0200 Subject: [PATCH 26/32] Add Dependency.to_dict method, extract class and sort imports Signed-off-by: Philippe Ombredanne --- gemfileparser/__init__.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/gemfileparser/__init__.py b/gemfileparser/__init__.py index d050e82..a317b5b 100644 --- a/gemfileparser/__init__.py +++ b/gemfileparser/__init__.py @@ -46,27 +46,40 @@ '''Python library to parse Ruby's Gemfiles and gemspec files.''' +import collections import csv +import glob import io -import re import os -import glob -import collections +import re + + +class Dependency(object): + ''' A class to hold information about a dependency gem.''' + + def __init__(self): + self.name = '' + self.requirement = [] + self.autorequire = '' + self.source = '' + self.parent = [] + self.group = '' + + def to_dict(self): + return dict( + name=self.name, + requirement=self.requirement, + autorequire=self.autorequire, + source=self.source, + parent=self.parent, + group=self.group, + ) class GemfileParser(object): '''Creates a GemfileParser object to perform operations. ''' - class Dependency(object): - ''' A class to hold information about a dependency gem.''' - - def __init__(self): - self.name = '' - self.requirement = [] - self.autorequire = '' - self.source = '' - self.parent = [] - self.group = '' + Dependency = Dependency gemfile_regexes = collections.OrderedDict() gemfile_regexes['source'] = re.compile( From f0d91c763d4cdc1d9c39027324aa2580fbe5fa70 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:55:03 +0200 Subject: [PATCH 27/32] Do not use globals for group Signed-off-by: Philippe Ombredanne --- gemfileparser/__init__.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/gemfileparser/__init__.py b/gemfileparser/__init__.py index a317b5b..a8bd1c6 100644 --- a/gemfileparser/__init__.py +++ b/gemfileparser/__init__.py @@ -79,8 +79,6 @@ def to_dict(self): class GemfileParser(object): '''Creates a GemfileParser object to perform operations. ''' - Dependency = Dependency - gemfile_regexes = collections.OrderedDict() gemfile_regexes['source'] = re.compile( r"source:[ ]?(?P[a-zA-Z:\/\.-]+)") @@ -100,7 +98,7 @@ class GemfileParser(object): r"(?P[a-zA-Z]+[\.0-9a-zA-Z _-]*)") gemfile_regexes['requirement'] = re.compile( r"(?P([>|<|=|~>|\d]+[ ]*[0-9\.\w]+[ ,]*)+)") - global_group = 'runtime' + group_block_regex = re.compile( r"group[ ]?:[ ]?(?P.*?) do") add_dvtdep_regex = re.compile( @@ -112,7 +110,9 @@ class GemfileParser(object): def __init__(self, filepath, appname=''): self.filepath = filepath # Required when calls to gemspec occurs - self.gemfile = open(filepath) + + self.current_group = 'runtime' + self.appname = appname self.dependencies = { 'development': [], @@ -120,9 +120,11 @@ def __init__(self, filepath, appname=''): 'dependency': [], 'test': [], 'production': [], - 'metrics': [] + 'metrics': [], } - self.contents = self.gemfile.readlines() + with open(filepath) as gf: + self.contents = gf.readlines() + if filepath.endswith(('.gemspec', '.podspec')): self.gemspec = True else: @@ -163,8 +165,8 @@ def parse_line(self, line): stripped_column = stripped_column.replace("]", "") stripped_column = stripped_column.strip() column_list.append(stripped_column) - dep = self.Dependency() - dep.group = GemfileParser.global_group + dep = Dependency() + dep.group = self.current_group dep.parent.append(self.appname) for column in column_list: # Check for a match in each regex and assign to @@ -197,9 +199,9 @@ def parse_gemfile(self, path=''): elif line.startswith('group'): match = self.group_block_regex.match(line) if match: - GemfileParser.global_group = match.group('groupblock') + self.current_group = match.group('groupblock') elif line.startswith('end'): - GemfileParser.global_group = 'runtime' + self.current_group = 'runtime' elif line.startswith('gemspec'): # Gemfile contains a call to gemspec gemfiledir = os.path.dirname(self.filepath) @@ -225,15 +227,15 @@ def parse_gemspec(self, path=''): line = self.preprocess(line) match = GemfileParser.add_dvtdep_regex.match(line) if match: - GemfileParser.global_group = 'development' + self.current_group = 'development' else: match = GemfileParser.add_rundep_regex.match(line) if match: - GemfileParser.global_group = 'runtime' + self.current_group = 'runtime' else: match = GemfileParser.add_dep_regex.match(line) if match: - GemfileParser.global_group = 'dependency' + self.current_group = 'dependency' if match: line = match.group('line') self.parse_line(line) From ce1b4ed6873e25a4773a42c1933d85440557cee1 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 14:56:02 +0200 Subject: [PATCH 28/32] Make tests data driven Use JSON expected files and add more tests Signed-off-by: Philippe Ombredanne --- tests/Gemfile-expected.json | 8 + tests/Gemfile_1-expected.json | 1125 +++++++++++++++++ tests/Gemfile_2-expected.json | 34 + tests/Gemfile_3-expected.json | 21 + tests/Gemfile_4-expected.json | 19 + tests/Gemfile_5 | 1 + tests/Gemfile_5-expected.json | 19 + tests/address_standardization.gemspec | 67 + ...ress_standardization.gemspec-expected.json | 119 ++ tests/arel.gemspec | 43 + tests/arel.gemspec-expected.json | 82 ++ tests/sample.gemspec-expected.json | 64 + tests/test_gemfileparser.py | 83 +- 13 files changed, 1648 insertions(+), 37 deletions(-) create mode 100644 tests/Gemfile-expected.json create mode 100644 tests/Gemfile_1-expected.json create mode 100644 tests/Gemfile_2-expected.json create mode 100644 tests/Gemfile_3-expected.json create mode 100644 tests/Gemfile_4-expected.json create mode 100644 tests/Gemfile_5 create mode 100644 tests/Gemfile_5-expected.json create mode 100644 tests/address_standardization.gemspec create mode 100644 tests/address_standardization.gemspec-expected.json create mode 100644 tests/arel.gemspec create mode 100644 tests/arel.gemspec-expected.json create mode 100644 tests/sample.gemspec-expected.json diff --git a/tests/Gemfile-expected.json b/tests/Gemfile-expected.json new file mode 100644 index 0000000..0a5ec1a --- /dev/null +++ b/tests/Gemfile-expected.json @@ -0,0 +1,8 @@ +{ + "development": [], + "runtime": [], + "dependency": [], + "test": [], + "production": [], + "metrics": [] +} \ No newline at end of file diff --git a/tests/Gemfile_1-expected.json b/tests/Gemfile_1-expected.json new file mode 100644 index 0000000..7e38ae8 --- /dev/null +++ b/tests/Gemfile_1-expected.json @@ -0,0 +1,1125 @@ +{ + "development": [], + "runtime": [ + { + "name": "rails", + "requirement": [ + "4.2.4" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "responders", + "requirement": [ + "2.1.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "unicorn", + "requirement": [ + "4.9.0" + ], + "autorequire": "true", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "diaspora_federation-rails", + "requirement": [ + "0.0.6" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "acts_as_api", + "requirement": [ + "0.4.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "json", + "requirement": [ + "1.8.3" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "json-schema", + "requirement": [ + "2.5.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "devise", + "requirement": [ + "3.5.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "devise_lastseenable", + "requirement": [ + "0.0.6" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "devise-token_authenticatable", + "requirement": [ + "~> 0.4.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "simple_captcha2", + "requirement": [ + "0.3.4" + ], + "autorequire": "simple", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "sidekiq", + "requirement": [ + "3.4.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "sinatra", + "requirement": [ + "1.4.6" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "sidetiq", + "requirement": [ + "0.6.3" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "uglifier", + "requirement": [ + "2.7.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "configurate", + "requirement": [ + "0.3.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rack-cors", + "requirement": [ + "0.4.0" + ], + "autorequire": "rack/cors", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "bootstrap-sass", + "requirement": [ + "2.3.2.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "compass-rails", + "requirement": [ + "2.0.4" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "sass-rails", + "requirement": [ + "5.0.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "autoprefixer-rails", + "requirement": [ + "5.2.1.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "mysql2", + "requirement": [ + "0.3.18 " + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "pg", + "requirement": [ + "0.18.2 " + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "activerecord-import", + "requirement": [ + "0.10.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "carrierwave", + "requirement": [ + "0.10.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "fog", + "requirement": [ + "1.32.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "mini_magick", + "requirement": [ + "4.2.7" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "remotipart", + "requirement": [ + "1.2.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "uuid", + "requirement": [ + "2.3.8" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "entypo-rails", + "requirement": [ + "2.2.3" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "backbone-on-rails", + "requirement": [ + "1.2.0.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "handlebars_assets", + "requirement": [ + "0.20.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "jquery-rails", + "requirement": [ + "4.0.4" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "jquery-ui-rails", + "requirement": [ + "5.0.5" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "js_image_paths", + "requirement": [ + "0.0.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "js-routes", + "requirement": [ + "1.0.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-jquery", + "requirement": [ + "1.11.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-markdown-it", + "requirement": [ + "4.4.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-markdown-it-hashtag", + "requirement": [ + "0.3.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-markdown-it-diaspora-mention", + "requirement": [ + "0.3.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-markdown-it-sanitizer", + "requirement": [ + "0.3.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-markdown-it--markdown-it-for-inline", + "requirement": [ + "0.1.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-markdown-it-sub", + "requirement": [ + "1.0.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-markdown-it-sup", + "requirement": [ + "1.0.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-highlightjs", + "requirement": [ + "8.6.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-jeresig--jquery.hotkeys", + "requirement": [ + "0.2.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-jquery-placeholder", + "requirement": [ + "2.1.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-jquery-textchange", + "requirement": [ + "0.2.3" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-perfect-scrollbar", + "requirement": [ + "0.6.4" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-jakobmattsson--jquery-elastic", + "requirement": [ + "1.6.11" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "facebox-rails", + "requirement": [ + "0.2.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "http_accept_language", + "requirement": [ + "2.0.5" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "i18n-inflector-rails", + "requirement": [ + "1.0.7" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-i18n", + "requirement": [ + "4.0.4" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "markerb", + "requirement": [ + "1.0.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "messagebus_ruby_api", + "requirement": [ + "1.0.3" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "nokogiri", + "requirement": [ + "1.6.6.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "redcarpet", + "requirement": [ + "3.3.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "twitter-text", + "requirement": [ + "1.12.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "roxml", + "requirement": [ + "3.1.6" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "ruby-oembed", + "requirement": [ + "0.8.14" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "open_graph_reader", + "requirement": [ + "0.6.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "omniauth", + "requirement": [ + "1.2.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "omniauth-facebook", + "requirement": [ + "2.0.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "omniauth-tumblr", + "requirement": [ + "1.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "omniauth-twitter", + "requirement": [ + "1.2.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "twitter", + "requirement": [ + "5.14.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "omniauth-wordpress", + "requirement": [ + "0.2.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "active_model_serializers", + "requirement": [ + "0.9.3" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "diaspora-vines", + "requirement": [ + "~> 0.2.0.develop" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-assets-diaspora_jsxc", + "requirement": [ + "~> 0.1.4.alpha", + "< 0.1.4.develop" + ], + "autorequire": "", + "source": "https://rails-assets.org", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "acts-as-taggable-on", + "requirement": [ + "3.5.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "addressable", + "requirement": [ + "2.3.8" + ], + "autorequire": "addressable/uri", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "faraday", + "requirement": [ + "0.9.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "faraday_middleware", + "requirement": [ + "0.10.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "faraday-cookie_jar", + "requirement": [ + "0.0.6" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "typhoeus", + "requirement": [ + "0.7.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "gon", + "requirement": [ + "6.0.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "haml", + "requirement": [ + "4.0.6" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "mobile-fu", + "requirement": [ + "1.3.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "will_paginate", + "requirement": [ + "3.0.7" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rails-timeago", + "requirement": [ + "2.11.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "logging-rails", + "requirement": [ + "0.5.0" + ], + "autorequire": "logging/rails", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "rubyzip", + "requirement": [ + "1.1.7" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + }, + { + "name": "minitest", + "requirement": [], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + } + ], + "dependency": [], + "test": [], + "production": [ + { + "name": "rails_admin", + "requirement": [ + "0.7.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "production" + }, + { + "name": "rack-google-analytics", + "requirement": [ + "1.2.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "production" + }, + { + "name": "rack-piwik", + "requirement": [ + "0.3.0" + ], + "autorequire": "rack/piwik", + "source": "", + "parent": [ + "" + ], + "group": "production" + }, + { + "name": "rack-protection", + "requirement": [ + "1.5.3" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "production" + }, + { + "name": "eye", + "requirement": [ + "0.7.pre" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "production" + }, + { + "name": "rack-rewrite", + "requirement": [ + "1.5.1" + ], + "autorequire": "false", + "source": "", + "parent": [ + "" + ], + "group": "production" + }, + { + "name": "rack-ssl", + "requirement": [ + "1.4.1" + ], + "autorequire": "rack/ssl", + "source": "", + "parent": [ + "" + ], + "group": "production" + }, + { + "name": "asset_sync", + "requirement": [ + "1.1.0" + ], + "autorequire": "false", + "source": "", + "parent": [ + "" + ], + "group": "production" + } + ], + "metrics": [] +} \ No newline at end of file diff --git a/tests/Gemfile_2-expected.json b/tests/Gemfile_2-expected.json new file mode 100644 index 0000000..a04b990 --- /dev/null +++ b/tests/Gemfile_2-expected.json @@ -0,0 +1,34 @@ +{ + "development": [ + { + "name": "responders", + "requirement": [ + "3.0.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + } + ], + "runtime": [ + { + "name": "rails", + "requirement": [ + "4.2.4" + ], + "autorequire": "", + "source": "http://www.example.com", + "parent": [ + "" + ], + "group": "runtime" + } + ], + "dependency": [], + "test": [], + "production": [], + "metrics": [] +} \ No newline at end of file diff --git a/tests/Gemfile_3-expected.json b/tests/Gemfile_3-expected.json new file mode 100644 index 0000000..a660af6 --- /dev/null +++ b/tests/Gemfile_3-expected.json @@ -0,0 +1,21 @@ +{ + "development": [ + { + "name": "rails", + "requirement": [ + "4.2.4" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + } + ], + "runtime": [], + "dependency": [], + "test": [], + "production": [], + "metrics": [] +} \ No newline at end of file diff --git a/tests/Gemfile_4-expected.json b/tests/Gemfile_4-expected.json new file mode 100644 index 0000000..5f7d89b --- /dev/null +++ b/tests/Gemfile_4-expected.json @@ -0,0 +1,19 @@ +{ + "development": [], + "runtime": [ + { + "name": "rails", + "requirement": [], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + } + ], + "dependency": [], + "test": [], + "production": [], + "metrics": [] +} \ No newline at end of file diff --git a/tests/Gemfile_5 b/tests/Gemfile_5 new file mode 100644 index 0000000..b5e7562 --- /dev/null +++ b/tests/Gemfile_5 @@ -0,0 +1 @@ +gem 'byebug', platforms: [:mri, :mingw, :x64_mingw], group: development diff --git a/tests/Gemfile_5-expected.json b/tests/Gemfile_5-expected.json new file mode 100644 index 0000000..bb8a39e --- /dev/null +++ b/tests/Gemfile_5-expected.json @@ -0,0 +1,19 @@ +{ + "development": [ + { + "name": "platforms", + "requirement": [], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + } + ], + "runtime": [], + "dependency": [], + "test": [], + "production": [], + "metrics": [] +} \ No newline at end of file diff --git a/tests/address_standardization.gemspec b/tests/address_standardization.gemspec new file mode 100644 index 0000000..77b9227 --- /dev/null +++ b/tests/address_standardization.gemspec @@ -0,0 +1,67 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{mysmallidea-address_standardization} + s.version = "0.4.1" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Elliot Winkler"] + s.date = %q{2010-02-01} + s.description = %q{A tiny Ruby library to quickly standardize a postal address} + s.email = %q{elliot.winkler@gmail.com} + s.extra_rdoc_files = [ + "README.md", + "TODO" + ] + s.files = [ + ".gitignore", + "README.md", + "Rakefile", + "TODO", + "address_standardization.gemspec", + "lib/address_standardization.rb", + "lib/address_standardization/abstract_service.rb", + "lib/address_standardization/address.rb", + "lib/address_standardization/class_level_inheritable_attributes.rb", + "lib/address_standardization/google_maps.rb", + "lib/address_standardization/melissa_data.rb", + "lib/address_standardization/ruby_ext.rb", + "lib/address_standardization/version.rb", + "test/google_maps_test.rb", + "test/melissa_data_test.rb", + "test/test_helper.rb" + ] + s.homepage = %q{http://github.com/mcmire/address_standardization} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.5} + s.summary = %q{A tiny Ruby library to quickly standardize a postal address} + s.test_files = [ + "test/google_maps_test.rb", + "test/melissa_data_test.rb", + "test/test_helper.rb" + ] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 0"]) + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + end + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + end +end + diff --git a/tests/address_standardization.gemspec-expected.json b/tests/address_standardization.gemspec-expected.json new file mode 100644 index 0000000..447015a --- /dev/null +++ b/tests/address_standardization.gemspec-expected.json @@ -0,0 +1,119 @@ +{ + "development": [ + { + "name": "mcmire-context", + "requirement": [ + ">= 0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + }, + { + "name": "mcmire-matchy", + "requirement": [ + ">= 0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + } + ], + "runtime": [ + { + "name": "mechanize", + "requirement": [ + ">= 0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + } + ], + "dependency": [ + { + "name": "mechanize", + "requirement": [ + ">= 0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + }, + { + "name": "mcmire-context", + "requirement": [ + ">= 0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + }, + { + "name": "mcmire-matchy", + "requirement": [ + ">= 0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + }, + { + "name": "mechanize", + "requirement": [ + ">= 0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + }, + { + "name": "mcmire-context", + "requirement": [ + ">= 0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + }, + { + "name": "mcmire-matchy", + "requirement": [ + ">= 0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + } + ], + "test": [], + "production": [], + "metrics": [] +} \ No newline at end of file diff --git a/tests/arel.gemspec b/tests/arel.gemspec new file mode 100644 index 0000000..7a07b0a --- /dev/null +++ b/tests/arel.gemspec @@ -0,0 +1,43 @@ +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{arel} + s.version = "2.0.7.beta.20110429111451" + + s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= + s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"] + s.date = %q{2011-04-29} + s.description = %q{Arel is a SQL AST manager for Ruby. It + +1. Simplifies the generation complex of SQL queries +2. Adapts to various RDBMS systems + +It is intended to be a framework framework; that is, you can build your own ORM +with it, focusing on innovative object and collection modeling as opposed to +database compatibility and query generation.} + s.email = ["aaron@tenderlovemaking.com", "bryan@brynary.com", "miloops@gmail.com", "nick@example.org"] + s.extra_rdoc_files = ["History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown"] + s.files = [".autotest", ".gemtest", "History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown", "Rakefile", "arel.gemspec", "lib/arel.rb", "lib/arel/alias_predication.rb", "lib/arel/attributes.rb", "lib/arel/attributes/attribute.rb", "lib/arel/compatibility/wheres.rb", "lib/arel/crud.rb", "lib/arel/delete_manager.rb", "lib/arel/deprecated.rb", "lib/arel/expression.rb", "lib/arel/expressions.rb", "lib/arel/factory_methods.rb", "lib/arel/insert_manager.rb", "lib/arel/math.rb", "lib/arel/nodes.rb", "lib/arel/nodes/and.rb", "lib/arel/nodes/binary.rb", "lib/arel/nodes/count.rb", "lib/arel/nodes/delete_statement.rb", "lib/arel/nodes/equality.rb", "lib/arel/nodes/function.rb", "lib/arel/nodes/in.rb", "lib/arel/nodes/infix_operation.rb", "lib/arel/nodes/inner_join.rb", "lib/arel/nodes/insert_statement.rb", "lib/arel/nodes/join_source.rb", "lib/arel/nodes/named_function.rb", "lib/arel/nodes/node.rb", "lib/arel/nodes/ordering.rb", "lib/arel/nodes/outer_join.rb", "lib/arel/nodes/select_core.rb", "lib/arel/nodes/select_statement.rb", "lib/arel/nodes/sql_literal.rb", "lib/arel/nodes/string_join.rb", "lib/arel/nodes/table_alias.rb", "lib/arel/nodes/terminal.rb", "lib/arel/nodes/unary.rb", "lib/arel/nodes/unqualified_column.rb", "lib/arel/nodes/update_statement.rb", "lib/arel/nodes/values.rb", "lib/arel/nodes/with.rb", "lib/arel/order_predications.rb", "lib/arel/predications.rb", "lib/arel/relation.rb", "lib/arel/select_manager.rb", "lib/arel/sql/engine.rb", "lib/arel/sql_literal.rb", "lib/arel/table.rb", "lib/arel/tree_manager.rb", "lib/arel/update_manager.rb", "lib/arel/visitors.rb", "lib/arel/visitors/depth_first.rb", "lib/arel/visitors/dot.rb", "lib/arel/visitors/ibm_db.rb", "lib/arel/visitors/join_sql.rb", "lib/arel/visitors/mssql.rb", "lib/arel/visitors/mysql.rb", "lib/arel/visitors/oracle.rb", "lib/arel/visitors/order_clauses.rb", "lib/arel/visitors/postgresql.rb", "lib/arel/visitors/sqlite.rb", "lib/arel/visitors/to_sql.rb", "lib/arel/visitors/visitor.rb", "lib/arel/visitors/where_sql.rb", "test/attributes/test_attribute.rb", "test/helper.rb", "test/nodes/test_as.rb", "test/nodes/test_bin.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_equality.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_named_function.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_select_core.rb", "test/nodes/test_select_statement.rb", "test/nodes/test_sql_literal.rb", "test/nodes/test_sum.rb", "test/nodes/test_update_statement.rb", "test/support/fake_record.rb", "test/test_activerecord_compat.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_factory_methods.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dot.rb", "test/visitors/test_ibm_db.rb", "test/visitors/test_join_sql.rb", "test/visitors/test_mssql.rb", "test/visitors/test_mysql.rb", "test/visitors/test_oracle.rb", "test/visitors/test_postgres.rb", "test/visitors/test_sqlite.rb", "test/visitors/test_to_sql.rb"] + s.homepage = %q{http://github.com/rails/arel} + s.rdoc_options = ["--main", "README.markdown"] + s.require_paths = ["lib"] + s.rubyforge_project = %q{arel} + s.rubygems_version = %q{1.6.1} + s.summary = %q{Arel is a SQL AST manager for Ruby} + s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_as.rb", "test/nodes/test_bin.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_equality.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_named_function.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_select_core.rb", "test/nodes/test_select_statement.rb", "test/nodes/test_sql_literal.rb", "test/nodes/test_sum.rb", "test/nodes/test_update_statement.rb", "test/test_activerecord_compat.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_factory_methods.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dot.rb", "test/visitors/test_ibm_db.rb", "test/visitors/test_join_sql.rb", "test/visitors/test_mssql.rb", "test/visitors/test_mysql.rb", "test/visitors/test_oracle.rb", "test/visitors/test_postgres.rb", "test/visitors/test_sqlite.rb", "test/visitors/test_to_sql.rb"] + + if s.respond_to? :specification_version then + s.specification_version = 3 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_development_dependency(%q, [">= 2.0.2"]) + s.add_development_dependency(%q, [">= 2.9.1"]) + else + s.add_dependency(%q, [">= 2.0.2"]) + s.add_dependency(%q, [">= 2.9.1"]) + end + else + s.add_dependency(%q, [">= 2.0.2"]) + s.add_dependency(%q, [">= 2.9.1"]) + end +end diff --git a/tests/arel.gemspec-expected.json b/tests/arel.gemspec-expected.json new file mode 100644 index 0000000..b6d72d3 --- /dev/null +++ b/tests/arel.gemspec-expected.json @@ -0,0 +1,82 @@ +{ + "development": [ + { + "name": "minitest", + "requirement": [ + ">= 2.0.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + }, + { + "name": "hoe", + "requirement": [ + ">= 2.9.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + } + ], + "runtime": [], + "dependency": [ + { + "name": "minitest", + "requirement": [ + ">= 2.0.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + }, + { + "name": "hoe", + "requirement": [ + ">= 2.9.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + }, + { + "name": "minitest", + "requirement": [ + ">= 2.0.2" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + }, + { + "name": "hoe", + "requirement": [ + ">= 2.9.1" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "dependency" + } + ], + "test": [], + "production": [], + "metrics": [] +} \ No newline at end of file diff --git a/tests/sample.gemspec-expected.json b/tests/sample.gemspec-expected.json new file mode 100644 index 0000000..b67ca7c --- /dev/null +++ b/tests/sample.gemspec-expected.json @@ -0,0 +1,64 @@ +{ + "development": [ + { + "name": "rake-compiler", + "requirement": [ + ">= 0.7.5" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + }, + { + "name": "rspec", + "requirement": [ + ">= 2.0.0" + ], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + }, + { + "name": "activesupport", + "requirement": [], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + }, + { + "name": "json", + "requirement": [], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "development" + } + ], + "runtime": [ + { + "name": "redmine", + "requirement": [], + "autorequire": "", + "source": "", + "parent": [ + "" + ], + "group": "runtime" + } + ], + "dependency": [], + "test": [], + "production": [], + "metrics": [] +} \ No newline at end of file diff --git a/tests/test_gemfileparser.py b/tests/test_gemfileparser.py index 20ab6cc..1f8f86b 100644 --- a/tests/test_gemfileparser.py +++ b/tests/test_gemfileparser.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2015 Balasankar C +# Copyright (c) Balasankar C # gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License] # (http://www.gnu.org/licenses/gpl) @@ -46,53 +46,62 @@ from gemfileparser import GemfileParser -def test_source_only_gemfile(): - gemparser = GemfileParser('tests/Gemfile') - expected = { - 'dependency': [], - 'development': [], - 'test': [], - 'metrics': [], - 'runtime': [], - 'production': [], +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() } - dependencies = gemparser.parse() + + 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 test_name(): - gemparser = GemfileParser('tests/Gemfile_2') - dependencies = gemparser.parse() - assert 'rails' == dependencies['runtime'][0].name +def test_source_only_gemfile(): + check_gemparser_results('tests/Gemfile') + + +def test_gemfile_1(): + check_gemparser_results('tests/Gemfile_1') + + +def test_gemfile_2(): + check_gemparser_results('tests/Gemfile_2') + + +def test_gemfile_3(): + check_gemparser_results('tests/Gemfile_3') -def test_requirement(): - gemparser = GemfileParser('tests/Gemfile_2') - dependencies = gemparser.parse() - assert ['4.2.4'] == dependencies['runtime'][0].requirement +def test_gemfile_4(): + check_gemparser_results('tests/Gemfile_4') -def test_group(): - gemparser = GemfileParser('tests/Gemfile_3') - dependencies = gemparser.parse() - assert ['4.2.4'] == dependencies['development'][0].requirement +def test_gemfile_platforms(): + check_gemparser_results('tests/Gemfile_5') -def test_group_block(): - gemparser = GemfileParser('tests/Gemfile_2') - dependencies = gemparser.parse() - assert ['3.0.0'] == dependencies['development'][0].requirement - assert ['4.2.4'] == dependencies['runtime'][0].requirement +def test_gemspec_1(): + check_gemparser_results('tests/sample.gemspec') -def test_source(): - gemparser = GemfileParser('tests/Gemfile_2') - dependencies = gemparser.parse() - assert 'http://www.example.com' == dependencies['runtime'][0].source +def test_gemspec_2(): + check_gemparser_results('tests/address_standardization.gemspec') -def test_gemspec(): - gemparser = GemfileParser('tests/Gemfile_2') - dependencies = gemparser.parse() - assert 'rails' in [x.name for x in dependencies['runtime']] - assert 'responders' in [x.name for x in dependencies['development']] +def test_gemspec_3(): + check_gemparser_results('tests/arel.gemspec') From 458703d7ee1f5b238506c413c800047a5234893c Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Thu, 20 Aug 2020 20:21:50 +0200 Subject: [PATCH 29/32] Add self name to authors Signed-off-by: Philippe Ombredanne --- AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 84dfeb1..b41e462 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,4 +5,5 @@ # Names are in alphabetical order, for the sanity of mind. - Balasankar C -- Rohit Potter \ No newline at end of file +- Rohit Potter +- Philippe Ombredanne From 88134c1fe3f1694501f26ffb1794769ce622882d Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Wed, 26 Aug 2020 09:09:32 +0200 Subject: [PATCH 30/32] Use SPDX license identifiers for brevity and clarity Signed-off-by: Philippe Ombredanne --- LICENSE | 44 +++++++++++++++++++++++++++++++ gemfileparser/__init__.py | 52 +++++-------------------------------- tests/test_gemfileparser.py | 44 ++----------------------------- 3 files changed, 53 insertions(+), 87 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2db0ece --- /dev/null +++ b/LICENSE @@ -0,0 +1,44 @@ +gemfileparser is dual-licensed under your choice of [GNU GPL version 3 (or above) License] +(http://www.gnu.org/licenses/gpl) +or the [MIT License](https://opensource.org/licenses/MIT). + +Personally, I prefer anyone using this to respect the GPL license and use that +itself for derivative works - thus making them also Free Software. But, your +call. + +Copyright (c) 2020 Gemfileparser authors (listed in AUTHORS file) + 2015-2018 Balasankar C + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. +. +This program 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 this program. If not, see . + + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/gemfileparser/__init__.py b/gemfileparser/__init__.py index a8bd1c6..62fa7c0 100644 --- a/gemfileparser/__init__.py +++ b/gemfileparser/__init__.py @@ -1,50 +1,11 @@ #!/usr/bin/env python # # Copyright (c) Balasankar C and others +# SPDX-License-Identifier: GPL-3.0-or-later OR MIT -# gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License] -# (http://www.gnu.org/licenses/gpl) -# and [MIT License](https://opensource.org/licenses/MIT). - -# Personally, I prefer anyone using this to respect the GPL license and use that -# itself for derivative works - thus making them also Free Software. But, your -# call. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# . -# This program 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 this program. If not, see . -# -# -# MIT License -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -'''Python library to parse Ruby's Gemfiles and gemspec files.''' +""" +Python library to parse Ruby Gemfiles, gemspec and Cocoapods podspec files. +""" import collections import csv @@ -55,8 +16,9 @@ class Dependency(object): - ''' A class to hold information about a dependency gem.''' - + """ + A class to hold information about a dependency gem. + """ def __init__(self): self.name = '' self.requirement = [] diff --git a/tests/test_gemfileparser.py b/tests/test_gemfileparser.py index 1f8f86b..7386e7f 100644 --- a/tests/test_gemfileparser.py +++ b/tests/test_gemfileparser.py @@ -1,47 +1,7 @@ #!/usr/bin/env python # -# Copyright (c) Balasankar C - -# gemfileparser is dual-licensed under [GNU GPL version 3 (or above) License] -# (http://www.gnu.org/licenses/gpl) -# and [MIT License](https://opensource.org/licenses/MIT). - -# Personally, I prefer anyone using this to respect the GPL license and use that -# itself for derivative works - thus making them also Free Software. But, your -# call. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# . -# This program 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 this program. If not, see . - -# MIT License -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# Copyright (c) Balasankar C and others +# SPDX-License-Identifier: GPL-3.0-or-later OR MIT from gemfileparser import GemfileParser From 6ee209ad87e153e3c73509a06d79eb281a15d545 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Wed, 26 Aug 2020 09:29:13 +0200 Subject: [PATCH 31/32] Streamline docstrings, remove redundant code Signed-off-by: Philippe Ombredanne --- gemfileparser/__init__.py | 143 ++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 76 deletions(-) diff --git a/gemfileparser/__init__.py b/gemfileparser/__init__.py index 62fa7c0..e0af8a8 100644 --- a/gemfileparser/__init__.py +++ b/gemfileparser/__init__.py @@ -7,6 +7,10 @@ Python library to parse Ruby Gemfiles, gemspec and Cocoapods podspec files. """ +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + import collections import csv import glob @@ -19,6 +23,7 @@ class Dependency(object): """ A class to hold information about a dependency gem. """ + def __init__(self): self.name = '' self.requirement = [] @@ -39,39 +44,28 @@ def to_dict(self): class GemfileParser(object): - '''Creates a GemfileParser object to perform operations. ''' - + """ + Create a GemfileParser object to perform operations. + """ gemfile_regexes = collections.OrderedDict() - gemfile_regexes['source'] = re.compile( - r"source:[ ]?(?P[a-zA-Z:\/\.-]+)") - gemfile_regexes['git'] = re.compile( - r"git:[ ]?(?P[a-zA-Z:\/\.-]+)") - gemfile_regexes['platform'] = re.compile( - r"platform:[ ]?(?P[a-zA-Z:\/\.-]+)") - gemfile_regexes['path'] = re.compile( - r"path:[ ]?(?P[a-zA-Z:\/\.-]+)") - gemfile_regexes['branch'] = re.compile( - r"branch:[ ]?(?P[a-zA-Z:\/\.-]+)") - gemfile_regexes['autorequire'] = re.compile( - r"require:[ ]?(?P[a-zA-Z:\/\.-]+)") - gemfile_regexes['group'] = re.compile( - r"group:[ ]?(?P[a-zA-Z:\/\.-]+)") - gemfile_regexes['name'] = re.compile( - r"(?P[a-zA-Z]+[\.0-9a-zA-Z _-]*)") - gemfile_regexes['requirement'] = re.compile( - r"(?P([>|<|=|~>|\d]+[ ]*[0-9\.\w]+[ ,]*)+)") - - group_block_regex = re.compile( - r"group[ ]?:[ ]?(?P.*?) do") - add_dvtdep_regex = re.compile( - r".*add_development_dependency(?P.*)") - add_rundep_regex = re.compile( - r".*add_runtime_dependency(?P.*)") - add_dep_regex = re.compile( - r".*dependency(?P.*)") + gemfile_regexes['source'] = re.compile(r"source:[ ]?(?P[a-zA-Z:\/\.-]+)") + gemfile_regexes['git'] = re.compile(r"git:[ ]?(?P[a-zA-Z:\/\.-]+)") + gemfile_regexes['platform'] = re.compile(r"platform:[ ]?(?P[a-zA-Z:\/\.-]+)") + gemfile_regexes['path'] = re.compile(r"path:[ ]?(?P[a-zA-Z:\/\.-]+)") + gemfile_regexes['branch'] = re.compile(r"branch:[ ]?(?P[a-zA-Z:\/\.-]+)") + gemfile_regexes['autorequire'] = re.compile(r"require:[ ]?(?P[a-zA-Z:\/\.-]+)") + gemfile_regexes['group'] = re.compile(r"group:[ ]?(?P[a-zA-Z:\/\.-]+)") + gemfile_regexes['name'] = re.compile(r"(?P[a-zA-Z]+[\.0-9a-zA-Z _-]*)") + gemfile_regexes['requirement'] = re.compile(r"(?P([>|<|=|~>|\d]+[ ]*[0-9\.\w]+[ ,]*)+)") + + group_block_regex = re.compile(r"group[ ]?:[ ]?(?P.*?) do") + + gemspec_add_dvtdep_regex = re.compile(r".*add_development_dependency(?P.*)") + gemspec_add_rundep_regex = re.compile(r".*add_runtime_dependency(?P.*)") + gemspec_add_dep_regex = re.compile(r".*dependency(?P.*)") def __init__(self, filepath, appname=''): - self.filepath = filepath # Required when calls to gemspec occurs + self.filepath = filepath self.current_group = 'runtime' @@ -87,14 +81,13 @@ def __init__(self, filepath, appname=''): with open(filepath) as gf: self.contents = gf.readlines() - if filepath.endswith(('.gemspec', '.podspec')): - self.gemspec = True - else: - self.gemspec = False + self.gemspec = filepath.endswith(('.gemspec', '.podspec')) @staticmethod def preprocess(line): - '''Removes the comment portion and excess spaces.''' + """ + Remove the comment portion and excess spaces. + """ if "#" in line: line = line[:line.index('#')] @@ -102,39 +95,34 @@ def preprocess(line): return line def parse_line(self, line): - '''Parses each line and creates dependency objects accordingly''' - - try: - - # StringIO requires a unicode object. - # But unicode() doesn't work with Python3 - # as it is already in unicode format. - # So, first try converting and if that fails, use original. + """ + Parse a line and return a Dependency object. + """ - line = unicode(line) - except NameError: - pass - linefile = io.StringIO(line) # csv requires a file object + # csv requires a file-like object + linefile = io.StringIO(line) for line in csv.reader(linefile, delimiter=','): column_list = [] for column in line: - stripped_column = column.replace("'", "") - stripped_column = stripped_column.replace('"', "") - stripped_column = stripped_column.replace("%q<", "") - stripped_column = stripped_column.replace("(", "") - stripped_column = stripped_column.replace(")", "") - stripped_column = stripped_column.replace("[", "") - stripped_column = stripped_column.replace("]", "") - stripped_column = stripped_column.strip() + stripped_column = ( + column.replace("'", "") + .replace('"', "") + .replace("%q<", "") + .replace("(", "") + .replace(")", "") + .replace("[", "") + .replace("]", "") + .strip() + ) column_list.append(stripped_column) + dep = Dependency() dep.group = self.current_group dep.parent.append(self.appname) for column in column_list: # Check for a match in each regex and assign to # corresponding variables - for criteria in GemfileParser.gemfile_regexes: - criteria_regex = GemfileParser.gemfile_regexes[criteria] + for criteria, criteria_regex in GemfileParser.gemfile_regexes.items(): match = criteria_regex.match(column) if match: if criteria == 'requirement': @@ -147,23 +135,24 @@ def parse_line(self, line): else: self.dependencies[dep.group] = [dep] - def parse_gemfile(self, path=''): - '''Parses a Gemfile and returns a dict of categorized dependencies.''' + def parse_gemfile(self): + """ + Parse a Gemfile and returns a mapping of categorized dependencies. + """ - if path == '': - contents = self.contents - else: - contents = open(path).readlines() - for line in contents: + for line in self.contents: line = self.preprocess(line) if line == '' or line.startswith('source'): continue + elif line.startswith('group'): match = self.group_block_regex.match(line) if match: self.current_group = match.group('groupblock') + elif line.startswith('end'): self.current_group = 'runtime' + elif line.startswith('gemspec'): # Gemfile contains a call to gemspec gemfiledir = os.path.dirname(self.filepath) @@ -173,29 +162,30 @@ def parse_gemfile(self, path=''): continue gemspec_file = gemspec_list[0] self.parse_gemspec(path=os.path.join(gemfiledir, gemspec_file)) + elif line.startswith('gem '): line = line[3:] self.parse_line(line) + return self.dependencies - def parse_gemspec(self, path=''): - '''Method to handle gemspec files.''' + def parse_gemspec(self, path=None): + """ + Parse a .gemspec or .podspec and return a mapping of categorized + dependencies. + """ - if path == '': - contents = self.contents - else: - contents = open(path).readlines() - for line in contents: + for line in self.contents: line = self.preprocess(line) - match = GemfileParser.add_dvtdep_regex.match(line) + match = self.gemspec_add_dvtdep_regex.match(line) if match: self.current_group = 'development' else: - match = GemfileParser.add_rundep_regex.match(line) + match = self.gemspec_add_rundep_regex.match(line) if match: self.current_group = 'runtime' else: - match = GemfileParser.add_dep_regex.match(line) + match = self.gemspec_add_dep_regex.match(line) if match: self.current_group = 'dependency' if match: @@ -204,8 +194,9 @@ def parse_gemspec(self, path=''): return self.dependencies def parse(self): - '''Calls necessary function based on whether file is a gemspec file - or not and forwards the dicts returned by them.''' + """ + Return a mapping of dependencies parsed from the Gemfile or gemspec. + """ if self.gemspec: return self.parse_gemspec() else: From 8a93afb253183686f09fc66a1ce953caacb70b6d Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Wed, 26 Aug 2020 09:31:07 +0200 Subject: [PATCH 32/32] Format for long lines Signed-off-by: Philippe Ombredanne --- README.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 2f24d1d..fef78a4 100644 --- a/README.rst +++ b/README.rst @@ -2,8 +2,8 @@ gemfileparser ============= -gemfileparser parses Ruby Gemfile using Python with supports Ruby Gemfiles and .gemspec files -as well as Cocoapod .podspec files. +gemfileparser parses Ruby Gemfile using Python with supports Ruby Gemfiles +and .gemspec files as well as Cocoapod .podspec files. Installation @@ -32,11 +32,11 @@ Usage The parse() method returns a dict object of the following format:: { - 'development': [list of dependency objects inside group 'development'], - 'runtime': [list of runtime dependency objects], - . - . - .} + 'development': [list of dependency objects inside group 'development'], + 'runtime': [list of runtime dependency objects], + . + . + } Each dependency object contains the following attributes: