|
1 | 1 | # Databricks notebook source
|
2 | 2 | # MAGIC %md
|
3 |
| -# MAGIC **NOTE**: the following cell _**should**_ fail. |
| 3 | +# MAGIC # Introduction to Databricks Repos |
| 4 | + |
| 5 | +# COMMAND ---------- |
| 6 | + |
| 7 | +# MAGIC %md |
| 8 | +# MAGIC |
| 9 | +# MAGIC This repo is created to demonstrate Git integration with Databricks Repos. Databricks Repos is a visual Git client in Databricks. **It supports common Git operations such a cloning a repository, committing and pushing, pulling, branch management, and visual comparison of diffs when committing.** |
| 10 | +# MAGIC |
| 11 | +# MAGIC Within Repos you can develop code in notebooks or other files and follow data science and engineering code development best practices using Git for version control, collaboration, and CI/CD. |
| 12 | +# MAGIC |
| 13 | +# MAGIC *In Databricks Repos*, you can use Git functionality to: |
| 14 | +# MAGIC - Clone, push to, and pull from a remote Git repository. |
| 15 | +# MAGIC - Create and manage branches for development work. |
| 16 | +# MAGIC - Create notebooks, and edit notebooks and other files. |
| 17 | +# MAGIC - Visually compare differences upon commit. |
| 18 | +# MAGIC |
| 19 | +# MAGIC For following tasks, *work in your Git provider*: |
| 20 | +# MAGIC - Create a pull request. |
| 21 | +# MAGIC - Resolve merge conflicts. |
| 22 | +# MAGIC - Merge or delete branches. |
| 23 | +# MAGIC - Rebase a branch. |
| 24 | + |
| 25 | +# COMMAND ---------- |
| 26 | + |
| 27 | +# MAGIC %md |
| 28 | +# MAGIC ## Importing Notebooks/Modules |
| 29 | +# MAGIC |
| 30 | +# MAGIC You can import Databricks notebooks as well as python or R modules. |
| 31 | +# MAGIC |
| 32 | +# MAGIC ### Import Python Modules |
4 | 33 | # MAGIC
|
5 |
| -# MAGIC Relative imports of Python libraries are currently not supported. ([Custom libraries can be uploaded to the workspace or installed from PyPi](https://docs.databricks.com/libraries/workspace-libraries.html).) |
| 34 | +# MAGIC The current working directory of your repo and notebook are automatically added to the Python path. When you work in the repo root, you can import modules from the root directory and all subdirectories. |
6 | 35 |
|
7 | 36 | # COMMAND ----------
|
8 | 37 |
|
|
11 | 40 | # COMMAND ----------
|
12 | 41 |
|
13 | 42 | # MAGIC %md
|
| 43 | +# MAGIC ### Import Databricks Notebooks |
| 44 | +# MAGIC |
14 | 45 | # MAGIC Using `%run` allows you to execute a Databricks notebook in the current SparkSession, bringing any imported modules, declared variables, or defined functions into the current scope.
|
15 | 46 | # MAGIC
|
16 | 47 | # MAGIC Note that Databricks Python notebooks are stored as normal Python files with the first line
|
|
19 | 50 | # MAGIC # Databricks notebook source
|
20 | 51 | # MAGIC ```
|
21 | 52 | # MAGIC
|
22 |
| -# MAGIC The Databricks web app searches for this line when syncing changes with the remote repository and will render Python scripts as single cell notebooks automatically. |
| 53 | +# MAGIC When you import the notebook, Databricks recognizes it and imports it as a notebook, not as a Python module. |
| 54 | +# MAGIC |
| 55 | +# MAGIC If you want to import the notebook as a Python module, you must edit the notebook in a code editor and remove the line `# Databricks Notebook source`. Removing that line converts the notebook to a regular Python file. |
| 56 | +# MAGIC |
| 57 | +# MAGIC In the following cell, we are importing an Databricks notebook and run it. |
23 | 58 |
|
24 | 59 | # COMMAND ----------
|
25 | 60 |
|
26 |
| -# MAGIC %run ./my_lib/my_funcs |
| 61 | +# MAGIC %run ./my_lib/db-notebook |
27 | 62 |
|
28 | 63 | # COMMAND ----------
|
29 | 64 |
|
30 | 65 | # MAGIC %md
|
| 66 | +# MAGIC ## Using Imported Modules |
| 67 | +# MAGIC |
31 | 68 | # MAGIC The remainder of this notebook demonstrates using the functions declared in the referenced `my_funcs` Python file.
|
32 | 69 |
|
33 | 70 | # COMMAND ----------
|
|
0 commit comments