Skip to content

Commit

Permalink
feat: [OSM-2206] support for local whl files req specifier (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
gemaxim authored Dec 23, 2024
1 parent 6f5f1b3 commit b42e5fc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 20 deletions.
18 changes: 13 additions & 5 deletions pysrc/requirements/requirement.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -33,6 +34,8 @@

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

WHL_FILE_REGEX = re.compile(r'^(?P<name>.*?)-(?P<version>.*?)-.*\.whl$')

class Requirement(object):
"""
Represents a single requirement
Expand Down Expand Up @@ -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.
Expand Down
28 changes: 13 additions & 15 deletions test/system/inspect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -924,21 +937,6 @@ describe('inspect', () => {
},
],
},
{
workspace: 'pipenv-app',
targetFile: undefined,
expected: [
{
pkg: {
name: 'jinja2',
version: '3.1.4',
},
labels: {
pkgIdProvenance: '[email protected]',
},
},
],
},
])(
'should get correct pkgIdProvenance labels for packages in graph for workspace = $workspace',
async ({ workspace, targetFile, expected }) => {
Expand Down
2 changes: 2 additions & 0 deletions test/workspaces/pip-app-local-whl-file/README.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file not shown.
10 changes: 10 additions & 0 deletions test/workspaces/pip-app-local-whl-file/project/setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
packages=find_packages(),
install_requires=['numpy', 'pandas'],
)
2 changes: 2 additions & 0 deletions test/workspaces/pip-app-local-whl-file/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests==2.31.0
./lib/my_package-0.1.0-py3-none-any.whl

0 comments on commit b42e5fc

Please sign in to comment.