Skip to content

Commit

Permalink
Auto-create py.typed File(s) (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans authored Apr 10, 2023
1 parent 25e30aa commit d3989e3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: WIPACrepo/wipac-dev-flake8-action@v1
- uses: actions/setup-python@v4
- uses: WIPACrepo/wipac-dev-flake8-action@v1.0

mypy:
runs-on: ubuntu-latest
Expand All @@ -18,7 +18,7 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: WIPACrepo/wipac-dev-mypy-action@v1.1
- uses: WIPACrepo/wipac-dev-mypy-action@v1.2

setup_builder:
runs-on: ubuntu-latest
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# WIPACrepo/wipac-dev-py-setup-action
GitHub Action Package for Automating Python-Package Setup
GitHub Action Package for Automating Python-Package Setup & Maintenance



## Overview
This GitHub Action prepares a repository to be GitHub-released and PyPI-published by the [Python Semantic Release GitHub Action](https://python-semantic-release.readthedocs.io/en/latest/). All that a user needs to do is define a few attributes in `setup.cfg` (see [*Main Configuration Modes*](#main-configuration-modes)).

### Details
`setup.cfg` sections needed for publishing a package to PyPI are auto-generated, hyper-linked badges are added to the `README.md`, and the root directory's `requirements.txt` is overwritten/updated (by way of [pip-compile](https://github.com/jazzband/pip-tools)). Commits are git-pushed by the "github-actions" bot (github-actions@github.com) by default, or your chosen actor configured by inputs (`git_committer_name` & `git_committer_email`).
- `setup.cfg` sections needed for publishing a package to PyPI are auto-generated,
- hyper-linked badges are added to the `README.md`,
- the root directory's `requirements.txt` is overwritten/updated (by way of [pip-compile](https://github.com/jazzband/pip-tools)) along with dedicated `requirements-EXTRA.txt` files for each package "extra", and
- `py.typed` files are created as needed.
Commits are git-pushed by the "github-actions" bot (github-actions@github.com) by default, or your chosen actor configured by inputs (`git_committer_name` & `git_committer_email`).

#### GitHub Action Syntax
```
Expand Down
27 changes: 27 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ runs:
git commit -m "<bot> update README.md" || true
shell: bash

- name: Add py.typed file(s) (and commit)
run: |
python -c '
import os
from pathlib import Path
line_to_parse = ""
with open("setup.cfg") as f:
for line in f.readlines():
if line.startswith("version_variable = "):
line_to_parse = line.strip() # remove newline
if not line_to_parse:
raise Exception("Cannot addd py.typed files (missing version_variable in setup.cfg)")
for version_path in line_to_parse.removeprefix("version_variable = ").split(","):
print(version_path)
dpath = version_path.removesuffix("__init__.py:__version__")
print(dpath)
fpath = Path(dpath) / "py.typed"
print(fpath)
fpath.touch() # create if needed!
'
git add . # won't error if nothing to add
git commit -m "<bot> add py.typed file(s)" || true
shell: bash

- name: Build requirements.txt (and commit)
run: |
pip3 install pip-tools
Expand Down

0 comments on commit d3989e3

Please # to comment.