Skip to content

Commit

Permalink
Merge pull request #122 from nexB/ignore_comments_from_netrc
Browse files Browse the repository at this point in the history
Support comments in netrc file #107
  • Loading branch information
TG1999 authored Feb 23, 2023
2 parents 39588f1 + 9bdb540 commit ed46103
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 404 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ Changelog
=========


v0.9.5
-------------

- Update readme with test instructions.
- Fail gracefully at parsing setup.py with no deps.
- Support comments in netrc file #107.


v0.9.4
------

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ resolvelib==0.8.1
saneyaml==0.5.2
soupsieve==2.3.2.post1
text-unidecode==1.3
tinynetrc==1.3.1
toml==0.10.2
urllib3==1.26.11
zipp==3.8.1
1 change: 0 additions & 1 deletion requirements_builder.ABOUT
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ install_requires =
requests >= 2.18.0
resolvelib >= 0.8.1
saneyaml >= 0.5.2
tinynetrc >= 1.3.1
toml >= 0.10.0
mock >= 3.0.5

Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ install_requires =
requests >= 2.18.0
resolvelib >= 0.8.1
saneyaml >= 0.5.2
tinynetrc >= 1.3.1
toml >= 0.10.0
mock >= 3.0.5
packvers >= 21.5
Expand Down
10 changes: 5 additions & 5 deletions src/python_inspector/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#

import os
from netrc import netrc
from typing import Dict
from typing import List
from typing import NamedTuple
Expand All @@ -19,7 +20,6 @@
from packvers.requirements import Requirement
from resolvelib import BaseReporter
from resolvelib import Resolver
from tinynetrc import Netrc

from _packagedcode.models import DependentPackage
from _packagedcode.models import PackageData
Expand Down Expand Up @@ -128,9 +128,9 @@ def resolve_dependencies(
if netrc_file:
if verbose:
printer(f"Using netrc file {netrc_file}")
netrc = Netrc(file=netrc_file)
parsed_netrc = netrc(netrc_file)
else:
netrc = None
parsed_netrc = None

# TODO: deduplicate me
direct_dependencies = []
Expand Down Expand Up @@ -233,8 +233,8 @@ def resolve_dependencies(
repos.append(existing)
else:
credentials = None
if netrc:
login, password = utils.get_netrc_auth(index_url, netrc)
if parsed_netrc:
login, password = utils.get_netrc_auth(index_url, parsed_netrc)
credentials = (
dict(login=login, password=password) if login and password else None
)
Expand Down
8 changes: 6 additions & 2 deletions src/python_inspector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import json
import os
import tempfile
from typing import Dict
from typing import List
from typing import NamedTuple
Expand All @@ -23,8 +24,11 @@ def get_netrc_auth(url, netrc):
Return login and password if url is in netrc
else return login and password as None
"""
if netrc.get(url):
return (netrc[url].get("login"), netrc[url].get("password"))
hosts = netrc.hosts
if url in hosts:
url_auth = hosts.get(url)
# netrc returns a tuple of (login, account, password)
return (url_auth[0], url_auth[2])
return (None, None)


Expand Down
45 changes: 23 additions & 22 deletions tests/data/azure-devops.req-310-expected.json

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions tests/data/azure-devops.req-38-expected.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion tests/data/frozen-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ SecretStorage==3.3.2
six==1.16.0
soupsieve==2.3.2.post1
text-unidecode==1.3
tinynetrc==1.3.1
toml==0.10.2
tomli==1.2.3
tqdm==4.64.0
Expand Down
179 changes: 17 additions & 162 deletions tests/data/frozen-requirements.txt-expected.json

Large diffs are not rendered by default.

103 changes: 85 additions & 18 deletions tests/data/single-url-except-simple-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,73 @@
"datasource_id": null,
"purl": "pkg:pypi/[email protected]"
},
{
"type": "pypi",
"namespace": null,
"name": "flask",
"version": "2.2.3",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "A simple framework for building complex web applications.\nFlask\n=====\n\nFlask is a lightweight `WSGI`_ web application framework. It is designed\nto make getting started quick and easy, with the ability to scale up to\ncomplex applications. It began as a simple wrapper around `Werkzeug`_\nand `Jinja`_ and has become one of the most popular Python web\napplication frameworks.\n\nFlask offers suggestions, but doesn't enforce any dependencies or\nproject layout. It is up to the developer to choose the tools and\nlibraries they want to use. There are many extensions provided by the\ncommunity that make adding new functionality easy.\n\n.. _WSGI: https://wsgi.readthedocs.io/\n.. _Werkzeug: https://werkzeug.palletsprojects.com/\n.. _Jinja: https://jinja.palletsprojects.com/\n\n\nInstalling\n----------\n\nInstall and update using `pip`_:\n\n.. code-block:: text\n\n $ pip install -U Flask\n\n.. _pip: https://pip.pypa.io/en/stable/getting-started/\n\n\nA Simple Example\n----------------\n\n.. code-block:: python\n\n # save this as app.py\n from flask import Flask\n\n app = Flask(__name__)\n\n @app.route(\"/\")\n def hello():\n return \"Hello, World!\"\n\n.. code-block:: text\n\n $ flask run\n * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n\n\nContributing\n------------\n\nFor guidance on setting up a development environment and how to make a\ncontribution to Flask, see the `contributing guidelines`_.\n\n.. _contributing guidelines: https://github.com/pallets/flask/blob/main/CONTRIBUTING.rst\n\n\nDonate\n------\n\nThe Pallets organization develops and supports Flask and the libraries\nit uses. In order to grow the community of contributors and users, and\nallow the maintainers to devote more time to the projects, `please\ndonate today`_.\n\n.. _please donate today: https://palletsprojects.com/donate\n\n\nLinks\n-----\n\n- Documentation: https://flask.palletsprojects.com/\n- Changes: https://flask.palletsprojects.com/changes/\n- PyPI Releases: https://pypi.org/project/Flask/\n- Source Code: https://github.com/pallets/flask/\n- Issue Tracker: https://github.com/pallets/flask/issues/\n- Website: https://palletsprojects.com/p/flask/\n- Twitter: https://twitter.com/PalletsTeam\n- Chat: https://discord.gg/pallets",
"release_date": "2023-02-15T22:43:57",
"parties": [
{
"type": "person",
"role": "author",
"name": "Armin Ronacher",
"email": "[email protected]",
"url": null
},
{
"type": "person",
"role": "maintainer",
"name": "Pallets",
"email": "[email protected]",
"url": null
}
],
"keywords": [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Flask",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Internet :: WWW/HTTP :: WSGI",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
"Topic :: Software Development :: Libraries :: Application Frameworks"
],
"homepage_url": "https://palletsprojects.com/p/flask",
"download_url": "https://files.pythonhosted.org/packages/e8/5c/ff9047989bd995b1098d14b03013f160225db2282925b517bb4a967752ee/Flask-2.2.3.tar.gz",
"size": 697599,
"sha1": null,
"md5": "09a3dfdc4fc622ec49910cfd62f45eaa",
"sha256": "7eb373984bf1c770023fce9db164ed0c3353cd0b53f130f4693da0ca756a2e6d",
"sha512": null,
"bug_tracking_url": "https://github.com/pallets/flask/issues/",
"code_view_url": "https://github.com/pallets/flask/",
"vcs_url": null,
"copyright": null,
"license_expression": null,
"declared_license": {
"license": "BSD-3-Clause",
"classifiers": [
"License :: OSI Approved :: BSD License"
]
},
"notice_text": null,
"source_packages": [],
"file_references": [],
"extra_data": {},
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": "https://pypi.org/pypi/flask/2.2.3/json",
"datasource_id": null,
"purl": "pkg:pypi/[email protected]"
},
{
"type": "pypi",
"namespace": null,
Expand Down Expand Up @@ -827,12 +894,12 @@
"type": "pypi",
"namespace": null,
"name": "zipp",
"version": "3.13.0",
"version": "3.14.0",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "Backport of pathlib-compatible object wrapper for zip files\n.. image:: https://img.shields.io/pypi/v/zipp.svg\n :target: https://pypi.org/project/zipp\n\n.. image:: https://img.shields.io/pypi/pyversions/zipp.svg\n\n.. image:: https://github.com/jaraco/zipp/workflows/tests/badge.svg\n :target: https://github.com/jaraco/zipp/actions?query=workflow%3A%22tests%22\n :alt: tests\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/psf/black\n :alt: Code style: Black\n\n.. .. image:: https://readthedocs.org/projects/skeleton/badge/?version=latest\n.. :target: https://skeleton.readthedocs.io/en/latest/?badge=latest\n\n.. image:: https://img.shields.io/badge/skeleton-2023-informational\n :target: https://blog.jaraco.com/skeleton\n\n.. image:: https://tidelift.com/badges/package/pypi/zipp\n :target: https://tidelift.com/subscription/pkg/pypi-zipp?utm_source=pypi-zipp&utm_medium=readme\n\n\nA pathlib-compatible Zipfile object wrapper. Official backport of the standard library\n`Path object <https://docs.python.org/3.8/library/zipfile.html#path-objects>`_.\n\n\nCompatibility\n=============\n\nNew features are introduced in this third-party library and later merged\ninto CPython. The following table indicates which versions of this library\nwere contributed to different versions in the standard library:\n\n.. list-table::\n :header-rows: 1\n\n * - zipp\n - stdlib\n * - 3.9\n - 3.12\n * - 3.5\n - 3.11\n * - 3.2\n - 3.10\n * - 3.3 ??\n - 3.9\n * - 1.0\n - 3.8\n\n\nUsage\n=====\n\nUse ``zipp.Path`` in place of ``zipfile.Path`` on any Python.\n\nFor Enterprise\n==============\n\nAvailable as part of the Tidelift Subscription.\n\nThis project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.\n\n`Learn more <https://tidelift.com/subscription/pkg/pypi-zipp?utm_source=pypi-zipp&utm_medium=referral&utm_campaign=github>`_.\n\nSecurity Contact\n================\n\nTo report a security vulnerability, please use the\n`Tidelift security contact <https://tidelift.com/security>`_.\nTidelift will coordinate the fix and disclosure.",
"release_date": "2023-02-09T17:04:05",
"release_date": "2023-02-18T00:47:56",
"parties": [
{
"type": "person",
Expand All @@ -849,11 +916,11 @@
"Programming Language :: Python :: 3 :: Only"
],
"homepage_url": "https://github.com/jaraco/zipp",
"download_url": "https://files.pythonhosted.org/packages/95/7b/1608a7344743f54a8c072d64d2a279934fd204d6d015278b0a0ed4ce104b/zipp-3.13.0-py3-none-any.whl",
"size": 6718,
"download_url": "https://files.pythonhosted.org/packages/a8/7d/90189265f0a9bcdf79b1143b77b0ef6dca0a5f13783f1e1efa4d7d7eafca/zipp-3.14.0-py3-none-any.whl",
"size": 6706,
"sha1": null,
"md5": "bbe676c29bf9e6db5a128cf2cbcb3b0f",
"sha256": "e8b2a36ea17df80ffe9e2c4fda3f693c3dad6df1697d3cd3af232db680950b0b",
"md5": "d5441872afc6ebdd5ef223afd1bbfc28",
"sha256": "188834565033387710d046e3fe96acfc9b5e86cbca7f39ff69cf21a4128198b7",
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
Expand All @@ -872,20 +939,20 @@
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": "https://pypi.org/pypi/zipp/3.13.0/json",
"api_data_url": "https://pypi.org/pypi/zipp/3.14.0/json",
"datasource_id": null,
"purl": "pkg:pypi/zipp@3.13.0"
"purl": "pkg:pypi/zipp@3.14.0"
},
{
"type": "pypi",
"namespace": null,
"name": "zipp",
"version": "3.13.0",
"version": "3.14.0",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "Backport of pathlib-compatible object wrapper for zip files\n.. image:: https://img.shields.io/pypi/v/zipp.svg\n :target: https://pypi.org/project/zipp\n\n.. image:: https://img.shields.io/pypi/pyversions/zipp.svg\n\n.. image:: https://github.com/jaraco/zipp/workflows/tests/badge.svg\n :target: https://github.com/jaraco/zipp/actions?query=workflow%3A%22tests%22\n :alt: tests\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/psf/black\n :alt: Code style: Black\n\n.. .. image:: https://readthedocs.org/projects/skeleton/badge/?version=latest\n.. :target: https://skeleton.readthedocs.io/en/latest/?badge=latest\n\n.. image:: https://img.shields.io/badge/skeleton-2023-informational\n :target: https://blog.jaraco.com/skeleton\n\n.. image:: https://tidelift.com/badges/package/pypi/zipp\n :target: https://tidelift.com/subscription/pkg/pypi-zipp?utm_source=pypi-zipp&utm_medium=readme\n\n\nA pathlib-compatible Zipfile object wrapper. Official backport of the standard library\n`Path object <https://docs.python.org/3.8/library/zipfile.html#path-objects>`_.\n\n\nCompatibility\n=============\n\nNew features are introduced in this third-party library and later merged\ninto CPython. The following table indicates which versions of this library\nwere contributed to different versions in the standard library:\n\n.. list-table::\n :header-rows: 1\n\n * - zipp\n - stdlib\n * - 3.9\n - 3.12\n * - 3.5\n - 3.11\n * - 3.2\n - 3.10\n * - 3.3 ??\n - 3.9\n * - 1.0\n - 3.8\n\n\nUsage\n=====\n\nUse ``zipp.Path`` in place of ``zipfile.Path`` on any Python.\n\nFor Enterprise\n==============\n\nAvailable as part of the Tidelift Subscription.\n\nThis project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.\n\n`Learn more <https://tidelift.com/subscription/pkg/pypi-zipp?utm_source=pypi-zipp&utm_medium=referral&utm_campaign=github>`_.\n\nSecurity Contact\n================\n\nTo report a security vulnerability, please use the\n`Tidelift security contact <https://tidelift.com/security>`_.\nTidelift will coordinate the fix and disclosure.",
"release_date": "2023-02-09T17:04:06",
"release_date": "2023-02-18T00:47:57",
"parties": [
{
"type": "person",
Expand All @@ -902,11 +969,11 @@
"Programming Language :: Python :: 3 :: Only"
],
"homepage_url": "https://github.com/jaraco/zipp",
"download_url": "https://files.pythonhosted.org/packages/d1/2f/ba544a8a6ad5ad9dcec1b00f536bb9fb078f5f50d1a1408876de18a9151b/zipp-3.13.0.tar.gz",
"size": 18725,
"download_url": "https://files.pythonhosted.org/packages/ab/47/b47d02b741e0aa6f998fc80457d3dfc05cb7732ef480597c2971cbc79260/zipp-3.14.0.tar.gz",
"size": 18405,
"sha1": null,
"md5": "ee68b317a1393b11c2d4037a30d18bed",
"sha256": "23f70e964bc11a34cef175bc90ba2914e1e4545ea1e3e2f67c079671883f9cb6",
"md5": "4562e20704fda17222f87d6618a4f604",
"sha256": "9e5421e176ef5ab4c0ad896624e87a7b2f07aca746c9b2aa305952800cb8eecb",
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
Expand All @@ -925,9 +992,9 @@
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": "https://pypi.org/pypi/zipp/3.13.0/json",
"api_data_url": "https://pypi.org/pypi/zipp/3.14.0/json",
"datasource_id": null,
"purl": "pkg:pypi/zipp@3.13.0"
"purl": "pkg:pypi/zipp@3.14.0"
}
],
"resolved_dependencies_graph": [
Expand All @@ -948,7 +1015,7 @@
{
"package": "pkg:pypi/[email protected]",
"dependencies": [
"pkg:pypi/zipp@3.13.0"
"pkg:pypi/zipp@3.14.0"
]
},
{
Expand All @@ -972,7 +1039,7 @@
]
},
{
"package": "pkg:pypi/zipp@3.13.0",
"package": "pkg:pypi/zipp@3.14.0",
"dependencies": []
}
]
Expand Down
Loading

0 comments on commit ed46103

Please sign in to comment.