diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3faa999..5bccfa2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,6 +89,7 @@ jobs: name: release url: https://pypi.org/p/plain-abc permissions: + contents: write id-token: write steps: - name: Download all the dists @@ -98,3 +99,18 @@ jobs: path: dist/ - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + '${{ github.ref_name }}' + --repo '${{ github.repository }}' + --notes "" + - name: Upload to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' diff --git a/.gitignore b/.gitignore index bb7cf06..e41adb4 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,6 @@ dmypy.json # IDE .vscode + +# pytest-readme +tests/test_readme.py diff --git a/LICENSE b/LICENSE index 9b4c391..f1d99ff 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Chielo +Copyright (c) 2023 Chielo Newctle Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 4efbc55..0f87066 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Another `ABC` implementation without `metaclass`. -It is a little bit annoying to have metaclass conflict, +It is a little bit annoying to have `metaclass` conflict, especially when trying to use ABC along with other libraries. `plain-abc` provides a simple `ABC` implementation without `metaclass`. @@ -94,10 +94,10 @@ class Foo(IEnum, Enum): assert Foo.foo.value == 'foo' ``` -## To solve metaclass conflict without `plain-abc` +## To solve `metaclass` conflict without `plain-abc` -Here is an example of metaclass conflict -and how to mix ABCMeta and other metaclasses. +Here is an example of `metaclass` conflict +and how to mix `ABCMeta` with other `metaclass`es. ```python from abc import ABC, ABCMeta, abstractmethod diff --git a/pyproject.toml b/pyproject.toml index f28ed05..c9c9493 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "plain-abc" -version = "0.0.4" -authors = [{ name = "Chielo Newctle", email = "ChieloNewctle@Yandex.com" }] +version = "0.1.0" +authors = [{ name = "Chielo Newctle", email = "ChieloNewctle@gmail.com" }] description = "An ABC implementation without metaclass" readme = "README.md" requires-python = ">=3.8" diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..01ca78f --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,53 @@ +def parse_from_readme(): + """ + Adapted from https://github.com/boxed/pytest-readme + + Copyright (c) 2020, Anders Hovmöller + + Under the BSD 3-Clause "New" or "Revised" License. + """ + with open( + "tests/test_readme.py", + "w", + encoding="utf8", + ) as out, open("README.md", encoding="utf8") as readme: + output, mode = [], None + + for i, line in enumerate(readme.readlines()): + output.append("\n") + + if mode is None and line.strip() == "```python": + mode = "first_line" + output[i] = "def test_line_%s():\n" % i + continue + + if line.strip() == "```": + if mode == "doctest": + output[i] = ' """\n' + mode = None + continue + + if mode == "first_line": + if line.strip() == "": + mode = None + output[i - 1] = "\n" + continue + + if line.strip().startswith(">>>"): + mode = "doctest" + output[i - 2] = ( + output[i - 1][:-1] + " " + output[i - 2] + ) # move the def line one line up + output[i - 1] = ' """\n' + else: + mode = "test" + + if mode in ("doctest", "test"): + output[i] = " " + line + else: + output[i] = "# %s" % line + + out.writelines(output) + + +parse_from_readme()