Skip to content
Open
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
70 changes: 64 additions & 6 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,57 @@ on:
branches: [ main ]
workflow_dispatch:

permissions:
contents: read

jobs:
check-lockfile:
name: "Check: pylock.toml Sync"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
persist-credentials: false
- name: Check if pyproject.toml was modified
id: check_pyproject
env:
GH_EVENT_NAME: ${{ github.event_name }}
GH_BASE_REF: ${{ github.base_ref }}
run: |
if [ "$GH_EVENT_NAME" = "pull_request" ]; then
git fetch origin "$GH_BASE_REF" --depth=1
BASE_REF="origin/$GH_BASE_REF"
else
BASE_REF="HEAD~1"
fi
if git diff --name-only "$BASE_REF" HEAD | grep -q '^pyproject.toml$'; then
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "pyproject.toml was modified. Validating pylock.toml sync..."
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "pyproject.toml was not modified. Skipping lockfile sync check."
fi
- uses: astral-sh/setup-uv@1edb52594c857e2b5b13128931090f0640537287 # v5.3.0
if: steps.check_pyproject.outputs.changed == 'true'
with:
enable-cache: true
- name: Verify pylock.toml is up to date with pyproject.toml
if: steps.check_pyproject.outputs.changed == 'true'
run: |
uv export --format pylock.toml --all-extras --default-index https://pypi.org/simple -o pylock_generated.toml --python 3.12
grep -v '^#' pylock.toml > pylock_current_clean.toml
grep -v '^#' pylock_generated.toml > pylock_new_clean.toml
diff -u pylock_current_clean.toml pylock_new_clean.toml || {
echo -e "\n---> pylock.toml is out of sync with pyproject.toml." >&2
echo -e "---> Run 'uv export --format pylock.toml --all-extras --default-index https://pypi.org/simple -o pylock.toml --python 3.12' locally and commit the changes." >&2
exit 1
}

pytest-job:
name: pytest-job
needs: check-lockfile
runs-on: ubuntu-latest
timeout-minutes: 30

Expand All @@ -31,17 +80,26 @@ jobs:
cancel-in-progress: true

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

# Install deps
- uses: actions/setup-python@v5
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: "3.12"
cache: pip

- run: pip --version
- run: pip install -e .[dev,pipeline,text]
- run: pip freeze
- uses: astral-sh/setup-uv@1edb52594c857e2b5b13128931090f0640537287 # v5.3.0
with:
enable-cache: true

- name: Install dependencies
run: |
uv pip install --system -r pylock.toml
uv pip install --system -e .

- name: Run pyrefly
run: pyrefly check

- name: Run core tests
run: pytest -vv -n auto --import-mode=importlib
63 changes: 63 additions & 0 deletions .github/workflows/update_lockfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Update pylock.toml

on:
schedule:
- cron: "0 3 1 * *" # Run monthly on the 1st of every month at 03:00 UTC
workflow_dispatch: # Allow manual trigger from GitHub Actions UI

jobs:
update-lockfile:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4.2.2
with:
persist-credentials: false

- name: Set up Python
uses: "actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38" # v5.4.0
with:
python-version: "3.12"

- name: Install uv
uses: "astral-sh/setup-uv@1edb52594c857e2b5b13128931090f0640537287" # v5.3.0
with:
enable-cache: true

- name: Regenerate pylock.toml
run: |
uv export --format pylock.toml --all-extras --default-index https://pypi.org/simple -o pylock.toml --python 3.12
go run github.com/google/addlicense@v1.1.1 -c "Google LLC" -y "2026" -l apache pylock.toml

- name: Create Pull Request
uses: "peter-evans/create-pull-request@dd2324fc52d5d43c699a5636bcf19fceaa70c284" # v7.0.7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update dependencies in pylock.toml"
title: "Update pylock.toml dependencies"
body: |
Automated update of dependencies in `pylock.toml` triggered by ${{ github.event_name }}.

Generated via `uv export --format pylock.toml --all-extras --default-index https://pypi.org/simple -o pylock.toml --python 3.12`.
branch: "automated/update-pylock"
delete-branch: true
labels: |
dependencies
automated
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ poetry.lock
.pytest_cache/

# Type checking
.pytype/
.pyrefly/

# Other
*.DS_Store
Expand Down
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,44 @@ DP Synth deliberately keeps its dependency footprint small:
- If your contribution requires a new dependency, discuss it in the issue
tracker first.

## Development Setup

We use [uv](https://docs.astral.sh/uv/) for managing your development
environment. It provides support for managing `pylock.toml` lock files and
is significantly faster than `pip`.

> [!NOTE]
> The `pylock.toml` file is generated using `uv`, but it follows standard
> specifications as per PEP 751 and should work with modern package managers
> that support it.

1. **Install uv:** Follow the [official instructions](https://docs.astral.sh/uv/getting-started/installation/).
2. **Create an environment and install dependencies:**

```bash
# Create a virtual environment with Python 3.12
uv venv --python 3.12
# Activate it (Linux/macOS)
source .venv/bin/activate
# Install all dependencies from the lockfile and install the project in editable mode
uv pip install -r pylock.toml
uv pip install -e .
```

3. **Updating `pylock.toml`:** Regenerate `pylock.toml` using `uv` periodically
or when modifying dependencies in `pyproject.toml`:

```bash
uv export --format pylock.toml --all-extras --default-index https://pypi.org/simple -o pylock.toml --python 3.12
go run github.com/google/addlicense@v1.1.1 -c "Google LLC" -y "2026" -l apache pylock.toml
```

Commit the updated `pylock.toml` to ensure CI and contributors remain in
sync.

Note that any update to `pyproject.toml` must be accompanied by a
regeneration of `pylock.toml`.

## Contributor License Agreement

Contributions to this project must be accompanied by a Contributor License
Expand Down
3 changes: 2 additions & 1 deletion dpsynth/dataset_descriptors/dataset_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def encoding_transform(
)
encoder = transformations.discrete_encoder(categorical_attr)
# Discretize then encode: float -> str interval -> int.
return encoder @ discretize_transform # pytype: disable=bad-return-type
return encoder @ discretize_transform

raise ValueError(
'`encoding_transform` is called before values are derived.'
Expand Down Expand Up @@ -306,3 +306,4 @@ def update_from_domain_specification(
attr_desc.categorical_attribute = spec
elif isinstance(spec, domain.NumericalAttribute):
attr_desc.numerical_attribute = spec
# test comment
4 changes: 2 additions & 2 deletions dpsynth/pipeline_transformations/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def save_data_local(
"""Saves the synthetic data to a file locally."""
match data_format:
case types.DataFormat.CSV:
save_csv(data, path, attributes) # pytype: disable=wrong-arg-types
save_csv(data, path, attributes)
case types.DataFormat.TFRECORD:
os.makedirs(os.path.dirname(path), exist_ok=True)
with tf.io.TFRecordWriter(path) as writer:
for record in data:
# record is expected to be a proto message.
writer.write(record.SerializeToString()) # type: ignore
writer.write(record.SerializeToString())
case _:
raise ValueError(f'Unsupported data format: {data_format}')

Expand Down
Loading
Loading