From 594b618031394a0926d4eef4cfc251000c4e8d08 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 11 Sep 2023 08:19:15 +0200 Subject: [PATCH] set working dir to test dir in snippet tests allow to import snippets from any file --- docs/website/docs/conftest.py | 5 ++--- docs/website/docs/getting-started.md | 4 ++-- docs/website/package.json | 6 +++--- docs/website/{ => tools}/update_snippets.js | 9 +++++++-- 4 files changed, 14 insertions(+), 10 deletions(-) rename docs/website/{ => tools}/update_snippets.js (94%) diff --git a/docs/website/docs/conftest.py b/docs/website/docs/conftest.py index 9e3fb745fd..088dfc8071 100644 --- a/docs/website/docs/conftest.py +++ b/docs/website/docs/conftest.py @@ -4,10 +4,9 @@ from tests.utils import patch_home_dir, autouse_test_storage, preserve_environ, duckdb_pipeline_location, wipe_pipeline @pytest.fixture(autouse=True) -def set_working_dir(): +def set_working_dir(request): # always set working dir to main website folder - abspath = os.path.abspath(__file__) - dname = os.path.dirname(abspath) + dname = os.path.dirname(request.module.__file__) os.chdir(dname) def pytest_configure(config): diff --git a/docs/website/docs/getting-started.md b/docs/website/docs/getting-started.md index 47ea61e937..8dbabd2430 100644 --- a/docs/website/docs/getting-started.md +++ b/docs/website/docs/getting-started.md @@ -40,7 +40,7 @@ Make sure that your `dlt` version is **0.3.15** or above. Check it in the termin Let's load a list of Python objects (dictionaries) into `duckdb` and inspect the created dataset: - + ```python import dlt @@ -58,7 +58,7 @@ load_info = pipeline.run(data, table_name="users") print(load_info) ``` - + Save this python script with the name `quick_start_pipeline.py` and run the following command: diff --git a/docs/website/package.json b/docs/website/package.json index 29fe766087..768917dd5d 100644 --- a/docs/website/package.json +++ b/docs/website/package.json @@ -4,9 +4,9 @@ "private": true, "scripts": { "docusaurus": "docusaurus", - "start": "node update_snippets.js --watch & docusaurus start", - "build": "node update_snippets.js && docusaurus build", - "build:netlify": "node update_snippets.js && docusaurus build --out-dir build/docs", + "start": "node tools/update_snippets.js --watch & docusaurus start", + "build": "node tools/update_snippets.js && docusaurus build", + "build:netlify": "node tools/update_snippets.js && docusaurus build --out-dir build/docs", "swizzle": "docusaurus swizzle", "clear": "docusaurus clear", "serve": "docusaurus serve", diff --git a/docs/website/update_snippets.js b/docs/website/tools/update_snippets.js similarity index 94% rename from docs/website/update_snippets.js rename to docs/website/tools/update_snippets.js index 0458ad5991..00f38cdfef 100644 --- a/docs/website/update_snippets.js +++ b/docs/website/tools/update_snippets.js @@ -3,7 +3,7 @@ const path = require('path'); const dedent = require('dedent'); var watch = require('node-watch'); -const BASE_DIR = "./docs"; +const BASE_DIR = "./docs/"; const DOCS_EXTENSIONS = [".md", ".mdx"]; const SNIPPETS_FILE_SUFFIX = "-snippets.py" @@ -67,7 +67,12 @@ function buildSnippetMap(lines, fileName) { // get the right snippet for a file function getSnippet(fileName, snippetName) { const ext = path.extname(fileName); - const snippetsFileName = fileName.slice(0, -ext.length) + SNIPPETS_FILE_SUFFIX; + const snippetParts = snippetName.split("::"); + let snippetsFileName = fileName.slice(0, -ext.length) + SNIPPETS_FILE_SUFFIX; + if (snippetParts.length > 1) { + snippetsFileName = BASE_DIR + snippetParts[0]; + snippetName = snippetParts[1]; + } const lines = fs.readFileSync(snippetsFileName, 'utf8').split(/\r?\n/); const snippetMap = buildSnippetMap(lines, snippetsFileName);