Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ replace = Version: {new_version}
[bumpversion:file:assets/manifest.json]
search = "id": "{current_version}"
replace = "id": "{new_version}"

[bumpversion:file:pyproject.toml]
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:uv.lock]
search = name = "clima"
version = "{current_version}"
replace = name = "clima"
version = "{new_version}"
3 changes: 2 additions & 1 deletion .gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ tests
assets/data/OneBuilding*.zip

assets/data/Region*.kml
file_system_store
file_system_store
.venv
19 changes: 8 additions & 11 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,28 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Set up uv
uses: astral-sh/setup-uv@v10.3.1

- name: Build Clima
run: |-
pip install pipenv
pipenv install --dev
uv sync --frozen

- name: Ruff Check
run: |-
pipenv run ruff check . --output-format=github
uv run ruff check . --output-format=github

- name: Ruff Format (verify)
run: |-
pipenv run ruff format --check .
uv run ruff format --check .

- name: Install Playwright Browsers
run: |
pipenv run playwright install chromium
uv run playwright install chromium

- name: Start Clima
run: |-
pipenv run python main.py &
uv run python main.py &

- name: Wait for Clima to be ready
run: |
Expand All @@ -46,4 +43,4 @@ jobs:
- name: Test Clima
run: |-
cd tests
pipenv run pytest --base-url=http://127.0.0.1:8080 -vv
uv run pytest --base-url=http://127.0.0.1:8080 -vv
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10
3.11
22 changes: 14 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install pipenv
RUN python -m pip install --upgrade pip \
&& python -m pip install --no-cache-dir "pipenv>=2024.0,<2026.0"
# Install uv
COPY --from=ghcr.io/astral-sh/uv:0.13.1 /uv /usr/local/bin/uv

# Use the image's Python 3.11 and keep the environment inside /app
ENV UV_PYTHON_DOWNLOADS=never \
UV_LINK_MODE=copy \
UV_PROJECT_ENVIRONMENT=/app/.venv \
PATH="/app/.venv/bin:$PATH"

# Set working directory
WORKDIR /app

# Copy Pipfile and Pipfile.lock
COPY Pipfile Pipfile.lock ./
# Copy the dependency files first so this layer is cached
COPY pyproject.toml uv.lock ./

# Install dependencies
RUN pipenv sync
# Install the locked production dependencies
RUN uv sync --frozen --no-dev

COPY . .

EXPOSE 8080

CMD ["pipenv", "run", "python", "main.py"]
CMD ["python", "main.py"]
33 changes: 0 additions & 33 deletions Pipfile

This file was deleted.

1,538 changes: 0 additions & 1,538 deletions Pipfile.lock

This file was deleted.

20 changes: 10 additions & 10 deletions docs/contributing/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ git clone https://github.com/<your-account-name>/clima.git
cd clima
```

Install the dependencies using pipenv. You will need to have pipenv installed on your machine. If you do not have it yet, please refer to [pipenv installation guide](https://pipenv.pypa.io/en/latest/#install-pipenv-today).
Install the dependencies using uv. You will need to have uv installed on your machine. If you do not have it yet, please refer to the [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/).

```bash
pipenv sync --dev
uv sync
````

Set up the upstream repository and check the output repositories.
Expand Down Expand Up @@ -87,17 +87,17 @@ Available [here](code_of_conduct.md)
We use ruff to enforce the code style and code formatting. You can run it with:

```bash
pipenv run ruff check .
pipenv run ruff format .
uv run ruff check .
uv run ruff format .
```

To ensure that the code is formatted correctly, we use a pre-commit hook that runs Ruff before every commit.
Run the following once to enable hooks in your local repo:

```bash
pipenv run pre-commit install
uv run pre-commit install
# optional: run on all files
pipenv run pre-commit run --all-files
uv run pre-commit run --all-files
```

Hence, you will need to make sure that the code is formatted correctly before committing your changes; otherwise, the commit will fail.
Expand All @@ -122,18 +122,18 @@ Before submitting a Pull Request, please make sure:
- You have installed project dependencies:

```bash
pipenv sync --dev
pipenv run playwright install # Required to install browsers
uv sync
uv run playwright install # Required to install browsers
```
Start the app server:
```bash
pipenv run python main.py
uv run python main.py
```
Then, from the root directory, run tests using pytest:
```bash
cd tests

pipenv run pytest --base-url=http://127.0.0.1:8080 -vv -n 2
uv run pytest --base-url=http://127.0.0.1:8080 -vv -n 2
```

## Submitting changes
Expand Down
57 changes: 30 additions & 27 deletions docs/contributing/run-project-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ description: >-

## Prerequisites

Python 3 installed on your machine and [pipenv](https://docs.pipenv.org).
[uv](https://docs.astral.sh/uv/) installed on your machine. You can install it by following the [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/).

* If you do not have Python installed on your machine you can follow [this guide](https://wiki.python.org/moin/BeginnersGuide/Download)
* You can install `pipenv` using the following command `pip install pipenv`.
* uv reads the Python version from `.python-version` (3.11) and downloads it if it is not already installed, so you do not need to install Python separately.

## Installation

Expand All @@ -24,61 +23,65 @@ This guide is for Mac OSX, Linux, or Windows.
$ cd clima
```

2. **Create a virtual environment using pipenv and install dependencies:**
2. **Create a virtual environment and install dependencies:**

```text
pipenv install --dev
uv sync
```

3. **Run tool locally**

Now you should be ready to run the tool locally.

`pipenv run python main.py`
`uv run python main.py`

Visit [http://localhost:8080](http://localhost:8080) in your browser to check it out. Note that whenever you want to run the tool, you have to activate the virtualenv first.
Visit [http://localhost:8080](http://localhost:8080) in your browser to check it out. `uv run` uses the project's virtual environment, so you do not need to activate it first.

### Adding new dependencies

Pipfiles contain information about the dependencies of your project, and supersede the requirements.txt file that is typically used in Python projects.
`pyproject.toml` lists the dependencies of the project, and `uv.lock` records the exact version of every package that gets installed.

To install a Python package for your project use the `install` keyword. For example,
To add a Python package to the project use the `add` command. For example,

`pipenv install beautifulsoup4`
`uv add beautifulsoup4`

The package name, together with its version and a list of its own dependencies, can be frozen by updating the Pipfile.lock. This is done using the lock keyword,
`uv add` updates both `pyproject.toml` and `uv.lock`. If you edit `pyproject.toml` by hand, update the lock file with

`pipenv lock`
`uv lock`

### Managing your development environment

There are usually some Python packages that are only required in your development environment and not in your production environment, such as unit testing packages. Pipenv will let you keep the two environments separate using the --dev flag. For example,
There are usually some Python packages that are only required in your development environment and not in your production environment, such as unit testing packages. uv keeps them in a separate `dev` dependency group using the --dev flag. For example,

`pipenv install --dev nose2`
`uv add --dev nose2`

## Testing

This project runs both Python unit tests, and Cypress end-to-end tests in CI.
The tests are end-to-end tests written with pytest and [Playwright](https://playwright.dev/python/). CI runs them on every push and pull request to `development`.

To run Python tests locally:
- If you haven't already, install Python dev dependencies.
- Then: `pipenv run python -m pytest`
To run them locally:
- Install the browser Playwright uses (only needed once): `uv run playwright install chromium`
- Start the Clima application with `uv run python main.py` and confirm that http://localhost:8080/ is up.
- In a second terminal, run the tests:

To run Cypress locally:
- If you haven't already, start the Clima application and confirm that http://localhost:8080/ is up.
- Then: `cd tests/node; npm install; npm run cy:open`
```bash
cd tests
uv run pytest --base-url=http://127.0.0.1:8080 -vv --numprocesses 4
```

## Versioning

When you release a new version of the tool you should first use `bumpversion` to update the version of the tool. You can use the following command:
When you release a new version of the tool you should first use `bump2version` to update the version of the tool. You can use the following command:

```text
bumpversion patch # alternatively you can use minor or major instead of patch
uv run bump2version patch # alternatively you can use minor or major instead of patch
```

If the above command do not work even if you have committed all the files try with `bumpversion patch --allow-dirty`
`bump2version` updates the version in `pyproject.toml`, `uv.lock`, `pages/lib/layout.py` and `assets/manifest.json`, then commits the change and tags it. The settings are in `.bumpversion.cfg`.

If the above command does not work even if you have committed all the files try with `uv run bump2version patch --allow-dirty`

Secondly, you should describe the changes in `CHANGELOG.md`
Secondly, you should describe the changes in `docs/version/changelog.md`

## Deploy to Google Cloud Run

Expand All @@ -88,13 +91,13 @@ First make sure you that:

* gcloud is up-to-date
* that you are logged in with the right account
* you have updated the Pipfile.lock.
* you have updated `uv.lock` (`uv lock`) and committed it.

First test the application.

```bash
cd tests
pipenv run pytest --base-url=http://127.0.0.1:8080 -vv --numprocesses 4
uv run pytest --base-url=http://127.0.0.1:8080 -vv --numprocesses 4
```

### Deploy test version manually using gcloud and docker locally - quicker and great to test small changes
Expand Down
46 changes: 46 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[project]
name = "clima"
version = "0.10.2"
requires-python = ">=3.11"
dependencies = [
"dash==3.2.0",
"dash-bootstrap-components==1.2.0",
"dash-extensions==1.0.7",
"dash-iconify==0.1.2",
"dash-leaflet==1.0.15",
"dash-mantine-components==2.2.1",
"kgcpy==1.1.8",
"numpy==1.26.3",
"pandas==2.2.0",
"plotly==5.18.0",
"pvlib==0.9.1",
"pythermalcomfort==2.9.1",
"requests==2.32.4",
"scipy==1.12.0",
]

[dependency-groups]
dev = [
"black==26.3.1",
"bump2version==1.0.1",
"cleanpy==0.5.1",
"pre-commit==4.6.0",
"pytest==9.0.3",
"pytest-playwright==0.7.2",
"pytest-xdist==3.8.0",
"ruff==0.15.12",
]

[tool.uv]
# Keep transitive packages on the major (or, for 0.x, minor) versions that the old
# Pipfile.lock used. Unconstrained resolution moved each of these across a major
# version, which the pinned direct dependencies were never tested against.
constraint-dependencies = [
"filelock<4",
"llvmlite<0.48",
"numba<0.66",
"pillow<13",
"pyee<14",
"python-dateutil<3",
"setuptools<83",
]
2 changes: 1 addition & 1 deletion scripts/build_locations_geojson.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Build assets/data/locations.geojson.gz from the two source data files.
Run from the repo root: pipenv run python scripts/build_locations_geojson.py
Run from the repo root: uv run python scripts/build_locations_geojson.py
"""

import gzip
Expand Down
Loading
Loading