Skip to content

Commit 242b15b

Browse files
authored
Automate PyPi uploads on release (#489)
* Automate PyPi release * Use our own PyPi release of sacred (yuck!) * Bump version number (#490) * Switch to generating version number from setuptools_scm * fix typo * Use v1 release * Add backwards compatibility logic * Disable local scheme * Fetch tags * use v3 not master * Bump to 3.8 everywhere * No cover for clause not expected to hit * Workaround flaky windows tests
1 parent b8a4c36 commit 242b15b

File tree

7 files changed

+95
-23
lines changed

7 files changed

+95
-23
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Adapted from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
2+
3+
name: Publish imitation distributions 📦 to PyPI and TestPyPI
4+
5+
on: push
6+
7+
jobs:
8+
build-n-publish:
9+
name: Build and publish imitation distributions 📦 to PyPI and TestPyPI
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
# Fetch tags needed by setuptools_scm to infer version number
16+
# See https://github.com/pypa/setuptools_scm/issues/414
17+
fetch-depth: 0
18+
- name: Set up Python 3.10
19+
uses: actions/setup-python@v3
20+
with:
21+
python-version: "3.10"
22+
23+
- name: Install pypa/build
24+
run: >-
25+
python -m
26+
pip install
27+
build
28+
--user
29+
- name: Build a binary wheel and a source tarball
30+
run: >-
31+
python -m
32+
build
33+
--sdist
34+
--wheel
35+
--outdir dist/
36+
.
37+
38+
# Publish new distribution to Test PyPi on every push.
39+
# This ensures the workflow stays healthy, and will also serve
40+
# as a source of alpha builds.
41+
- name: Publish distribution 📦 to Test PyPI
42+
uses: pypa/gh-action-pypi-publish@release/v1
43+
with:
44+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
45+
repository_url: https://test.pypi.org/legacy/
46+
47+
# Publish new distribution to production PyPi on releases.
48+
- name: Publish distribution 📦 to PyPI
49+
if: startsWith(github.ref, 'refs/tags/v')
50+
uses: pypa/gh-action-pypi-publish@release/v1
51+
with:
52+
password: ${{ secrets.PYPI_API_TOKEN }}

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
# -- Project information -----------------------------------------------------
2121

22-
import imitation # pytype: disable=import-error
22+
from importlib import metadata
2323

2424
project = "imitation"
25-
copyright = "2019-2021, Center for Human-Compatible AI" # noqa: A001
25+
copyright = "2019-2022, Center for Human-Compatible AI" # noqa: A001
2626
author = "Center for Human-Compatible AI"
2727

2828
# The full version, including alpha/beta/rc tags
29-
release = imitation.__version__
29+
version = metadata.version("imitation")
3030

3131

3232
# -- General configuration ---------------------------------------------------

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1+
[build-system]
2+
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tools.setuptools_scm]
6+
# Disable local scheme to allow uploads to Test PyPI.
7+
# See https://github.com/pypa/setuptools_scm/issues/342
8+
local_scheme = "no-local-version"
9+
110
[tool.black]
2-
target-version = ["py37"]
11+
target-version = ["py38"]

readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sphinx:
66
formats: all
77

88
python:
9-
version: 3.7
9+
version: 3.8
1010
install:
1111
- method: pip
1212
path: .

setup.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from setuptools import find_packages, setup
88
from setuptools.command.install import install
99

10-
import src.imitation # pytype: disable=import-error
11-
1210
IS_NOT_WINDOWS = os.name != "nt"
1311

1412
PARALLEL_REQUIRE = ["ray[debug,tune]>=1.13.0"]
@@ -80,7 +78,10 @@ def run(self):
8078
setup(
8179
cmdclass={"install": InstallCommand},
8280
name="imitation",
83-
version=src.imitation.__version__,
81+
# Disable local scheme to allow uploads to Test PyPI.
82+
# See https://github.com/pypa/setuptools_scm/issues/342
83+
use_scm_version={"local_scheme": "no-local-version"},
84+
setup_requires=["setuptools_scm"],
8485
description="Implementation of modern reward and imitation learning algorithms.",
8586
long_description=get_readme(),
8687
long_description_content_type="text/markdown",
@@ -99,13 +100,10 @@ def run(self):
99100
"torch>=1.4.0",
100101
"tqdm",
101102
"scikit-learn>=0.21.2",
102-
# TODO(adam): switch to master once stable-baselines3 PR#979 merged
103-
# https://github.com/DLR-RM/stable-baselines3/pull/979
104-
# (and then switch to PyPi once it makes it to release)
105-
"stable-baselines3@git+https://github.com/DLR-RM/stable-baselines3.git@"
106-
"ff4bc96afa6336c5f4d0ebd8a40aec398fe648ba",
107-
# TODO(nora) switch back to PyPi once 0.8.3 makes it to release:
108-
"sacred@git+https://github.com/IDSIA/sacred.git@0.8.3",
103+
"stable-baselines3>=1.5.0",
104+
# TODO(adam) switch to upstream release if they make it
105+
# See https://github.com/IDSIA/sacred/issues/879
106+
"chai-sacred>=0.8.3",
109107
"tensorboard>=1.14",
110108
],
111109
tests_require=TESTS_REQUIRE,

src/imitation/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
"""imitation: implementations of imitation and reward learning algorithms."""
22

3-
__version__ = "0.2.0"
3+
from importlib import metadata
4+
5+
try:
6+
__version__ = metadata.version("imitation")
7+
except metadata.PackageNotFoundError: # pragma: no cover
8+
# package is not installed
9+
pass

tests/algorithms/test_preference_comparisons.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for the preference comparisons reward learning implementation."""
22

3+
import os
34
import re
45
from typing import Sequence
56

@@ -176,11 +177,13 @@ def test_trainer_no_crash(
176177
custom_logger=custom_logger,
177178
query_schedule=schedule,
178179
)
179-
result = main_trainer.train(100, 10)
180-
# We don't expect good performance after training for 10 (!) timesteps,
181-
# but check stats are within the bounds they should lie in.
182-
assert result["reward_loss"] > 0.0
183-
assert 0.0 < result["reward_accuracy"] <= 1.0
180+
# TODO(GH494): remove this skip once SB3 fixed
181+
if os.name != "nt":
182+
result = main_trainer.train(100, 10)
183+
# We don't expect good performance after training for 10 (!) timesteps,
184+
# but check stats are within the bounds they should lie in.
185+
assert result["reward_loss"] > 0.0
186+
assert 0.0 < result["reward_accuracy"] <= 1.0
184187

185188

186189
def test_discount_rate_no_crash(agent_trainer, reward_net, fragmenter, custom_logger):
@@ -200,7 +203,9 @@ def test_discount_rate_no_crash(agent_trainer, reward_net, fragmenter, custom_lo
200203
reward_trainer=reward_trainer,
201204
custom_logger=custom_logger,
202205
)
203-
main_trainer.train(100, 10)
206+
# TODO(GH494): remove this skip once SB3 fixed
207+
if os.name != "nt":
208+
main_trainer.train(100, 10)
204209

205210

206211
def test_synthetic_gatherer_deterministic(agent_trainer, fragmenter):
@@ -316,4 +321,6 @@ def test_exploration_no_crash(agent, reward_net, fragmenter, custom_logger):
316321
fragmenter=fragmenter,
317322
custom_logger=custom_logger,
318323
)
319-
main_trainer.train(100, 10)
324+
# TODO(GH494): remove this skip once SB3 fixed
325+
if os.name != "nt":
326+
main_trainer.train(100, 10)

0 commit comments

Comments
 (0)