Skip to content

Packagedcode to handle .podspec file - #2067

Closed
rpotter12 wants to merge 2 commits into
aboutcode-org:developfrom
rpotter12:podspec-parser
Closed

rpotter12 wants to merge 2 commits into
aboutcode-org:developfrom
rpotter12:podspec-parser

Conversation

@rpotter12

@rpotter12 rpotter12 commented Jun 13, 2020

Copy link
Copy Markdown
Contributor

Fixes #2036

Implementation to handle .podspec files.

  1. Created cocoapods.py which handle Cocoapods Package.
  2. Created spec.py which parse .podspec and .gemspec files and return dictionary with data.

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
    Run tests locally to check for errors.
  • Commits are in uniquely-named feature branch and has no merge conflicts 📁

@rpotter12
rpotter12 force-pushed the podspec-parser branch 2 times, most recently from c41b9f0 to 6e884e7 Compare June 13, 2020 23:47
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
@rpotter12

Copy link
Copy Markdown
Contributor Author

@MaJuRG This PR is not completed yet.

@rpotter12
rpotter12 force-pushed the podspec-parser branch 4 times, most recently from ac689e2 to 4db59fe Compare June 22, 2020 03:08

@steven-esser steven-esser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the gemfileparser library work on podspec files?

@rpotter12

rpotter12 commented Jun 23, 2020

Copy link
Copy Markdown
Contributor Author

Does the gemfileparser library work on podspec files?

@MaJuRG No that library does not work with podspec files. podspec files are very much same with the gemspec file but not exactly same. So I have edited the code of gemspec file here to get all the data of podspec file and the approach is totally different from @balasankarc of https://gitlab.com/balasankarc/gemfileparser library.

@rpotter12
rpotter12 requested a review from steven-esser June 23, 2020 00:08
@steven-esser

Copy link
Copy Markdown
Contributor

What exactly is different about them, from a technical side? would the parser work if you changed the filename?

Just trying to understand more to give proper advice :)

@rpotter12

Copy link
Copy Markdown
Contributor Author

What exactly is different about them, from a technical side? would the parser work if you changed the filename?

Just trying to understand more to give proper advice :)

@MaJuRG
Like in dependency is written in the format s.dependency "<dep_name>" "<dep_version" but in gemspec file it is written in the format s.add_development_dependency "<dep_name>" "<dep_version" or s.add_development_dependency(%q<minitest>, [">= 2.0.2"])
and
in gemspec authors and email are written in different line like s.authors = ["Aaron Patterson"], s.email = ["aaron@tenderlovemaking.com"] and in podspec file author and email are same line s.author = {"Aaron Patterson" => "aaron@tenderlovemaking.com"}

@rpotter12
rpotter12 force-pushed the podspec-parser branch 2 times, most recently from 96cfb83 to ae40e74 Compare June 24, 2020 20:01
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
@rpotter12

Copy link
Copy Markdown
Contributor Author

@MaJuRG @pombredanne @JonoYang I have made all the changes. Please review this again and merge this if everything looks good :)

@rpotter12
rpotter12 requested a review from steven-esser June 25, 2020 03:29

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the progress!
I have a more extra comments provided inline for your consideration

Comment thread src/packagedcode/podspec.py Outdated
return column_list


def parse_podspec(location):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not just a variation on the .gemspec?

@rpotter12 rpotter12 Jun 25, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, .gemspec and .podspec files are very similar to each other but not exactly same so I have made changes according to it :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have a shared utility module and not duplicate things then.

Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
Comment thread tests/packagedcode/data/podspec/LoadingShimmer/LoadingShimmer.podspec Outdated
Comment thread tests/packagedcode/data/plugin/podspec-package-expected.json Outdated
Comment thread tests/packagedcode/data/podspec/SwiftLib/SwiftLib.podspec Outdated
Comment thread tests/packagedcode/data/podspec/SwiftLib/SwiftLib.podspec Outdated
# the lib prefix of their name.
#

# spec.framework = "SomeFramework"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sure, but do we want to track these as deps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frameworks are a list of system frameworks that the user’s target needs to link against. I don't think this comes under dependencies. What do you say??

@rpotter12 rpotter12 closed this Jun 26, 2020
@rpotter12 rpotter12 reopened this Jun 26, 2020
@rpotter12
rpotter12 requested a review from pombredanne June 26, 2020 21:51
@rpotter12

Copy link
Copy Markdown
Contributor Author

@MaJuRG @pombredanne @JonoYang I have done all the necessary changes. Please review this again :)

@steven-esser steven-esser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The url parsing is not correct at this time. See comments.

Comment thread src/packagedcode/podspec.py Outdated
Comment thread tests/packagedcode/data/plugin/podspec-package-expected.json Outdated
Comment thread tests/packagedcode/data/plugin/podspec-package-expected.json Outdated
Comment thread tests/packagedcode/data/podspec/BadgeHub.podspec.expected.json Outdated
Comment thread tests/packagedcode/data/podspec/BadgeHub.podspec.expected.json Outdated
@rpotter12
rpotter12 requested a review from steven-esser June 30, 2020 03:19

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the progress and updates. 👍
I am picky so please see my comments inline!

Comment thread src/packagedcode/podspec.py Outdated


"""
Handle Podspec Package Manager

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about instead:

"""
Handle cocoapods packages manifests for macOS and iOS
including .podspec, Podfile and Podfile.lock files.
See https://cocoapods.org
"""

Also this may mean you want to rename the file from podspec.py to cocoapods.py which is a bit more generic?

Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated
Comment thread src/packagedcode/podspec.py Outdated

def parse_line(line):
"""
Parses each line and creates dependency objects accordingly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does a "line" arg looks like here?
Also please use the imperative style for docstring, e.g. something along the lines of:

Return a Dependency by parsing a line` string`

... but then, this is misleading: this function does not return a dependency?

Also add an example of what a "line" looks like.

Comment thread src/packagedcode/podspec.py Outdated
stripped_column = stripped_column.replace('[', "")
stripped_column = stripped_column.strip()
column_list.append(stripped_column)
return column_list

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me like you are parsing/cleaning up something that may be Ruby code here. This is also something that I saw in the rubygems code. You should have shared utility functions to handle this for both cocoapods an rubygems and not duplicate the code.

Comment thread tests/packagedcode/test_plugin.py Outdated
check_json_scan(expected_file, result_file, regen=False)

def test_package_command_scan_podspec(self):
test_dir = self.get_test_loc('podspec/package')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid reusing the same test files in a different test as this creates unnecessary coupling between tests that will bite us in the future.

Here you want to have a dedicated directory for this test f=data files and its expected file.

@@ -0,0 +1,140 @@
#

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this SwiftLib.podspec the example from their doc? It feels a little contrived. Can you find a better set of data files?

"code_view_url": null,
"vcs_url": "https://github.com/nanopb/nanopb.git",
"copyright": null,
"license_expression": "unknown",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely need to override the license detection in order to detect correctly these declared_license
Also is there a way to collect ALL the license values of ALL the podspecs? Ask around for help for this or check in https://github.com/CocoaPods/Specs ... this will be useful to properly create mapping of they license conventions to our keys (in addition to applying proper detection to their license field structure)
That should be in its own ticket though, so create one

],
"purl": "pkg:pods/nanopb@1.30905.0",
"repository_homepage_url": "https://cocoapods.org/pods/nanopb",
"repository_download_url": "https://github.com/nanopb/nanopb/archive/1.30905.0.zip",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be also the download URL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pods source code can be download by this url. :)

"purl": "pkg:pods/nanopb@1.30905.0",
"repository_homepage_url": "https://cocoapods.org/pods/nanopb",
"repository_download_url": "https://github.com/nanopb/nanopb/archive/1.30905.0.zip",
"api_data_url": "https://github.com/nanopb/nanopb"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this instead something from from https://github.com/CocoaPods/Specs ? you should check in the pod Ruby code to understand how things work.

@rpotter12
rpotter12 force-pushed the podspec-parser branch 3 times, most recently from cddcff3 to 66cc58f Compare July 3, 2020 01:51
@rpotter12
rpotter12 requested a review from pombredanne July 3, 2020 01:51
rpotter12 added 2 commits July 3, 2020 20:43
Signed-off-by: rpotter12 <rohitpotter12@gmail.com>
Signed-off-by: rpotter12 <rohitpotter12@gmail.com>

@steven-esser steven-esser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small nitpicks.


def is_podspec(location):
"""
Checks is the file is a podspec file or not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be: Checks if the file is actually a podspec file (nitpick)


def build_package(podspec_data):
"""
Return a Pacakge object from a package data mapping or None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pacakge should be Package

@rpotter12

Copy link
Copy Markdown
Contributor Author

#2075 is the merged which is the extended version of this PR.

@rpotter12 rpotter12 closed this Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse Podspec Files

3 participants