Skip to content

Commit

Permalink
Merged in refactor/uv (pull request #447)
Browse files Browse the repository at this point in the history
move to uv 😃

Approved-by: Randy Taylor
Approved-by: Hasan Ammar
  • Loading branch information
jrkerns committed Sep 20, 2024
2 parents b3e9a2b + 320a51a commit 4706b46
Show file tree
Hide file tree
Showing 7 changed files with 2,193 additions and 90 deletions.
88 changes: 30 additions & 58 deletions bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
image: python:3.11-slim
image: ghcr.io/astral-sh/uv:python3.11-bookworm-slim


definitions:
caches:
testfiles: tests_basic/test_files
precommit: ~/.cache/pre-commit
uv: ~/.cache/uv
steps:
- step: &pre-commit-checks
name: Pre-commit checks
image: python:3.11-slim
- step: &pre-commit-checks-and-setup
name: Pre-commit checks & env setup
script:
- apt-get update
- apt-get -y install git
- pip install pre-commit
- pre-commit run --all-files
- step: &set-up-env
name: Set up Env
- uv sync --frozen
- uv tool run pre-commit run --all-files
caches:
- pip
script:
- apt-get update
- python -m venv venv
- source venv/bin/activate
- pip install .[dev]
- pip install .[docs]
- pip uninstall pylinac -y
- pip freeze
- precommit
- uv
artifacts:
- venv/**
- .venv/**
- step: &push-to-github
name: Push to Github
clone:
Expand All @@ -38,8 +30,7 @@ definitions:
- step: &build-docs
name: Build Docs
script:
- source venv/bin/activate
- nox -s build_docs
- uv run nox -s build_docs
condition:
changesets:
includePaths:
Expand All @@ -49,8 +40,7 @@ definitions:
name: Run CBCT Tests
size: 2x
script:
- source venv/bin/activate
- pytest tests_basic/test_cbct.py -n 2 --cov=pylinac.cbct --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_cbct.py -n 2 --cov=pylinac.cbct --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -62,8 +52,7 @@ definitions:
- step: &quart-tests
name: Run Quart Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_quart.py --cov=pylinac.quart --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_quart.py --cov=pylinac.quart --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -76,8 +65,7 @@ definitions:
- step: &acr-tests
name: Run ACR CT/MRI Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_acr.py --cov=pylinac.acr --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_acr.py --cov=pylinac.acr --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -90,8 +78,7 @@ definitions:
- step: &cheese-tests
name: Run Cheese Phantom Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_cheese.py --cov=pylinac.cheese --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_cheese.py --cov=pylinac.cheese --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -104,8 +91,7 @@ definitions:
- step: &planar-tests
name: Run Planar Imaging Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_planar_imaging.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_planar_imaging.py --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -117,8 +103,7 @@ definitions:
- step: &dlg-tests
name: Run DLG Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_dlg.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_dlg.py --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -130,8 +115,7 @@ definitions:
- step: &field-analysis-tests
name: Run Field Analysis Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_field_analysis.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_field_analysis.py --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -143,8 +127,7 @@ definitions:
- step: &machine-log-tests
name: Run Machine Logs Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_logs.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_logs.py --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -156,8 +139,7 @@ definitions:
- step: &picket-fence-tests
name: Run Picket Fence Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_picketfence.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_picketfence.py --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -169,8 +151,7 @@ definitions:
- step: &starshot-tests
name: Run Starshot Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_starshot.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_starshot.py --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -182,8 +163,7 @@ definitions:
- step: &calibration-tests
name: Run TG-51/TRS-398 Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_tg51.py tests_basic/test_trs398.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_tg51.py tests_basic/test_trs398.py --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -196,8 +176,7 @@ definitions:
- step: &vmat-tests
name: Run VMAT Tests
script:
- source venv/bin/activate
- pytest tests_basic/test_vmat.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_vmat.py --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -210,8 +189,7 @@ definitions:
name: Run Winston-Lutz Tests
size: 2x
script:
- source venv/bin/activate
- pytest tests_basic/test_winstonlutz.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_winstonlutz.py --cov-report term --junitxml=./test-reports/pytest_results.xml
condition:
changesets:
includePaths:
Expand All @@ -222,8 +200,7 @@ definitions:
name: Run Winston-Lutz Multi-Target Multi-Field Tests
size: 2x
script:
- source venv/bin/activate
- pytest tests_basic/test_winstonlutz_mtmf.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_winstonlutz_mtmf.py --cov-report term --junitxml=./test-reports/pytest_results.xml
condition:
changesets:
includePaths:
Expand All @@ -233,8 +210,7 @@ definitions:
- step: &plan-generator-tests
name: Plan generator tests
script:
- source venv/bin/activate
- pytest tests_basic/test_plan_generator.py tests_basic/test_generated_plans.py --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/test_plan_generator.py tests_basic/test_generated_plans.py --cov-report term --junitxml=./test-reports/pytest_results.xml
condition:
changesets:
includePaths:
Expand All @@ -245,8 +221,7 @@ definitions:
- step: &core-module-tests
name: Run core module tests
script:
- source venv/bin/activate
- pytest tests_basic/core --cov-report term --junitxml=./test-reports/pytest_results.xml
- uv run --locked pytest tests_basic/core --cov-report term --junitxml=./test-reports/pytest_results.xml
caches:
- testfiles
condition:
Expand All @@ -259,19 +234,18 @@ definitions:
script:
- apt-get update
- apt-get install wget -y
- pip install nox
# Get gcloud CLI
- wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-416.0.0-linux-x86_64.tar.gz -O gcloud_cli.tar.gz
- tar -xf gcloud_cli.tar.gz
- ./google-cloud-sdk/install.sh --quiet
- export PATH="./google-cloud-sdk/bin:$PATH"
- nox -s update_dev_kraken
- uv run --locked nox -s update_dev_kraken

pipelines:

custom:
update-kraken:
- step: *set-up-env
- step: *pre-commit-checks-and-setup
- step: *update-dev-kraken
pypi:
- step:
Expand All @@ -297,9 +271,7 @@ pipelines:

pull-requests:
'**':
- parallel:
- step: *set-up-env
- step: *pre-commit-checks
- step: *pre-commit-checks-and-setup
- parallel:
- step: *build-docs
- step: *cbct-tests
Expand Down
6 changes: 6 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Legend
v 3.28.0
--------

General
^^^^^^^

* The minimum version of Python supported is now 3.9 as the end-of-life of Python 3.8 is October 2024.
* Along with this, minimum versions of numpy, scipy, and matplotlib have been bumped to versions that support Python 3.9.

Starshot
^^^^^^^^

Expand Down
24 changes: 20 additions & 4 deletions docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,29 @@ Be sure to ask for help if you need it!
* `Fork <https://github.com/jrkerns/pylinac/fork>`__ the pylinac repository.
* Clone your `forked repository to your local machine <https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository>`__: ``git clone`` followed by the URL of your forked repository.
Some IDEs also have a GUI for this. See also :ref:`distro_stack`.
* Create a virtual environment. This is optional but highly recommended. See the `Python guide <https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/>`__ to set up a new venv.
* Install the requirements and developer requirements: ``pip install .[dev]``
* Install the Python tool `uv <https://docs.astral.sh/uv/getting-started/installation/>`__.
* Install Python if necessary: ``uv python install``.
* Install the requirements: ``uv sync --frozen``. This will create a new virtual environment at ``.venv`` and install all required dependencies.
* Create a new branch for your work: ``git checkout -b my_new_branch``
* Make your changes
* Make your changes.
* Write tests for your changes. Most test modules in pylinac have a 1:1 correlation with the library modules and thus the
expected location should be straightforward.
* Run the tests locally: ``pytest``
* Run the tests locally: ``uv run pytest``
* If the tests pass, commit your changes: ``git commit -m "my new feature!"``
* Push your changes to your forked repository: ``git push origin my_new_branch``
* Make a new pull request to the main pylinac repository.

Building the package
--------------------

.. note::

This is for maintainers only.

To build a distributable package of pylinac:

.. code-block:: bash
uvx hatch version <new version>
uv build
uvx twine upload dist/pylinac-v<new version>*
2 changes: 1 addition & 1 deletion pylinac/core/array_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


def array_not_empty(array: np.ndarray) -> None:
"""Check an array isn't empty"""
"""Check an array isn't empty."""
if not array.size:
raise ValueError("Array must not be empty")

Expand Down
55 changes: 30 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pylinac"
requires-python = ">=3.8"
requires-python = ">=3.9"
description = "A toolkit for performing TG-142 QA-related tasks on a linear accelerator"
authors = [
{name = "James Kerns", email = "[email protected]"}
Expand Down Expand Up @@ -28,45 +28,34 @@ classifiers=[
]

dependencies = [
"scikit-image>=0.17.3",
"numpy>=0.16,<2",
"scipy>=1.1",
"scikit-image>=0.18",
"numpy>=1.20,<2",
"scipy>=1.11",
"tqdm>=3.8",
"Pillow>=4.0",
"argue~=0.3.1",
"py-linq~=1.4.0",
"reportlab>=3.3",
"pydicom>=2.0,<3",
"matplotlib>=2.0",
"matplotlib>=3.0",
"tabulate~=0.9.0",
"pydantic>=2.0",
"eval-type-backport; python_version<='3.8'",
"quaac",
"plotly>=5.0",
"sphinx-design>=0.6.0",
]

# unfortunately, RTD doesn't support custom installes like `uv sync`. Only "extra" dependencies are supported.
# this extra dependency entry point shouldn't be used outside of RTD.
# Use `uv sync` for local development.
[project.optional-dependencies]
dev = [
"pytest",
"pytest-xdist",
"pytest-cov",
"nox",
"furo",
"google-cloud-storage",
"sphinx",
"sphinx-design",
"sphinx-autobuild",
"sphinx-copybutton",
"pre-commit",
"hatch",
"parameterized",
]
docs = [
"sphinx",
"sphinx-design",
"sphinx-copybutton",
"furo",
"autodoc_pydantic"
"sphinx-autobuild>=2021.3.14",
"sphinx-copybutton>=0.5.2",
"sphinx-design>=0.6.0",
"sphinx>=7.1.2",
"furo>=2024.8.6",
]

[build-system]
Expand Down Expand Up @@ -121,3 +110,19 @@ ignore = ['E501']
"*/__init__.py" = ["F401"]
"pylinac/calibration/trs398.py" = ["F401", "I001"]
"pylinac/core/profile.py" = ['F821']

[tool.uv]
dev-dependencies = [
"autodoc-pydantic>=2.1.0",
"furo>=2024.8.6",
"google-cloud-storage>=2.18.2",
"nox>=2024.4.15",
"parameterized>=0.9.0",
"pytest-cov>=5.0.0",
"pytest-xdist>=3.6.1",
"pytest>=8.3.2",
"sphinx-autobuild>=2021.3.14",
"sphinx-copybutton>=0.5.2",
"sphinx-design>=0.6.0",
"sphinx>=7.1.2",
]
3 changes: 1 addition & 2 deletions tests_basic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def get_file_from_cloud_test_repo(path: List[str], force: bool = False) -> str:
if len(path) > 1:
for idx in range(1, len(path)):
local_dir = osp.join(osp.dirname(__file__), LOCAL_TEST_DIR, *path[:idx])
if not osp.isdir(local_dir):
os.mkdir(local_dir)
os.makedirs(local_dir, exist_ok=True)

blob.download_to_filename(local_filename)
time.sleep(2)
Expand Down
Loading

0 comments on commit 4706b46

Please sign in to comment.