Skip to content

Commit b42e5fc

Browse files
authored
feat: [OSM-2206] support for local whl files req specifier (#254)
1 parent 6f5f1b3 commit b42e5fc

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

pysrc/requirements/requirement.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import unicode_literals
22
import re
3+
import os
34
from pkg_resources import Requirement as Req
45

56
from .fragment import get_hash_info, parse_fragment, parse_extras_require
@@ -33,6 +34,8 @@
3334

3435
EDITABLE_REGEX = re.compile(r'^(-e|--editable=?)\s*')
3536

37+
WHL_FILE_REGEX = re.compile(r'^(?P<name>.*?)-(?P<version>.*?)-.*\.whl$')
38+
3639
class Requirement(object):
3740
"""
3841
Represents a single requirement
@@ -200,11 +203,16 @@ def parse_line(cls, line):
200203
req.subdirectory = fragment.get('subdirectory')
201204
req.path = groups['path']
202205
elif line.startswith('./'):
203-
setup_file = open(line + "/setup.py", "r")
204-
setup_content = setup_file.read()
205-
name_search = NAME_EQ_REGEX.search(setup_content)
206-
if name_search:
207-
req.name = name_search.group(1)
206+
if os.path.exists(line) and os.path.isfile(line) and line.lower().endswith(".whl"):
207+
match = re.match(WHL_FILE_REGEX, os.path.basename(line))
208+
if match:
209+
req.name = match.group("name")
210+
elif os.path.exists(line) and os.path.isdir(line):
211+
setup_file = open(line + "/setup.py", "r")
212+
setup_content = setup_file.read()
213+
name_search = NAME_EQ_REGEX.search(setup_content)
214+
if name_search:
215+
req.name = name_search.group(1)
208216
req.local_file = True
209217
else:
210218
# This is a requirement specifier.

test/system/inspect.spec.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ describe('inspect', () => {
129129
});
130130

131131
it.each([
132+
{
133+
workspace: 'pip-app-local-whl-file',
134+
uninstallPackages: [],
135+
pluginOpts: { allowMissing: true },
136+
expected: [
137+
{
138+
pkg: {
139+
name: 'pandas',
140+
},
141+
directDeps: ['my-package'],
142+
},
143+
],
144+
},
132145
{
133146
workspace: 'pip-app',
134147
uninstallPackages: [],
@@ -924,21 +937,6 @@ describe('inspect', () => {
924937
},
925938
],
926939
},
927-
{
928-
workspace: 'pipenv-app',
929-
targetFile: undefined,
930-
expected: [
931-
{
932-
pkg: {
933-
name: 'jinja2',
934-
version: '3.1.4',
935-
},
936-
labels: {
937-
pkgIdProvenance: '[email protected]',
938-
},
939-
},
940-
],
941-
},
942940
])(
943941
'should get correct pkgIdProvenance labels for packages in graph for workspace = $workspace',
944942
async ({ workspace, targetFile, expected }) => {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
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`.
2+
It was initially created at `/project/dist/my_package-0.1.0-py3-none-any.whl`, but moved to the `lib` directory.
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from setuptools import setup, find_packages
2+
setup(
3+
name='my_package',
4+
version='0.1.0',
5+
description='My awesome package',
6+
author='Your Name',
7+
author_email='[email protected]',
8+
packages=find_packages(),
9+
install_requires=['numpy', 'pandas'],
10+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests==2.31.0
2+
./lib/my_package-0.1.0-py3-none-any.whl

0 commit comments

Comments
 (0)