|
1 | 1 | # python-template |
2 | | -A template repository for |
| 2 | +A template repository for python projects in Sevan DWT. |
| 3 | + |
| 4 | +## Setup environment with uv |
| 5 | + |
| 6 | +> [!IMPORTANT] |
| 7 | +> You only need to follow the steps in this section if you are setting up an uv environment for the first time. If you already have an uv and credentials to sevan internal packages, you can skip to [Run a script](#run-a-script). |
| 8 | +
|
| 9 | +[UV](https://docs.astral.sh/uv/) is a Python package and project manager, which handles Python versions and virtual environments for you. |
| 10 | +To install uv, type the following in the PowerShell terminal: |
| 11 | + |
| 12 | +```powershell |
| 13 | +powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" |
| 14 | +``` |
| 15 | + |
| 16 | +This will download and install uv to: |
| 17 | + |
| 18 | +```powershell |
| 19 | +C:\Users\<your-username>\.local\bin |
| 20 | +``` |
| 21 | + |
| 22 | +You should receive a message that uv has been installed. |
| 23 | +To use uv from the terminal window, you need to add it to your system's PATH. |
| 24 | +Write the following in the PowerShell terminal: |
| 25 | + |
| 26 | +```powershell |
| 27 | +$env:Path = "C:\Users\<your-username>\.local\bin;$env:Path" |
| 28 | +``` |
| 29 | + |
| 30 | +After installing uv, you can check that uv is available by running the `uv` command: |
| 31 | + |
| 32 | +```powershell |
| 33 | +uv |
| 34 | +``` |
| 35 | + |
| 36 | +You should see a help menu listing the available commands. |
| 37 | + |
| 38 | + |
| 39 | +#### Configure credentials for internal packages |
| 40 | + |
| 41 | +To get access to the internal packages, you need to set up your credentials towards Repoforge. |
| 42 | +This is done by running the `setup_credentials.ps1` script from the terminal window: |
| 43 | + |
| 44 | +```powershell |
| 45 | +.\setup_credentials.ps1 |
| 46 | +``` |
| 47 | + |
| 48 | +You might be prompted to enter your Repoforge token. If that happens, request a token from EBG/SLF. |
| 49 | +Enter your token when prompted. The credentials should now be saved to: |
| 50 | + |
| 51 | +```powershell |
| 52 | +C:\Users\<your-username>\_netrc |
| 53 | +``` |
| 54 | + |
| 55 | +Your setup should now be complete. |
| 56 | + |
| 57 | + |
| 58 | +## Run a script |
| 59 | + |
| 60 | +To test your setup, you can try to run one of your scripts: |
| 61 | + |
| 62 | +```powershell |
| 63 | +uv run .\src\main.py |
| 64 | +``` |
| 65 | + |
| 66 | +## Develop your own scripts |
| 67 | + |
| 68 | +### Add a new package |
| 69 | + |
| 70 | +To add a new package, you can use the `uv add` command. For example, to add the `numpy` package, you can run: |
| 71 | + |
| 72 | +```powershell |
| 73 | +uv add numpy |
| 74 | +``` |
| 75 | + |
| 76 | +### Running the tests |
| 77 | + |
| 78 | +To run the tests for the projec: |
| 79 | + |
| 80 | +```powershell |
| 81 | +uv run pytest |
| 82 | +``` |
| 83 | + |
| 84 | +### Linting and formatting |
| 85 | + |
| 86 | +Pre-commit is used to format and lint the code-base before a commit is done. To install git-hooks: |
| 87 | + |
| 88 | +```console |
| 89 | +uv run pre-commit install |
| 90 | +``` |
| 91 | +It will now automatically run on the files changed when trying to commit. To run on all files: |
| 92 | + |
| 93 | +```console |
| 94 | +uv run pre-commit run --all-files |
| 95 | +``` |
0 commit comments