Skip to content

Commit

Permalink
Merge branch 'master' into fix/requirements-line-with-more-than-one-s…
Browse files Browse the repository at this point in the history
…pace
  • Loading branch information
admons committed Mar 24, 2022
2 parents 9594b20 + 5871df7 commit 6c8fa99
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
2 changes: 2 additions & 0 deletions lib/dependencies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface PythonInspectOptions {
allowMissing?: boolean; // Allow skipping packages that are not found in the environment.
args?: string[];
projectName?: string; // Allow providing a project name for the root node and package
allowEmpty?: boolean; // Allow manifest without dependencies (mostly for SCM)
}

type Options = api.SingleSubprojectInspectOptions & PythonInspectOptions;
Expand Down Expand Up @@ -55,6 +56,7 @@ export async function getDependencies(
targetFile,
options.allowMissing || false,
includeDevDeps,
options.allowEmpty,
options.args,
options.projectName
),
Expand Down
6 changes: 6 additions & 0 deletions lib/dependencies/inspect-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export async function inspectInstalledDeps(
targetFile: string,
allowMissing: boolean,
includeDevDeps: boolean,
allowEmpty: boolean,
args?: string[],
projectName?: string
): Promise<DepGraph> {
Expand All @@ -136,6 +137,7 @@ export async function inspectInstalledDeps(
...buildArgs(
targetFile,
allowMissing,
allowEmpty,
tempDirObj.name,
includeDevDeps,
args
Expand Down Expand Up @@ -196,6 +198,7 @@ export function getPythonEnv(targetFile: string) {
export function buildArgs(
targetFile: string,
allowMissing: boolean,
allowEmpty: boolean,
tempDirPath: string,
includeDevDeps: boolean,
extraArgs?: string[]
Expand All @@ -208,6 +211,9 @@ export function buildArgs(
if (allowMissing) {
args.push('--allow-missing');
}
if (allowEmpty) {
args.push('--allow-empty');
}
if (includeDevDeps) {
args.push('--dev-deps');
}
Expand Down
9 changes: 7 additions & 2 deletions pysrc/pip_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def canonicalize_package_name(name):
def create_dependencies_tree_by_req_file_path(requirements_file_path,
allow_missing=False,
dev_deps=False,
only_provenance=False):
only_provenance=False,
allow_empty=False):
# get all installed packages
pkgs = list(pkg_resources.working_set)

Expand All @@ -265,7 +266,7 @@ def create_dependencies_tree_by_req_file_path(requirements_file_path,

# create a list of dependencies from the dependencies file
required = get_requirements_list(requirements_file_path, dev_deps=dev_deps)
if not required:
if not required and not allow_empty:
msg = 'No dependencies detected in manifest.'
sys.exit(msg)
else:
Expand Down Expand Up @@ -316,13 +317,17 @@ def main():
parser.add_argument("--only-provenance",
action="store_true",
help="only return top level deps with provenance information")
parser.add_argument("--allow-empty",
action="store_true",
help="return empty dep tree instead of throwing")
args = parser.parse_args()

create_dependencies_tree_by_req_file_path(
args.requirements,
allow_missing=args.allow_missing,
dev_deps=args.dev_deps,
only_provenance=args.only_provenance,
allow_empty=args.allow_empty,
)

if __name__ == '__main__':
Expand Down
48 changes: 32 additions & 16 deletions test/unit/build-args.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { buildArgs } from '../../lib/dependencies/inspect-implementation';

describe('build args', () => {
it('should return expected args', () => {
const result = buildArgs('requirements.txt', false, '../pysrc', false, [
'-argOne',
'-argTwo',
]);
const result = buildArgs(
'requirements.txt',
false,
false,
'../pysrc',
false,
['-argOne', '-argTwo']
);
expect(result).toEqual([
`..${path.sep}pysrc${path.sep}pip_resolve.py`,
'requirements.txt',
Expand All @@ -16,10 +20,14 @@ describe('build args', () => {
});

it('should return expected args when allowMissing is true', () => {
const result = buildArgs('requirements.txt', true, '../pysrc', false, [
'-argOne',
'-argTwo',
]);
const result = buildArgs(
'requirements.txt',
true,
false,
'../pysrc',
false,
['-argOne', '-argTwo']
);
expect(result).toEqual([
`..${path.sep}pysrc${path.sep}pip_resolve.py`,
'requirements.txt',
Expand All @@ -30,10 +38,14 @@ describe('build args', () => {
});

it('should return expected args when includeDevDeps is true', () => {
const result = buildArgs('requirements.txt', false, '../pysrc', true, [
'-argOne',
'-argTwo',
]);
const result = buildArgs(
'requirements.txt',
false,
false,
'../pysrc',
true,
['-argOne', '-argTwo']
);
expect(result).toEqual([
`..${path.sep}pysrc${path.sep}pip_resolve.py`,
'requirements.txt',
Expand All @@ -44,10 +56,14 @@ describe('build args', () => {
});

it('should return expected args when allowMissing and includeDevDeps are true', () => {
const result = buildArgs('requirements.txt', true, '../pysrc', true, [
'-argOne',
'-argTwo',
]);
const result = buildArgs(
'requirements.txt',
true,
false,
'../pysrc',
true,
['-argOne', '-argTwo']
);
expect(result).toEqual([
`..${path.sep}pysrc${path.sep}pip_resolve.py`,
'requirements.txt',
Expand Down

0 comments on commit 6c8fa99

Please sign in to comment.