-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cocoapods support to package.py #119
Changes from 2 commits
3768d2e
801e740
3b01c28
536f5ed
1f5ff88
666e594
9b3a113
82f2a1e
1eb1bc3
5226943
550c654
e1d9073
3b38ed8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
# specific language governing permissions and limitations under the License. | ||
|
||
import dataclasses | ||
import logging | ||
import os | ||
import re | ||
import time | ||
from typing import List | ||
|
@@ -32,11 +34,19 @@ | |
from fetchcode.package_util import GitHubSource | ||
from fetchcode.package_util import MiniupnpPackagesGitHubSource | ||
from fetchcode.package_util import OpenSSLGitHubSource | ||
from fetchcode.package_util import construct_cocoapods_package | ||
from fetchcode.package_util import get_cocoapod_tags | ||
from fetchcode.package_util import get_cocoapods_org_url_status | ||
from fetchcode.package_util import get_pod_data_with_soup | ||
from fetchcode.packagedcode_models import Package | ||
from fetchcode.utils import get_hashed_path | ||
from fetchcode.utils import get_response | ||
|
||
router = Router() | ||
|
||
LOG_FILE_LOCATION = os.path.join(os.path.expanduser("~"), "purlcli.log") | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def info(url): | ||
""" | ||
|
@@ -362,6 +372,123 @@ def get_gnu_data_from_purl(purl): | |
) | ||
|
||
|
||
@router.route("pkg:cocoapods/.*") | ||
def get_cocoapods_data_from_purl(purl): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @johnmhoran after refactoring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @keshav-space -- I was wondering about that, given how the other existing, relatively short There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keshav-space Moving these related functions to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keshav-space I am having trouble importing and accessing in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @johnmhoran please don't share the same logger across different files. Define a new logger for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @keshav-space . I've defined the logger in each of |
||
""" | ||
Generate `Package` object from the `purl` string of cocoapods type | ||
""" | ||
logging.basicConfig( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure we want logging in the library, but I am sure we do not want logging to be enabled and configured here at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirming that my added logging has been removed. |
||
filename=LOG_FILE_LOCATION, | ||
level=logging.WARN, | ||
format="%(levelname)s - %(message)s", | ||
filemode="w", | ||
) | ||
|
||
purl = PackageURL.from_string(purl) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put this in try/except block, given input may not be a valid PURL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @TG1999 . I'm in the midst of refactoring but will add this to the updated code. One note: there are nearly a dozen other uses of that same syntax by other supported PURL types in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TG1999 On second thought, purldb-toolkit's
|
||
name = purl.name | ||
version = purl.version | ||
cocoapods_org_url = f"https://cocoapods.org/pods/{name}" | ||
repository_homepage_url = f"https://cocoapods.org/pods/{name}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why track two variables with the exact same value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted. |
||
|
||
purl_to_cocoapods_org_url_status = get_cocoapods_org_url_status(purl, name, cocoapods_org_url) | ||
cocoa_org_url_status = purl_to_cocoapods_org_url_status["return_message"] | ||
|
||
status_values = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have all these statuses in other package implementations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These have been removed along with all related logging, messaging etc. |
||
"cocoapods_org_redirects_to_github", | ||
"cocoapods_org_url_redirects", | ||
"failed_to_fetch_github_redirect", | ||
"github_redirect_error", | ||
"github_redirect_not_found", | ||
] | ||
|
||
cocoa_org_url_status_code = None | ||
if cocoa_org_url_status == "cocoapods_org_url_not_found": | ||
cocoa_org_url_status_code = 404 | ||
elif cocoa_org_url_status == "cocoapods_org_url_temporarily_unavailable": | ||
cocoa_org_url_status_code = 503 | ||
elif any(cocoa_org_url_status == status for status in status_values): | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cocoa_org_url_status_code = 302 | ||
|
||
if ( | ||
cocoa_org_url_status == "cocoapods_org_url_not_found" | ||
or cocoa_org_url_status == "cocoapods_org_url_redirects" | ||
or cocoa_org_url_status == "cocoapods_org_url_temporarily_unavailable" | ||
or cocoa_org_url_status == "failed_to_fetch_github_redirect" | ||
or cocoa_org_url_status == "github_redirect_error" | ||
or cocoa_org_url_status == "github_redirect_not_found" | ||
): | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
|
||
purl_to_pod_data_with_soup = {} | ||
if cocoa_org_url_status_code != 302 and cocoa_org_url_status_code != 503: | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
purl_to_pod_data_with_soup = get_pod_data_with_soup(purl, name, cocoapods_org_url) | ||
|
||
cocoapods_org_pod_name = None | ||
if purl_to_pod_data_with_soup.get('cocoapods_org_pod_name') is not None: | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cocoapods_org_pod_name = purl_to_pod_data_with_soup["cocoapods_org_pod_name"] | ||
elif purl_to_cocoapods_org_url_status.get('cocoapods_org_pod_name') is not None: | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cocoapods_org_pod_name = purl_to_cocoapods_org_url_status["cocoapods_org_pod_name"] | ||
|
||
cocoapods_org_version = None | ||
cocoapods_org_gh_repo_owner = None | ||
cocoapods_org_gh_repo_name = None | ||
|
||
if purl_to_pod_data_with_soup.get("cocoapods_org_version") is not None: | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cocoapods_org_version = purl_to_pod_data_with_soup["cocoapods_org_version"] | ||
elif purl_to_cocoapods_org_url_status.get("cocoapods_org_version") is not None: | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cocoapods_org_version = purl_to_cocoapods_org_url_status[ | ||
"cocoapods_org_version" | ||
] | ||
|
||
if purl_to_pod_data_with_soup.get("cocoapods_org_gh_repo_owner") is not None: | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cocoapods_org_gh_repo_owner = purl_to_pod_data_with_soup[ | ||
"cocoapods_org_gh_repo_owner" | ||
] | ||
elif ( | ||
purl_to_cocoapods_org_url_status.get("cocoapods_org_gh_repo_owner") is not None | ||
): | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cocoapods_org_gh_repo_owner = purl_to_cocoapods_org_url_status[ | ||
"cocoapods_org_gh_repo_owner" | ||
] | ||
|
||
if purl_to_pod_data_with_soup.get("cocoapods_org_gh_repo_name") is not None: | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cocoapods_org_gh_repo_name = purl_to_pod_data_with_soup[ | ||
"cocoapods_org_gh_repo_name" | ||
] | ||
elif purl_to_cocoapods_org_url_status.get("cocoapods_org_gh_repo_name") is not None: | ||
keshav-space marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cocoapods_org_gh_repo_name = purl_to_cocoapods_org_url_status[ | ||
"cocoapods_org_gh_repo_name" | ||
] | ||
|
||
api = "https://cdn.cocoapods.org" | ||
hashed_path = get_hashed_path(cocoapods_org_pod_name) | ||
hashed_path_underscore = hashed_path.replace("/", "_") | ||
file_prefix = "all_pods_versions_" | ||
spec = f"{api}/{file_prefix}{hashed_path_underscore}.txt" | ||
data_list = get_cocoapod_tags(spec, cocoapods_org_pod_name) | ||
if not version: | ||
version = cocoapods_org_version | ||
for tag in data_list: | ||
if purl.version and tag != purl.version: | ||
continue | ||
|
||
tag_pkg = construct_cocoapods_package( | ||
purl, | ||
name, | ||
hashed_path, | ||
repository_homepage_url, | ||
cocoapods_org_gh_repo_owner, | ||
cocoapods_org_gh_repo_name, | ||
tag, | ||
cocoapods_org_pod_name | ||
) | ||
|
||
yield tag_pkg | ||
|
||
if purl.version: | ||
break | ||
|
||
|
||
@dataclasses.dataclass | ||
class DirectoryListedSource: | ||
source_url: str = dataclasses.field( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please never pin the version here. Only express what is your minimal required version. The pin goes in the requirements file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad you caught that -- thanks and fixed.