implement proposal for fetching paths and retaining structure of dirs and packages (#914)

* implement proposal

* update docs and replace py-env

* more docs

* suggested proposal

* update docs

* add to_file parameter

* remove comment from Makefile

* suggested improvements

* move tests from basic to py_config

* retain leading slash from the first path
This commit is contained in:
Madhur Tandon
2022-11-08 17:26:45 +05:30
committed by GitHub
parent 2f452e9dc7
commit 515858f313
27 changed files with 298 additions and 133 deletions

View File

@@ -0,0 +1,39 @@
import { joinPaths } from '../utils';
import { FetchConfig } from "../pyconfig";
export function calculatePaths(fetch_cfg: FetchConfig[]) {
const fetchPaths: string[] = [];
const paths: string[] = [];
fetch_cfg.forEach(function (each_fetch_cfg: FetchConfig) {
const from = each_fetch_cfg.from || "";
const to_folder = each_fetch_cfg.to_folder || ".";
const to_file = each_fetch_cfg.to_file;
const files = each_fetch_cfg.files;
if (files !== undefined)
{
if (to_file !== undefined)
{
throw Error(`Cannot use 'to_file' and 'files' parameters together!`);
}
for (const each_f of files)
{
const each_fetch_path = joinPaths([from, each_f]);
fetchPaths.push(each_fetch_path);
const each_path = joinPaths([to_folder, each_f]);
paths.push(each_path);
}
}
else
{
fetchPaths.push(from);
const filename = to_file || from.split('/').pop();
if (filename === '') {
throw Error(`Couldn't determine the filename from the path ${from}, supply ${to_file} parameter!`);
}
else {
paths.push(joinPaths([to_folder, filename]));
}
}
});
return [paths, fetchPaths];
}