Skip to content

Commit 9f265fb

Browse files
committed
Add support for comments in netrc file
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 9e765ec commit 9f265fb

11 files changed

Lines changed: 116 additions & 104 deletions

src/python_inspector/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#
1111

1212
import os
13+
from netrc import netrc
1314
from typing import Dict
1415
from typing import List
1516
from typing import NamedTuple
@@ -19,7 +20,6 @@
1920
from packvers.requirements import Requirement
2021
from resolvelib import BaseReporter
2122
from resolvelib import Resolver
22-
from tinynetrc import Netrc
2323

2424
from _packagedcode.models import DependentPackage
2525
from _packagedcode.models import PackageData
@@ -128,9 +128,9 @@ def resolve_dependencies(
128128
if netrc_file:
129129
if verbose:
130130
printer(f"Using netrc file {netrc_file}")
131-
netrc = Netrc(file=netrc_file)
131+
parsed_netrc = netrc(netrc_file)
132132
else:
133-
netrc = None
133+
parsed_netrc = None
134134

135135
# TODO: deduplicate me
136136
direct_dependencies = []
@@ -233,8 +233,8 @@ def resolve_dependencies(
233233
repos.append(existing)
234234
else:
235235
credentials = None
236-
if netrc:
237-
login, password = utils.get_netrc_auth(index_url, netrc)
236+
if parsed_netrc:
237+
login, password = utils.get_netrc_auth(index_url, parsed_netrc)
238238
credentials = (
239239
dict(login=login, password=password) if login and password else None
240240
)

src/python_inspector/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import json
1313
import os
14+
import tempfile
1415
from typing import Dict
1516
from typing import List
1617
from typing import NamedTuple
@@ -23,8 +24,11 @@ def get_netrc_auth(url, netrc):
2324
Return login and password if url is in netrc
2425
else return login and password as None
2526
"""
26-
if netrc.get(url):
27-
return (netrc[url].get("login"), netrc[url].get("password"))
27+
hosts = netrc.hosts
28+
if url in hosts:
29+
url_auth = hosts.get(url)
30+
# netrc returns a tuple of (login, account, password)
31+
return (url_auth[0], url_auth[2])
2832
return (None, None)
2933

3034

tests/data/azure-devops.req-310-expected.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -945,12 +945,12 @@
945945
"type": "pypi",
946946
"namespace": null,
947947
"name": "cryptography",
948-
"version": "39.0.0",
948+
"version": "39.0.1",
949949
"qualifiers": {},
950950
"subpath": null,
951951
"primary_language": "Python",
952952
"description": "cryptography is a package which provides cryptographic recipes and primitives to Python developers.\npyca/cryptography\n=================\n\n.. image:: https://img.shields.io/pypi/v/cryptography.svg\n :target: https://pypi.org/project/cryptography/\n :alt: Latest Version\n\n.. image:: https://readthedocs.org/projects/cryptography/badge/?version=latest\n :target: https://cryptography.io\n :alt: Latest Docs\n\n.. image:: https://github.com/pyca/cryptography/workflows/CI/badge.svg?branch=main\n :target: https://github.com/pyca/cryptography/actions?query=workflow%3ACI+branch%3Amain\n\n\n``cryptography`` is a package which provides cryptographic recipes and\nprimitives to Python developers. Our goal is for it to be your \"cryptographic\nstandard library\". It supports Python 3.6+ and PyPy3 7.2+.\n\n``cryptography`` includes both high level recipes and low level interfaces to\ncommon cryptographic algorithms such as symmetric ciphers, message digests, and\nkey derivation functions. For example, to encrypt something with\n``cryptography``'s high level symmetric encryption recipe:\n\n.. code-block:: pycon\n\n >>> from cryptography.fernet import Fernet\n >>> # Put this somewhere safe!\n >>> key = Fernet.generate_key()\n >>> f = Fernet(key)\n >>> token = f.encrypt(b\"A really secret message. Not for prying eyes.\")\n >>> token\n b'...'\n >>> f.decrypt(token)\n b'A really secret message. Not for prying eyes.'\n\nYou can find more information in the `documentation`_.\n\nYou can install ``cryptography`` with:\n\n.. code-block:: console\n\n $ pip install cryptography\n\nFor full details see `the installation documentation`_.\n\nDiscussion\n~~~~~~~~~~\n\nIf you run into bugs, you can file them in our `issue tracker`_.\n\nWe maintain a `cryptography-dev`_ mailing list for development discussion.\n\nYou can also join ``#pyca`` on ``irc.libera.chat`` to ask questions or get\ninvolved.\n\nSecurity\n~~~~~~~~\n\nNeed to report a security issue? Please consult our `security reporting`_\ndocumentation.\n\n\n.. _`documentation`: https://cryptography.io/\n.. _`the installation documentation`: https://cryptography.io/en/latest/installation/\n.. _`issue tracker`: https://github.com/pyca/cryptography/issues\n.. _`cryptography-dev`: https://mail.python.org/mailman/listinfo/cryptography-dev\n.. _`security reporting`: https://cryptography.io/en/latest/security/",
953-
"release_date": "2023-01-02T03:31:52",
953+
"release_date": "2023-02-07T19:40:44",
954954
"parties": [
955955
{
956956
"type": "person",
@@ -983,11 +983,11 @@
983983
"Topic :: Security :: Cryptography"
984984
],
985985
"homepage_url": "https://github.com/pyca/cryptography",
986-
"download_url": "https://files.pythonhosted.org/packages/7a/46/8b58d6b8244ff613ecb983b9428d1168dd0b014a34e13fb19737b9ba1fc1/cryptography-39.0.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
987-
"size": 4172511,
986+
"download_url": "https://files.pythonhosted.org/packages/bb/03/20b85e10571c919fd4862465c53ae40b6494fa7f82fd74131f401ce504f6/cryptography-39.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
987+
"size": 4183626,
988988
"sha1": null,
989-
"md5": "16571f6085127885160e7e3c5d51e360",
990-
"sha256": "1a6915075c6d3a5e1215eab5d99bcec0da26036ff2102a1038401d6ef5bef25b",
989+
"md5": "f9d2f40e36ef1db745d2127cb3af366f",
990+
"sha256": "e124352fd3db36a9d4a21c1aa27fd5d051e621845cb87fb851c08f4f75ce8be6",
991991
"sha512": null,
992992
"bug_tracking_url": null,
993993
"code_view_url": "https://github.com/pyca/cryptography/",
@@ -1008,20 +1008,20 @@
10081008
"dependencies": [],
10091009
"repository_homepage_url": null,
10101010
"repository_download_url": null,
1011-
"api_data_url": "https://pypi.org/pypi/cryptography/39.0.0/json",
1011+
"api_data_url": "https://pypi.org/pypi/cryptography/39.0.1/json",
10121012
"datasource_id": null,
1013-
"purl": "pkg:pypi/cryptography@39.0.0"
1013+
"purl": "pkg:pypi/cryptography@39.0.1"
10141014
},
10151015
{
10161016
"type": "pypi",
10171017
"namespace": null,
10181018
"name": "cryptography",
1019-
"version": "39.0.0",
1019+
"version": "39.0.1",
10201020
"qualifiers": {},
10211021
"subpath": null,
10221022
"primary_language": "Python",
10231023
"description": "cryptography is a package which provides cryptographic recipes and primitives to Python developers.\npyca/cryptography\n=================\n\n.. image:: https://img.shields.io/pypi/v/cryptography.svg\n :target: https://pypi.org/project/cryptography/\n :alt: Latest Version\n\n.. image:: https://readthedocs.org/projects/cryptography/badge/?version=latest\n :target: https://cryptography.io\n :alt: Latest Docs\n\n.. image:: https://github.com/pyca/cryptography/workflows/CI/badge.svg?branch=main\n :target: https://github.com/pyca/cryptography/actions?query=workflow%3ACI+branch%3Amain\n\n\n``cryptography`` is a package which provides cryptographic recipes and\nprimitives to Python developers. Our goal is for it to be your \"cryptographic\nstandard library\". It supports Python 3.6+ and PyPy3 7.2+.\n\n``cryptography`` includes both high level recipes and low level interfaces to\ncommon cryptographic algorithms such as symmetric ciphers, message digests, and\nkey derivation functions. For example, to encrypt something with\n``cryptography``'s high level symmetric encryption recipe:\n\n.. code-block:: pycon\n\n >>> from cryptography.fernet import Fernet\n >>> # Put this somewhere safe!\n >>> key = Fernet.generate_key()\n >>> f = Fernet(key)\n >>> token = f.encrypt(b\"A really secret message. Not for prying eyes.\")\n >>> token\n b'...'\n >>> f.decrypt(token)\n b'A really secret message. Not for prying eyes.'\n\nYou can find more information in the `documentation`_.\n\nYou can install ``cryptography`` with:\n\n.. code-block:: console\n\n $ pip install cryptography\n\nFor full details see `the installation documentation`_.\n\nDiscussion\n~~~~~~~~~~\n\nIf you run into bugs, you can file them in our `issue tracker`_.\n\nWe maintain a `cryptography-dev`_ mailing list for development discussion.\n\nYou can also join ``#pyca`` on ``irc.libera.chat`` to ask questions or get\ninvolved.\n\nSecurity\n~~~~~~~~\n\nNeed to report a security issue? Please consult our `security reporting`_\ndocumentation.\n\n\n.. _`documentation`: https://cryptography.io/\n.. _`the installation documentation`: https://cryptography.io/en/latest/installation/\n.. _`issue tracker`: https://github.com/pyca/cryptography/issues\n.. _`cryptography-dev`: https://mail.python.org/mailman/listinfo/cryptography-dev\n.. _`security reporting`: https://cryptography.io/en/latest/security/",
1024-
"release_date": "2023-01-02T03:36:08",
1024+
"release_date": "2023-02-07T19:41:00",
10251025
"parties": [
10261026
{
10271027
"type": "person",
@@ -1054,11 +1054,11 @@
10541054
"Topic :: Security :: Cryptography"
10551055
],
10561056
"homepage_url": "https://github.com/pyca/cryptography",
1057-
"download_url": "https://files.pythonhosted.org/packages/12/e3/c46c274cf466b24e5d44df5d5cd31a31ff23e57f074a2bb30931a8c9b01a/cryptography-39.0.0.tar.gz",
1058-
"size": 603406,
1057+
"download_url": "https://files.pythonhosted.org/packages/6a/f5/a729774d087e50fffd1438b3877a91e9281294f985bda0fd15bf99016c78/cryptography-39.0.1.tar.gz",
1058+
"size": 603634,
10591059
"sha1": null,
1060-
"md5": "12d0c6df42f600637a97904f84988ae2",
1061-
"sha256": "f964c7dcf7802d133e8dbd1565914fa0194f9d683d82411989889ecd701e8adf",
1060+
"md5": "f660591f3e629f2722e218d5f2ca35e5",
1061+
"sha256": "d1f6198ee6d9148405e49887803907fe8962a23e6c6f83ea7d98f1c0de375695",
10621062
"sha512": null,
10631063
"bug_tracking_url": null,
10641064
"code_view_url": "https://github.com/pyca/cryptography/",
@@ -1079,9 +1079,9 @@
10791079
"dependencies": [],
10801080
"repository_homepage_url": null,
10811081
"repository_download_url": null,
1082-
"api_data_url": "https://pypi.org/pypi/cryptography/39.0.0/json",
1082+
"api_data_url": "https://pypi.org/pypi/cryptography/39.0.1/json",
10831083
"datasource_id": null,
1084-
"purl": "pkg:pypi/cryptography@39.0.0"
1084+
"purl": "pkg:pypi/cryptography@39.0.1"
10851085
},
10861086
{
10871087
"type": "pypi",
@@ -2421,7 +2421,7 @@
24212421
"package": "pkg:pypi/azure-storage-blob@12.13.1",
24222422
"dependencies": [
24232423
"pkg:pypi/azure-core@1.26.3",
2424-
"pkg:pypi/cryptography@39.0.0",
2424+
"pkg:pypi/cryptography@39.0.1",
24252425
"pkg:pypi/msrest@0.6.21"
24262426
]
24272427
},
@@ -2444,7 +2444,7 @@
24442444
"dependencies": []
24452445
},
24462446
{
2447-
"package": "pkg:pypi/cryptography@39.0.0",
2447+
"package": "pkg:pypi/cryptography@39.0.1",
24482448
"dependencies": [
24492449
"pkg:pypi/cffi@1.15.1"
24502450
]

tests/data/azure-devops.req-38-expected.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -945,12 +945,12 @@
945945
"type": "pypi",
946946
"namespace": null,
947947
"name": "cryptography",
948-
"version": "39.0.0",
948+
"version": "39.0.1",
949949
"qualifiers": {},
950950
"subpath": null,
951951
"primary_language": "Python",
952952
"description": "cryptography is a package which provides cryptographic recipes and primitives to Python developers.\npyca/cryptography\n=================\n\n.. image:: https://img.shields.io/pypi/v/cryptography.svg\n :target: https://pypi.org/project/cryptography/\n :alt: Latest Version\n\n.. image:: https://readthedocs.org/projects/cryptography/badge/?version=latest\n :target: https://cryptography.io\n :alt: Latest Docs\n\n.. image:: https://github.com/pyca/cryptography/workflows/CI/badge.svg?branch=main\n :target: https://github.com/pyca/cryptography/actions?query=workflow%3ACI+branch%3Amain\n\n\n``cryptography`` is a package which provides cryptographic recipes and\nprimitives to Python developers. Our goal is for it to be your \"cryptographic\nstandard library\". It supports Python 3.6+ and PyPy3 7.2+.\n\n``cryptography`` includes both high level recipes and low level interfaces to\ncommon cryptographic algorithms such as symmetric ciphers, message digests, and\nkey derivation functions. For example, to encrypt something with\n``cryptography``'s high level symmetric encryption recipe:\n\n.. code-block:: pycon\n\n >>> from cryptography.fernet import Fernet\n >>> # Put this somewhere safe!\n >>> key = Fernet.generate_key()\n >>> f = Fernet(key)\n >>> token = f.encrypt(b\"A really secret message. Not for prying eyes.\")\n >>> token\n b'...'\n >>> f.decrypt(token)\n b'A really secret message. Not for prying eyes.'\n\nYou can find more information in the `documentation`_.\n\nYou can install ``cryptography`` with:\n\n.. code-block:: console\n\n $ pip install cryptography\n\nFor full details see `the installation documentation`_.\n\nDiscussion\n~~~~~~~~~~\n\nIf you run into bugs, you can file them in our `issue tracker`_.\n\nWe maintain a `cryptography-dev`_ mailing list for development discussion.\n\nYou can also join ``#pyca`` on ``irc.libera.chat`` to ask questions or get\ninvolved.\n\nSecurity\n~~~~~~~~\n\nNeed to report a security issue? Please consult our `security reporting`_\ndocumentation.\n\n\n.. _`documentation`: https://cryptography.io/\n.. _`the installation documentation`: https://cryptography.io/en/latest/installation/\n.. _`issue tracker`: https://github.com/pyca/cryptography/issues\n.. _`cryptography-dev`: https://mail.python.org/mailman/listinfo/cryptography-dev\n.. _`security reporting`: https://cryptography.io/en/latest/security/",
953-
"release_date": "2023-01-02T03:31:52",
953+
"release_date": "2023-02-07T19:40:44",
954954
"parties": [
955955
{
956956
"type": "person",
@@ -983,11 +983,11 @@
983983
"Topic :: Security :: Cryptography"
984984
],
985985
"homepage_url": "https://github.com/pyca/cryptography",
986-
"download_url": "https://files.pythonhosted.org/packages/7a/46/8b58d6b8244ff613ecb983b9428d1168dd0b014a34e13fb19737b9ba1fc1/cryptography-39.0.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
987-
"size": 4172511,
986+
"download_url": "https://files.pythonhosted.org/packages/bb/03/20b85e10571c919fd4862465c53ae40b6494fa7f82fd74131f401ce504f6/cryptography-39.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
987+
"size": 4183626,
988988
"sha1": null,
989-
"md5": "16571f6085127885160e7e3c5d51e360",
990-
"sha256": "1a6915075c6d3a5e1215eab5d99bcec0da26036ff2102a1038401d6ef5bef25b",
989+
"md5": "f9d2f40e36ef1db745d2127cb3af366f",
990+
"sha256": "e124352fd3db36a9d4a21c1aa27fd5d051e621845cb87fb851c08f4f75ce8be6",
991991
"sha512": null,
992992
"bug_tracking_url": null,
993993
"code_view_url": "https://github.com/pyca/cryptography/",
@@ -1008,20 +1008,20 @@
10081008
"dependencies": [],
10091009
"repository_homepage_url": null,
10101010
"repository_download_url": null,
1011-
"api_data_url": "https://pypi.org/pypi/cryptography/39.0.0/json",
1011+
"api_data_url": "https://pypi.org/pypi/cryptography/39.0.1/json",
10121012
"datasource_id": null,
1013-
"purl": "pkg:pypi/cryptography@39.0.0"
1013+
"purl": "pkg:pypi/cryptography@39.0.1"
10141014
},
10151015
{
10161016
"type": "pypi",
10171017
"namespace": null,
10181018
"name": "cryptography",
1019-
"version": "39.0.0",
1019+
"version": "39.0.1",
10201020
"qualifiers": {},
10211021
"subpath": null,
10221022
"primary_language": "Python",
10231023
"description": "cryptography is a package which provides cryptographic recipes and primitives to Python developers.\npyca/cryptography\n=================\n\n.. image:: https://img.shields.io/pypi/v/cryptography.svg\n :target: https://pypi.org/project/cryptography/\n :alt: Latest Version\n\n.. image:: https://readthedocs.org/projects/cryptography/badge/?version=latest\n :target: https://cryptography.io\n :alt: Latest Docs\n\n.. image:: https://github.com/pyca/cryptography/workflows/CI/badge.svg?branch=main\n :target: https://github.com/pyca/cryptography/actions?query=workflow%3ACI+branch%3Amain\n\n\n``cryptography`` is a package which provides cryptographic recipes and\nprimitives to Python developers. Our goal is for it to be your \"cryptographic\nstandard library\". It supports Python 3.6+ and PyPy3 7.2+.\n\n``cryptography`` includes both high level recipes and low level interfaces to\ncommon cryptographic algorithms such as symmetric ciphers, message digests, and\nkey derivation functions. For example, to encrypt something with\n``cryptography``'s high level symmetric encryption recipe:\n\n.. code-block:: pycon\n\n >>> from cryptography.fernet import Fernet\n >>> # Put this somewhere safe!\n >>> key = Fernet.generate_key()\n >>> f = Fernet(key)\n >>> token = f.encrypt(b\"A really secret message. Not for prying eyes.\")\n >>> token\n b'...'\n >>> f.decrypt(token)\n b'A really secret message. Not for prying eyes.'\n\nYou can find more information in the `documentation`_.\n\nYou can install ``cryptography`` with:\n\n.. code-block:: console\n\n $ pip install cryptography\n\nFor full details see `the installation documentation`_.\n\nDiscussion\n~~~~~~~~~~\n\nIf you run into bugs, you can file them in our `issue tracker`_.\n\nWe maintain a `cryptography-dev`_ mailing list for development discussion.\n\nYou can also join ``#pyca`` on ``irc.libera.chat`` to ask questions or get\ninvolved.\n\nSecurity\n~~~~~~~~\n\nNeed to report a security issue? Please consult our `security reporting`_\ndocumentation.\n\n\n.. _`documentation`: https://cryptography.io/\n.. _`the installation documentation`: https://cryptography.io/en/latest/installation/\n.. _`issue tracker`: https://github.com/pyca/cryptography/issues\n.. _`cryptography-dev`: https://mail.python.org/mailman/listinfo/cryptography-dev\n.. _`security reporting`: https://cryptography.io/en/latest/security/",
1024-
"release_date": "2023-01-02T03:36:08",
1024+
"release_date": "2023-02-07T19:41:00",
10251025
"parties": [
10261026
{
10271027
"type": "person",
@@ -1054,11 +1054,11 @@
10541054
"Topic :: Security :: Cryptography"
10551055
],
10561056
"homepage_url": "https://github.com/pyca/cryptography",
1057-
"download_url": "https://files.pythonhosted.org/packages/12/e3/c46c274cf466b24e5d44df5d5cd31a31ff23e57f074a2bb30931a8c9b01a/cryptography-39.0.0.tar.gz",
1058-
"size": 603406,
1057+
"download_url": "https://files.pythonhosted.org/packages/6a/f5/a729774d087e50fffd1438b3877a91e9281294f985bda0fd15bf99016c78/cryptography-39.0.1.tar.gz",
1058+
"size": 603634,
10591059
"sha1": null,
1060-
"md5": "12d0c6df42f600637a97904f84988ae2",
1061-
"sha256": "f964c7dcf7802d133e8dbd1565914fa0194f9d683d82411989889ecd701e8adf",
1060+
"md5": "f660591f3e629f2722e218d5f2ca35e5",
1061+
"sha256": "d1f6198ee6d9148405e49887803907fe8962a23e6c6f83ea7d98f1c0de375695",
10621062
"sha512": null,
10631063
"bug_tracking_url": null,
10641064
"code_view_url": "https://github.com/pyca/cryptography/",
@@ -1079,9 +1079,9 @@
10791079
"dependencies": [],
10801080
"repository_homepage_url": null,
10811081
"repository_download_url": null,
1082-
"api_data_url": "https://pypi.org/pypi/cryptography/39.0.0/json",
1082+
"api_data_url": "https://pypi.org/pypi/cryptography/39.0.1/json",
10831083
"datasource_id": null,
1084-
"purl": "pkg:pypi/cryptography@39.0.0"
1084+
"purl": "pkg:pypi/cryptography@39.0.1"
10851085
},
10861086
{
10871087
"type": "pypi",
@@ -2421,7 +2421,7 @@
24212421
"package": "pkg:pypi/azure-storage-blob@12.13.1",
24222422
"dependencies": [
24232423
"pkg:pypi/azure-core@1.26.3",
2424-
"pkg:pypi/cryptography@39.0.0",
2424+
"pkg:pypi/cryptography@39.0.1",
24252425
"pkg:pypi/msrest@0.6.21"
24262426
]
24272427
},
@@ -2444,7 +2444,7 @@
24442444
"dependencies": []
24452445
},
24462446
{
2447-
"package": "pkg:pypi/cryptography@39.0.0",
2447+
"package": "pkg:pypi/cryptography@39.0.1",
24482448
"dependencies": [
24492449
"pkg:pypi/cffi@1.15.1"
24502450
]

0 commit comments

Comments
 (0)