Skip to content

Commit

Permalink
Merge pull request #334 from kurtmckee/fix-ci
Browse files Browse the repository at this point in the history
Fix CI
  • Loading branch information
kurtmckee committed Feb 19, 2023
2 parents 0a58d5c + 617d8f4 commit 3bd7edf
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 105 deletions.
173 changes: 84 additions & 89 deletions .github/workflows/feedparser.yml
Original file line number Diff line number Diff line change
@@ -1,116 +1,111 @@
name: "feedparser"
name: "CI"

on: [push, pull_request]
on:
- "push"
- "pull_request"

jobs:
code:
name: "Python ${{ matrix.python-version }} on ${{ matrix.os}}"

runs-on: "${{ matrix.os }}"
test:
name: "Test on ${{ matrix.config.os-name }}"
runs-on: "${{ matrix.config.runner }}"

strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "pypy-3.9"
config:
- os-name: "Linux"
runner: "ubuntu-latest"
test-label: "ci-test-linux"
- os-name: "macOS"
runner: "macos-latest"
test-label: "ci-test-macos"
- os-name: "Windows"
runner: "windows-latest"
test-label: "ci-test-windows"
fail-fast: false

steps:
- name: Checkout the repo
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: "Checkout the repo"
uses: "actions/checkout@v3"

- name: Cache virtual environment
id: cache
uses: actions/cache@v3
- name: "Setup Python"
id: "setup-python"
uses: "actions/setup-python@v4"
with:
path: venv
key: "venv-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}"

- name: Create virtual environment
if: |
(startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS'))
&& steps.cache.outputs.cache-hit != 'true'
run: |
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
python -m pip install poetry
poetry update
- name: Create virtual environment
if: |
startsWith(runner.os, 'Windows')
&& steps.cache.outputs.cache-hit != 'true'
run: |
python -m venv venv
.\venv\scripts\activate.ps1
python -m pip install --upgrade pip
python -m pip install poetry
poetry update
- name: Run tox (*nix)
if: ${{ startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS') }}
python-version: |
3.7
3.8
3.9
3.10
3.11
pypy-3.9
- name: "Determine month number"
shell: "bash"
run: |
source venv/bin/activate
tox -e py,py-chardet
date +'month-number=%m' >> $GITHUB_ENV
date +'%m' > month-number.txt
- name: Run tox (Windows)
if: ${{ startsWith(runner.os, 'Windows') }}
run: |
.\venv\scripts\activate.ps1
tox -e py,py-chardet
- name: "Determine venv path"
shell: "bash"
run: "echo 'venv-path=${{ matrix.config.os-name == 'Windows' && '.venv/Scripts' || '.venv/bin' }}' >> $GITHUB_ENV"

- name: "Restore cache"
id: "restore-cache"
uses: "actions/cache@v3"
with:
path: |
.tox/
.venv/
key: "test-${{ matrix.config.runner }}-${{ hashFiles('pyproject.toml', 'tox.ini', 'month-number.txt') }}"

- name: Run tox (mypy)
if: ${{ startsWith(runner.os, 'Linux') && matrix.python-version == '3.10' }}
- name: "Create virtual environment"
if: "steps.restore-cache.outputs.cache-hit == false"
run: |
source venv/bin/activate
tox -e mypy
python -m venv .venv
${{ env.venv-path }}/python -m pip install --upgrade pip setuptools wheel
${{ env.venv-path }}/python -m pip install tox
docs:
name: "Build documentation"
- name: "Run tests"
run: "${{ env.venv-path }}/tox run -m ${{ matrix.config.test-label }}"

runs-on: ubuntu-latest
lint:
name: "Lint"
runs-on: "ubuntu-latest"

steps:
- name: Checkout the repo
uses: actions/checkout@v3
- name: "Checkout the repo"
uses: "actions/checkout@v3"

- name: Set up Python
uses: actions/setup-python@v3
- name: "Setup Python"
id: "setup-python"
uses: "actions/setup-python@v4"
with:
python-version: "3.10"
python-version: "3.11"

- name: Cache virtual environment
id: cache
uses: actions/cache@v3
- name: "Determine month number"
shell: "bash"
run: "date +'%m' > month-number.txt"

- name: "Restore cache"
id: "restore-cache"
uses: "actions/cache@v3"
with:
path: venv
key: "venv-${{ hashFiles('pyproject.toml') }}"
path: |
.mypy_cache/
.tox/
.venv/
key: "lint-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('month-number.txt', 'pyproject.toml', 'tox.ini') }}"


- name: Create virtual environment
if: steps.cache.outputs.cache-hit != 'true'
- name: "Create virtual environment"
if: "steps.restore-cache.outputs.cache-hit == false"
run: |
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
python -m pip install poetry
poetry update
python -m venv .venv
.venv/bin/python -m pip install --upgrade pip setuptools wheel
.venv/bin/python -m pip install tox
- name: Test building the documentation
run: |
source venv/bin/activate
tox -e docs
- name: "Build the documentation"
run: ".venv/bin/tox run -e docs"

- name: "Check type annotations"
run: ".venv/bin/tox run -e mypy"
5 changes: 5 additions & 0 deletions changelog.d/20230219_163510_kurtmckee_fix_ci.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Stewardship
-----------

* Update CI to minimize total run time.
(The total run time dropped from ~37 minutes to ~8 minutes with cache hits.)
28 changes: 14 additions & 14 deletions feedparser/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import urllib.error
import urllib.parse
import xml.sax
from typing import IO, Dict, List, Union
from typing import Optional, IO, Dict, List, Union

from . import http
from .datetimes import _parse_date, registerDateHandler
Expand Down Expand Up @@ -194,16 +194,16 @@ class StrictFeedParser(StrictXMLParser, XMLParserMixin, xml.sax.handler.ContentH

def parse(
url_file_stream_or_string,
etag: str = None,
modified: Union[str, datetime.datetime, time.struct_time] = None,
agent: str = None,
referrer: str = None,
handlers: List = None,
request_headers: Dict[str, str] = None,
response_headers: Dict[str, str] = None,
resolve_relative_uris: bool = None,
sanitize_html: bool = None,
optimistic_encoding_detection: bool = None,
etag: Optional[str] = None,
modified: Optional[Union[str, datetime.datetime, time.struct_time]] = None,
agent: Optional[str] = None,
referrer: Optional[str] = None,
handlers: Optional[List] = None,
request_headers: Optional[Dict[str, str]] = None,
response_headers: Optional[Dict[str, str]] = None,
resolve_relative_uris: Optional[bool] = None,
sanitize_html: Optional[bool] = None,
optimistic_encoding_detection: Optional[bool] = None,
) -> FeedParserDict:
"""Parse a feed from a URL, file, stream, or string.
Expand Down Expand Up @@ -319,9 +319,9 @@ def _parse_file_inplace(
file: Union[IO[bytes], IO[str]],
result: dict,
*,
resolve_relative_uris: bool = None,
sanitize_html: bool = None,
optimistic_encoding_detection: bool = None,
resolve_relative_uris: Optional[bool] = None,
sanitize_html: Optional[bool] = None,
optimistic_encoding_detection: Optional[bool] = None,
) -> None:
# Avoid a cyclic import.
import feedparser
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ profile = "black"


[tool.mypy]
packages = "feedparser"
show_error_codes = true
sqlite_cache = true
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ envlist =
py{311, 310, 39, 38, 37, py3}{-chardet, },
docs,
mypy
labels =
ci-test-linux = py{311, 310, 39, 38, 37, py3}-chardet
ci-test-macos = py{311, 37}-chardet
ci-test-windows = py{311, 37}-chardet
skip_missing_interpreters = True
isolated_build = True
min_version = 4.3.5
Expand All @@ -26,9 +30,8 @@ commands =


[testenv:mypy]
skip_install = True
deps =
mypy
types-chardet
commands =
mypy feedparser
mypy

0 comments on commit 3bd7edf

Please sign in to comment.