From e95868920dde08e42866edf1f4139fae063e8b73 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Fri, 15 Sep 2023 14:39:48 -0700 Subject: [PATCH 1/2] Add build config --- .github/workflows/build.yaml | 35 ++++++++++++++ .github/workflows/release.yaml | 55 ++++++++++++++++++++++ .gitignore | 85 ++++++++++++++++++++++++++++++++++ metron_talker/metron.py | 2 +- setup.cfg | 72 ++++++++++++++++++++++++++++ 5 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .gitignore diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..8ccb306 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,35 @@ +name: CI + +on: + pull_request: + push: + branches: + - '**' + +jobs: + build-and-publish: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python_version: ['3.9'] + os: [ubuntu-latest] + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Python ${{ matrix.python_version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python_version }} + + + - name: Install build dependencies + run: | + python -m pip install --upgrade --upgrade-strategy eager -r requirements-dev.txt + + - name: Build and install wheel + run: | + tox run -m build + python -m pip install dist/*.whl diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..d3f8432 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,55 @@ +name: CI + +on: + pull_request: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+*" + +jobs: + build-and-publish: + runs-on: ubuntu-latest + # Specifying a GitHub environment is optional, but strongly encouraged + environment: release + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + + - name: Install build dependencies + run: | + python -m pip install --upgrade --upgrade-strategy eager -r requirements-dev.txt + + - name: Build and install wheel + run: | + tox run -m build + python -m pip install dist/*.whl + + - name: "Publish distribution 📦 to PyPI" + if: startsWith(github.ref, 'refs/tags/') + uses: pypa/gh-action-pypi-publish@release/v1 + + - name: Get release name + if: startsWith(github.ref, 'refs/tags/') + shell: bash + run: | + git fetch --depth=1 origin +refs/tags/*:refs/tags/* # github is dumb + echo "release_name=$(git tag -l --format "%(refname:strip=2): %(contents:lines=1)" ${{ github.ref_name }})" >> $GITHUB_ENV + + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + name: "${{ env.release_name }}" + draft: false + files: | + dist/*.whl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d6bed2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,85 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion + +*.iml + +## Directory-based project format: +.idea/ + +### Other editors +.*.swp +nbproject/ +.vscode + +*.exe +*.zip + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# 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 + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# for testing +temp/ +tmp/ diff --git a/metron_talker/metron.py b/metron_talker/metron.py index 2e782ee..d44e7ec 100644 --- a/metron_talker/metron.py +++ b/metron_talker/metron.py @@ -52,7 +52,7 @@ class MetronSeriesType(Enum): class MetronEncoder(json.JSONEncoder): - def default(self, obj): + def default(self, obj: Any) -> Any: if isinstance(obj, (datetime, date)): return obj.isoformat() if isinstance(obj, decimal.Decimal): diff --git a/setup.cfg b/setup.cfg index ecfb580..8f82c15 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,3 +61,75 @@ dev = setuptools>=42 setuptools-scm[toml]>=3.4 wheel + +[tox:tox] +envlist = py3.9 + +[testenv] +deps = -rrequirements-dev.txt +commands = + coverage erase + coverage run -m pytest {posargs:tests} + coverage report + +[testenv:wheel] +description = Generate wheel and tar.gz +labels = + release + build +skip_install = true +deps = + build +commands_pre = + -python -c 'import shutil,pathlib; \ + shutil.rmtree("./build/", ignore_errors=True); \ + shutil.rmtree("./dist/", ignore_errors=True)' +commands = + python -m build + +[testenv:pypi-upload] +description = Upload wheel to PyPi +platform = Linux +labels = + release +skip_install = true +depends = wheel +deps = + twine +passenv = + TWINE_* +setenv = + TWINE_NON_INTERACTIVE=true +commands = + python -m twine upload dist/*.whl dist/*.tar.gz + +[pep8] +ignore = E265,E501 +max_line_length = 120 + +[flake8] +extend-ignore = E501, A003 +max_line_length = 120 +per-file-ignores = + *_test.py: LN001 + +[coverage:run] +plugins = covdefaults + +[coverage:report] +fail_under = 95 + +[mypy] +check_untyped_defs = true +disallow_any_generics = true +disallow_incomplete_defs = true +disallow_untyped_defs = true +no_implicit_optional = true +warn_redundant_casts = true +warn_unused_ignores = true + +[mypy-testing.*] +disallow_untyped_defs = false + +[mypy-tests.*] +disallow_untyped_defs = false From 9b5a8d73da92c17b3820793c847db098e967fda3 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Fri, 15 Sep 2023 15:01:57 -0700 Subject: [PATCH 2/2] Update dev requirements --- requirements-dev.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index d4a5c16..178c880 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,5 @@ black>=22 +build flake8==4.* flake8-black flake8-encodings @@ -8,4 +9,5 @@ isort>=5.10 pytest==7.* setuptools>=42 setuptools_scm[toml]>=3.4 +tox wheel