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
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ FROM python:3.12-slim
# * This app uses the git binary within the source code, hence coopying it over
COPY --from=build-app /app/.venv /app/.venv
COPY --from=build-app /usr/bin/git /usr/bin/git
COPY --from=build-app /usr/bin/unzip /usr/bin/unzip
COPY --from=build-app /app/india_forecast_app /app/india_forecast_app

# This is just a check to make sure it works, we've had problems with this in the past
ENV PATH="/app/.venv/bin:${PATH}"

ENTRYPOINT ["python","app/india_forecast_app/app.py"]
ENTRYPOINT ["app", "--write-to-db"]
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ SRC = india_forecast_app scripts tests

.PHONY: lint
lint:
poetry run ruff $(SRC)
ruff check $(SRC)

.PHONY: format
format:
poetry run ruff --fix $(SRC)
ruff check --fix $(SRC)

.PHONY: test
test:
poetry run pytest tests --disable-warnings
pytest tests --disable-warnings

.PHONY: docker.build
docker.build:
docker build -t ocf/india-forecast-app .
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

Runs wind and PV forecasts for India and saves to database

## Install dependencies (requires [poetry](https://python-poetry.org/))
## Install dependencies (requires [uv](https://docs.astral.sh/uv/))

```
poetry install
uv sync
```

## Linting and formatting
Expand Down Expand Up @@ -41,13 +41,13 @@ Replace `{DB_URL}` with a postgres DB connection string (see below for setting u

If testing on a local DB, you may use the following script to seed the the DB with a dummy user, site and site_group.
```
DB_URL={DB_URL} poetry run seeder
DB_URL={DB_URL} uv run seeder
```
⚠️ Note this is a destructive script and will drop all tables before recreating them to ensure a clean slate. DO NOT RUN IN PRODUCTION ENVIRONMENTS

This example runs the application and writes the results to stdout
```
DB_URL={DB_URL} NWP_ZARR_PATH={NWP_ZARR_PATH} poetry run app
DB_URL={DB_URL} NWP_ZARR_PATH={NWP_ZARR_PATH} uv run app
```

To save batches, you need to set the `SAVE_BATCHES_DIR` environment variable to directory.
Expand Down Expand Up @@ -97,7 +97,7 @@ docker run -it --rm -e DB_URL={DB_URL} -e NWP_ZARR_PATH={NWP_ZARR_PATH} ocf/indi

## Notes

This repo makes use of PyTorch (`torch` and `torchvision` packages) CPU-only version. In order to support installing PyTorch via poetry for various environments, we specify the exact wheels for each environment in the pyproject.toml file. Some background reading on why this is required can be found here: https://santiagovelez.substack.com/p/how-to-install-torch-cpu-in-poetry?utm_campaign=post&utm_medium=web&triedRedirect=true
This repo makes use of PyTorch (`torch` and `torchvision` packages) CPU-only version. In order to install the CPU-only build across environments, we point at the exact wheel for each platform in the `dependencies` list in pyproject.toml, guarded by environment markers.

## Contributors ✨

Expand Down Expand Up @@ -126,13 +126,13 @@ This project follows the [all-contributors](https://github.com/all-contributors/

## Troubleshooting

### Poetry Installation Issues
### Dependency Installation Issues

**Problem**: `poetry install` fails with dependency conflicts
**Solution**: Try updating Poetry first with `pip install --upgrade poetry`, then run `poetry update` followed by `poetry install`
**Problem**: `uv sync` fails with dependency conflicts
**Solution**: Try updating uv first with `uv self update`, then re-resolve with `uv lock --upgrade` followed by `uv sync`

**Problem**: Package installation errors
**Solution**: Check your Python version matches the one specified in `pyproject.toml`. You can use `poetry env use python3.x` to set the correct version.
**Solution**: Check your Python version matches the one specified in `pyproject.toml`. `uv python install` will fetch the right interpreter, and `uv sync` builds the environment against it.

### Docker Database Connection Issues

Expand Down
7 changes: 6 additions & 1 deletion india_forecast_app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""India Forecast App"""

__version__ = "1.2.8"
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version("india-forecast-app")
except PackageNotFoundError:
__version__ = "v?"
13 changes: 8 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies = [
"torch @ https://download.pytorch.org/whl/cpu/torch-2.3.1%2Bcpu-cp312-cp312-linux_x86_64.whl ; platform_system == 'Linux' and platform_machine == 'x86_64'",
"torchvision @ https://download.pytorch.org/whl/cpu/torchvision-0.18.1%2Bcpu-cp312-cp312-linux_x86_64.whl ; platform_system == 'Linux' and platform_machine == 'x86_64'",
"dp-sdk",
"betterproto>=2.0.0b7",
"grpclib>=0.4.7",
]

[dependency-groups]
Expand All @@ -55,23 +57,24 @@ dp-sdk = { url = "https://github.com/openclimatefix/data-platform/releases/downl
[project.urls]
repository = "https://github.com/openclimatefix/india-forecast-app"

[projects.scripts]
[project.scripts]
app = "india_forecast_app.app:app"
seeder = "scripts.seed_local_db:seed_db"
inspect = "tests.test_data.inspect:run"


[tool.setuptools.packages.find]
where = ["india_forecast_app"]
exclude = ["test*"]
where = ["."]
exclude = ["test*", "data*"]

[tool.setuptools.package-data]
"*" = ["py.typed", "*.conf"]
"*" = ["*.csv", "*.yaml", "*.nc"]

[tool.setuptools-git-versioning]
enabled = true
dirty_template = "{tag}"

[tool.pytest]
[tool.pytest.ini_options]
markers = ["requires_hf_token: marks tests that require a Hugging Face token to run"]

[tool.ruff]
Expand Down
4 changes: 4 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading