diff --git a/pysrc/requirements/requirement.py b/pysrc/requirements/requirement.py index eba8c28..e4def7e 100644 --- a/pysrc/requirements/requirement.py +++ b/pysrc/requirements/requirement.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals import re +import os from pkg_resources import Requirement as Req from .fragment import get_hash_info, parse_fragment, parse_extras_require @@ -33,6 +34,8 @@ EDITABLE_REGEX = re.compile(r'^(-e|--editable=?)\s*') +WHL_FILE_REGEX = re.compile(r'^(?P.*?)-(?P.*?)-.*\.whl$') + class Requirement(object): """ Represents a single requirement @@ -200,11 +203,16 @@ def parse_line(cls, line): req.subdirectory = fragment.get('subdirectory') req.path = groups['path'] elif line.startswith('./'): - setup_file = open(line + "/setup.py", "r") - setup_content = setup_file.read() - name_search = NAME_EQ_REGEX.search(setup_content) - if name_search: - req.name = name_search.group(1) + if os.path.exists(line) and os.path.isfile(line) and line.lower().endswith(".whl"): + match = re.match(WHL_FILE_REGEX, os.path.basename(line)) + if match: + req.name = match.group("name") + elif os.path.exists(line) and os.path.isdir(line): + setup_file = open(line + "/setup.py", "r") + setup_content = setup_file.read() + name_search = NAME_EQ_REGEX.search(setup_content) + if name_search: + req.name = name_search.group(1) req.local_file = True else: # This is a requirement specifier. diff --git a/test/system/inspect.spec.ts b/test/system/inspect.spec.ts index f62a8fd..29d35b9 100644 --- a/test/system/inspect.spec.ts +++ b/test/system/inspect.spec.ts @@ -129,6 +129,19 @@ describe('inspect', () => { }); it.each([ + { + workspace: 'pip-app-local-whl-file', + uninstallPackages: [], + pluginOpts: { allowMissing: true }, + expected: [ + { + pkg: { + name: 'pandas', + }, + directDeps: ['my-package'], + }, + ], + }, { workspace: 'pip-app', uninstallPackages: [], @@ -924,21 +937,6 @@ describe('inspect', () => { }, ], }, - { - workspace: 'pipenv-app', - targetFile: undefined, - expected: [ - { - pkg: { - name: 'jinja2', - version: '3.1.4', - }, - labels: { - pkgIdProvenance: 'Jinja2@3.1.4', - }, - }, - ], - }, ])( 'should get correct pkgIdProvenance labels for packages in graph for workspace = $workspace', async ({ workspace, targetFile, expected }) => { diff --git a/test/workspaces/pip-app-local-whl-file/README.md b/test/workspaces/pip-app-local-whl-file/README.md new file mode 100644 index 0000000..bd396b2 --- /dev/null +++ b/test/workspaces/pip-app-local-whl-file/README.md @@ -0,0 +1,2 @@ +The Python wheel file `./lib/my_package-0.1.0-py3-none-any.whl` was created based off of the `setup.py` file in the `project` directory by running `python setup.py bdist_wheel`. +It was initially created at `/project/dist/my_package-0.1.0-py3-none-any.whl`, but moved to the `lib` directory. \ No newline at end of file diff --git a/test/workspaces/pip-app-local-whl-file/lib/my_package-0.1.0-py3-none-any.whl b/test/workspaces/pip-app-local-whl-file/lib/my_package-0.1.0-py3-none-any.whl new file mode 100644 index 0000000..fbec6de Binary files /dev/null and b/test/workspaces/pip-app-local-whl-file/lib/my_package-0.1.0-py3-none-any.whl differ diff --git a/test/workspaces/pip-app-local-whl-file/project/setup.py b/test/workspaces/pip-app-local-whl-file/project/setup.py new file mode 100644 index 0000000..a2130c1 --- /dev/null +++ b/test/workspaces/pip-app-local-whl-file/project/setup.py @@ -0,0 +1,10 @@ +from setuptools import setup, find_packages +setup( + name='my_package', + version='0.1.0', + description='My awesome package', + author='Your Name', + author_email='your_email@example.com', + packages=find_packages(), + install_requires=['numpy', 'pandas'], +) \ No newline at end of file diff --git a/test/workspaces/pip-app-local-whl-file/requirements.txt b/test/workspaces/pip-app-local-whl-file/requirements.txt new file mode 100644 index 0000000..9d5d255 --- /dev/null +++ b/test/workspaces/pip-app-local-whl-file/requirements.txt @@ -0,0 +1,2 @@ +requests==2.31.0 +./lib/my_package-0.1.0-py3-none-any.whl \ No newline at end of file