Skip to content

Commit b2260fc

Browse files
committed
feat: modernize packaging with pyproject.toml and uv
- Migrate package metadata from setup.py to pyproject.toml (PEP 621) - Keep dynamic version reading from __init__.py for compatibility - Use modern dependency-groups format (PEP 735) for dev dependencies - Add uv for fast dependency management (10-100x faster than pip) - Update all CI/CD workflows to use uv - Add .python-version file for consistent Python version - Update CONTRIBUTING.md with uv instructions - Use modern build tool instead of setup.py commands - Fix license format to use SPDX identifier Benefits: - Faster dependency installation and resolution with uv - Modern Python packaging standards compliance - Better dependency locking with uv.lock - Simpler, more maintainable configuration - Consistent Python version across environments
1 parent 526a578 commit b2260fc

File tree

4 files changed

+117
-42
lines changed

4 files changed

+117
-42
lines changed

.github/CONTRIBUTING.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,50 @@ information on using pull requests.
2323

2424
## Setup local environment
2525

26-
Clone the project and run the following commands to setup your environment
26+
Clone the project and install [uv](https://github.com/astral-sh/uv) (our package manager):
2727

2828
```sh
29-
python3.11 -m venv venv
30-
source venv/bin/activate
31-
pip3 install --upgrade pip
32-
python3.11 -m pip install -e ".[dev]"
29+
# Install uv (if not already installed)
30+
curl -LsSf https://astral.sh/uv/install.sh | sh
31+
32+
# Clone and setup the project
33+
git clone https://github.com/firebase/firebase-functions-python.git
34+
cd firebase-functions-python
35+
uv sync --dev
3336
```
3437

35-
(this also applies to setting up samples environment for each sample)
38+
This will automatically:
39+
- Create a virtual environment
40+
- Install all runtime and development dependencies
41+
- Use the Python version specified in `.python-version` (3.10)
42+
43+
(For samples, you can use the same approach but run `uv sync` in each sample directory)
3644

3745
### Running tests
3846

3947
Without coverage:
4048
```bash
41-
python3.11 -m pytest
49+
uv run pytest
4250
```
4351

4452
With coverage:
4553
```bash
46-
python3.11 -m pytest --cov=src --cov-report term --cov-report html --cov-report xml -vv
54+
uv run pytest --cov=src --cov-report term --cov-report html --cov-report xml -vv
4755
```
4856

4957
### Formatting code
5058

5159
```bash
52-
python3.11 -m ruff format .
60+
uv run ruff format .
5361
```
5462

5563
### Running lints & type checking
5664

5765
```bash
5866
# Type checking
59-
python3.11 -m mypy .
67+
uv run mypy .
6068
# Linting
61-
python3.11 -m ruff check .
69+
uv run ruff check .
6270
```
6371

6472
### Generating Docs

.github/workflows/ci.yaml

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ jobs:
2020
uses: actions/setup-python@v4
2121
with:
2222
python-version: ${{ matrix.python }}
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v3
25+
with:
26+
enable-cache: true
2327
- name: Install dependencies
2428
run: |
25-
python${{ matrix.python }} -m venv venv
26-
source venv/bin/activate
27-
pip3 install --upgrade pip
28-
python${{ matrix.python }} -m pip install -e ".[dev]"
29+
uv sync --dev
2930
- name: Test with pytest & coverage
3031
run: |
31-
source venv/bin/activate
32-
python${{ matrix.python }} -m pytest --cov=src --cov-report term --cov-report html --cov-report xml -vv
32+
uv run pytest --cov=src --cov-report term --cov-report html --cov-report xml -vv
3333
# TODO requires activation for this repository on codecov website first.
3434
# - name: Upload coverage to Codecov
3535
# uses: codecov/codecov-action@v3
@@ -42,20 +42,19 @@ jobs:
4242
uses: actions/setup-python@v4
4343
with:
4444
python-version: "3.10"
45+
- name: Install uv
46+
uses: astral-sh/setup-uv@v3
47+
with:
48+
enable-cache: true
4549
- name: Install dependencies
4650
run: |
47-
python3.10 -m venv venv
48-
source venv/bin/activate
49-
pip3 install --upgrade pip
50-
python3.10 -m pip install -e ".[dev]"
51+
uv sync --dev
5152
- name: Lint with ruff
5253
run: |
53-
source venv/bin/activate
54-
python3.10 -m ruff check .
54+
uv run ruff check .
5555
- name: Lint with mypy
5656
run: |
57-
source venv/bin/activate
58-
python3.10 -m mypy .
57+
uv run mypy .
5958
6059
docs:
6160
runs-on: ubuntu-latest
@@ -65,17 +64,17 @@ jobs:
6564
uses: actions/setup-python@v4
6665
with:
6766
python-version: "3.10"
67+
- name: Install uv
68+
uses: astral-sh/setup-uv@v3
69+
with:
70+
enable-cache: true
6871
- name: Install dependencies
6972
run: |
70-
python3.10 -m venv venv
71-
source venv/bin/activate
72-
pip3 install --upgrade pip
73-
python3.10 -m pip install -e ".[dev]"
73+
uv sync --dev
7474
- name: Generate Reference Docs
7575
run: |
76-
source venv/bin/activate
7776
mkdir ./docs/build
78-
./docs/generate.sh --out=./docs/build/ --pypath=src/
77+
uv run ./docs/generate.sh --out=./docs/build/ --pypath=src/
7978
- uses: actions/upload-artifact@v4
8079
name: Upload Docs Preview
8180
with:
@@ -90,13 +89,13 @@ jobs:
9089
uses: actions/setup-python@v4
9190
with:
9291
python-version: "3.10"
92+
- name: Install uv
93+
uses: astral-sh/setup-uv@v3
94+
with:
95+
enable-cache: true
9396
- name: Install dependencies
9497
run: |
95-
python3.10 -m venv venv
96-
source venv/bin/activate
97-
pip3 install --upgrade pip
98-
python3.10 -m pip install -e ".[dev]"
98+
uv sync --dev
9999
- name: Check Formatting with ruff
100100
run: |
101-
source venv/bin/activate
102-
python3.10 -m ruff format --check .
101+
uv run ruff format --check .

.github/workflows/release.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,23 @@ jobs:
4141
with:
4242
python-version: '3.10'
4343

44+
- name: Install uv
45+
uses: astral-sh/setup-uv@v3
46+
with:
47+
enable-cache: true
48+
4449
- name: Install dependencies
4550
run: |
46-
pip install --upgrade pip
47-
python -m pip install -e ".[dev]"
51+
uv sync --dev
4852
4953
- name: Test with pytest & coverage
5054
run: |
51-
python -m pytest --cov=src --cov-report term --cov-report html --cov-report xml -vv
55+
uv run pytest --cov=src --cov-report term --cov-report html --cov-report xml -vv
5256
5357
# Build the Python Wheel and the source distribution.
5458
- name: Package release artifacts
5559
run: |
56-
python -m pip install setuptools wheel
57-
python setup.py bdist_wheel sdist
60+
uv run python -m build
5861
5962
# Attach the packaged artifacts to the workflow output. These can be manually
6063
# downloaded for later inspection if necessary.

pyproject.toml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,58 @@
1+
[build-system]
2+
requires = ["setuptools>=63.4.2", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "firebase_functions"
7+
description = "Firebase Functions Python SDK"
8+
readme = "README.md"
9+
authors = [{name = "Firebase Team"}]
10+
license = "Apache-2.0"
11+
keywords = ["firebase", "functions", "google", "cloud"]
12+
classifiers = [
13+
"Development Status :: 4 - Beta",
14+
"Intended Audience :: Developers",
15+
"Topic :: Software Development :: Build Tools",
16+
"Programming Language :: Python :: 3.10",
17+
"Programming Language :: Python :: 3.11",
18+
"Programming Language :: Python :: 3.12",
19+
]
20+
requires-python = ">=3.10"
21+
dependencies = [
22+
"flask>=2.1.2",
23+
"functions-framework>=3.0.0",
24+
"firebase-admin>=6.0.0",
25+
"pyyaml>=6.0",
26+
"typing-extensions>=4.4.0",
27+
"cloudevents>=1.2.0,<2.0.0",
28+
"flask-cors>=3.0.10",
29+
"pyjwt[crypto]>=2.5.0",
30+
"google-events==0.5.0",
31+
"google-cloud-firestore>=2.11.0",
32+
]
33+
dynamic = ["version"]
34+
35+
[project.urls]
36+
Homepage = "https://github.com/firebase/firebase-functions-python"
37+
Repository = "https://github.com/firebase/firebase-functions-python"
38+
Documentation = "https://firebase.google.com/docs/functions"
39+
"Bug Tracker" = "https://github.com/firebase/firebase-functions-python/issues"
40+
41+
42+
[tool.setuptools.dynamic]
43+
version = {attr = "firebase_functions.__version__"}
44+
45+
[tool.setuptools.packages.find]
46+
where = ["src"]
47+
48+
[tool.setuptools.package-data]
49+
firebase_functions = ["py.typed"]
50+
151
[tool.pytest.ini_options]
252
pythonpath = [
353
".", "src/",
454
]
55+
556
[tool.coverage]
657
[tool.coverage.run]
758
omit = [
@@ -44,3 +95,17 @@ quote-style = "double"
4495
indent-style = "space"
4596
skip-magic-trailing-comma = false
4697
line-ending = "auto"
98+
99+
[dependency-groups]
100+
dev = [
101+
"pytest>=7.1.2,<9",
102+
"setuptools>=63.4.2",
103+
"pytest-cov>=3.0.0",
104+
"mypy>=1.0.0",
105+
"sphinx>=6.1.3",
106+
"sphinxcontrib-napoleon>=0.7",
107+
"toml>=0.10.2",
108+
"google-cloud-tasks>=2.13.1",
109+
"ruff>=0.1.0",
110+
"build>=1.0.0",
111+
]

0 commit comments

Comments
 (0)