Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add config for PyPI runtime publishing #5273

Merged
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
30 changes: 30 additions & 0 deletions Source/DafnyRuntime/DafnyRuntimePython/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### from https://github.com/github/gitignore/blob/main/Python.gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Environments
.env
venv/
62 changes: 62 additions & 0 deletions Source/DafnyRuntime/DafnyRuntimePython/BUILDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Building the DafnyRuntimePython

## Prerequisites

- the `dotnet` CLI, to build Dafny
- Python, to build and upload the package
- [TestPyPI credentials](https://packaging.python.org/en/latest/guides/using-testpypi/), if you will upload to TestPyPI
- PyPI credentials, if you will upload to PyPI

## Steps

1. Ensure that the `System_` module is up-to-date:

```bash
# Ensure that the Dafny build is up-to-date,
# as it will be used to compile the System_ module.
$ dotnet build --project ../../Dafny

# Compile the System_ runtime module.
$ make update-system-module
```

2. Build the distribution package:

```bash
# Set up the build tooling
$ make setup-venv

# Remove old build artifacts
$ make clean-package

# Build the distribution package
$ make build-package
```

3. Check that the distribution package looks right locally and on TestPyPI,
as (production) PyPI does not allow overwriting uploaded packages:

```bash
# List the distribution package's files, and check that:
# 1. the version number is correct
# 2. the `System_/__init__.py` file exists
# 3. the `dafny/__init__.py` file exists
$ tar tf dist/dafnyruntimepython-X.Y.Z.tar.gz

# Upload to TestPyPI, and check that it appears correct at
# <https://test.pypi.org/project/DafnyRuntimePython/>.
$ make upload-package-testpypi
```

4. Upload to PyPI:

```bash
$ make upload-package-pypi
```

You can view the uploaded package at <https://pypi.org/project/DafnyRuntimePython/>.

## More info

The packaging process is described in
<https://packaging.python.org/en/latest/tutorials/packaging-projects/>
20 changes: 19 additions & 1 deletion Source/DafnyRuntime/DafnyRuntimePython/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
DAFNY = dotnet run --project ../../Dafny --no-build --

GENERATED_SYSTEM_MODULE_SOURCE=../obj/systemModulePopulator-py/System_.py
GENERATED_SYSTEM_MODULE_TARGET=System_.py
GENERATED_SYSTEM_MODULE_TARGET=System_/__init__.py

VIRTUALENV = venv

all: check-system-module

Expand All @@ -15,3 +17,19 @@ check-system-module: build-system-module

update-system-module: build-system-module
cp $(GENERATED_SYSTEM_MODULE_SOURCE) $(GENERATED_SYSTEM_MODULE_TARGET)

setup-venv:
python -m venv --clear $(VIRTUALENV)
$(VIRTUALENV)/bin/pip install --upgrade build twine

clean-package:
rm -rf dist/ *.egg-info/

build-package:
$(VIRTUALENV)/bin/python -m build

upload-package-testpypi:
$(VIRTUALENV)/bin/python -m twine upload --repository testpypi dist/*

upload-package-pypi:
$(VIRTUALENV)/bin/python -m twine upload dist/*
24 changes: 24 additions & 0 deletions Source/DafnyRuntime/DafnyRuntimePython/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[project]
name = "DafnyRuntimePython"
version = "4.8.1"
authors = [
{ name = "The Dafny core team", email = "[email protected]" },
]
description = "Dafny runtime for Python"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
Homepage = "https://github.com/dafny-lang/dafny"
Issues = "https://github.com/dafny-lang/dafny/issues"

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
packages = ["_dafny", "System_"]
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ hello, Dafny
Dafny program verifier finished with 0 verified, 0 errors
Wrote textual form of target program to CompileAndThenRun-py/__main__.py
Additional output written to CompileAndThenRun-py/CompileAndThenRun-py.dtr
Additional output written to CompileAndThenRun-py/System_.py
Additional output written to CompileAndThenRun-py/_dafny.py
Additional output written to CompileAndThenRun-py/System_/__init__.py
Additional output written to CompileAndThenRun-py/_dafny/__init__.py
Additional output written to CompileAndThenRun-py/module_.py
hello, Dafny
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ hello, Dafny
Dafny program verifier finished with 0 verified, 0 errors
Wrote textual form of target program to JustRun-py/__main__.py
Additional output written to JustRun-py/JustRun-py.dtr
Additional output written to JustRun-py/System_.py
Additional output written to JustRun-py/_dafny.py
Additional output written to JustRun-py/System_/__init__.py
Additional output written to JustRun-py/_dafny/__init__.py
Additional output written to JustRun-py/module_.py
Running...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ hello, Dafny
Dafny program verifier finished with 0 verified, 0 errors
Wrote textual form of target program to ManualCompile-py/__main__.py
Additional output written to ManualCompile-py/ManualCompile-py.dtr
Additional output written to ManualCompile-py/System_.py
Additional output written to ManualCompile-py/_dafny.py
Additional output written to ManualCompile-py/System_/__init__.py
Additional output written to ManualCompile-py/_dafny/__init__.py
Additional output written to ManualCompile-py/module_.py
hello, Dafny