Skip to content

Commit e8a7063

Browse files
feat: optional dependencies support for pip, pipenv and setuptools. (#234)
* feat: add suport for optional dependencies * feat: added tests for optional dependencies * feat: addres PR comments
1 parent d391221 commit e8a7063

File tree

13 files changed

+1140
-85
lines changed

13 files changed

+1140
-85
lines changed

lib/dependencies/inspect-implementation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function getMetaData(
5555
// https://www.npmjs.com/package/pkg#detecting-assets-in-source-code
5656
function createAssets() {
5757
return [
58+
path.join(__dirname, '../../pysrc/constants.py'),
5859
path.join(__dirname, '../../pysrc/pip_resolve.py'),
5960
path.join(__dirname, '../../pysrc/distPackage.py'),
6061
path.join(__dirname, '../../pysrc/package.py'),

pysrc/constants.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
from collections import namedtuple
3+
4+
5+
DepsManagerItem = namedtuple(
6+
'DepsManagerItem', ['package_manager', 'file']
7+
)
8+
9+
10+
# TODO: When support for Python 2.7 - 3.3 will be removed, use Enums instead
11+
# of namedtuple, this is just a workaround to support Python2.7 syntax.
12+
class DepsManager:
13+
PIP = DepsManagerItem(package_manager="pip", file="requirements.txt")
14+
PIPENV = DepsManagerItem(package_manager="pipenv", file="Pipfile")
15+
SETUPTOOLS = DepsManagerItem(package_manager="setuptools", file="setup.py")
16+
17+
@classmethod
18+
def discover(cls, requirements_file_path):
19+
"""Establishes the dependency manager based on the used files"""
20+
if os.path.basename(requirements_file_path) == 'Pipfile':
21+
return cls.PIPENV
22+
if os.path.basename(requirements_file_path) == 'setup.py':
23+
return cls.SETUPTOOLS
24+
25+
return cls.PIP

0 commit comments

Comments
 (0)