From dff7bee0a2ee9d5a41fc2d285f7cf12d1432fd83 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Tue, 26 Oct 2021 20:33:17 +0200 Subject: [PATCH 1/5] Add github actions Fixes: #39 --- .github/workflows/run-test.yaml | 72 +++++++++++++++++++++++++++++++++ .gitignore | 1 + mimeparse.py | 11 ++--- setup.py | 3 +- tox.ini | 30 ++------------ 5 files changed, 80 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/run-test.yaml diff --git a/.github/workflows/run-test.yaml b/.github/workflows/run-test.yaml new file mode 100644 index 0000000..a86fd17 --- /dev/null +++ b/.github/workflows/run-test.yaml @@ -0,0 +1,72 @@ +name: Run tests + +on: + push: + pull_request: + + +jobs: + run-test: + name: test-${{ matrix.python-version }} + runs-on: "ubuntu-latest" + strategy: + matrix: + python-version: + - "3.6" + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "pypy-3.7" + + fail-fast: false + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Set up python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + architecture: ${{ matrix.architecture }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade tox setuptools + pip list + + - name: Run tests + run: | + tox + + run-test: + name: lint + runs-on: "ubuntu-latest" + strategy: + matrix: + python-version: + - "3.10" + + fail-fast: false + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Set up python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + architecture: ${{ matrix.architecture }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade tox setuptools + pip list + + - name: Run tests + run: | + tox -e flake8 diff --git a/.gitignore b/.gitignore index eee4038..38186f5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist/ build/ .venv/ +.vscode diff --git a/mimeparse.py b/mimeparse.py index 0218553..0de6d57 100644 --- a/mimeparse.py +++ b/mimeparse.py @@ -85,14 +85,9 @@ def quality_and_fitness_parsed(mime_type, parsed_ranges): for (type, subtype, params) in parsed_ranges: # check if the type and the subtype match - type_match = ( - type in (target_type, '*') or - target_type == '*' - ) - subtype_match = ( - subtype in (target_subtype, '*') or - target_subtype == '*' - ) + type_match = type in (target_type, '*') or target_type == '*' + + subtype_match = subtype in (target_subtype, '*') or target_subtype == '*' # if they do, assess the "fitness" of this mime_type if type_match and subtype_match: diff --git a/setup.py b/setup.py index 5c34b21..3f10ad3 100755 --- a/setup.py +++ b/setup.py @@ -37,8 +37,7 @@ def read(fname): license="MIT", author_email="dbtsai@dbtsai.com", url="https://github.com/dbtsai/python-mimeparse", - download_url=("https://github.com/dbtsai/python-mimeparse/tarball/" + - version), + download_url=("https://github.com/dbtsai/python-mimeparse/tarball/" + version), keywords=["mime-type"], python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', classifiers=[ diff --git a/tox.ini b/tox.ini index 97c4794..ad40452 100644 --- a/tox.ini +++ b/tox.ini @@ -1,33 +1,9 @@ [tox] -envlist = py37,py36,py35,py34,py32,py27,pypy,pypy3,flake8 +envlist = py [testenv] -commands = python --version - ./mimeparse_test.py - -[testenv:py37] -basepython = python3.7 - -[testenv:py36] -basepython = python3.6 - -[testenv:py35] -basepython = python3.5 - -[testenv:py34] -basepython = python3.4 - -[testenv:py32] -basepython = python3.2 - -[testenv:py27] -basepython = python2.7 - -[testenv:pypy] -basepython = pypy - -[testenv:pypy3] -basepython = pypy3 +deps = pytest +commands = pytest [testenv:flake8] deps = flake8 From 186b3b9a0a933a05c15194d520e0e7a1a6729442 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Tue, 26 Oct 2021 20:34:54 +0200 Subject: [PATCH 2/5] Fix workflow --- .github/workflows/run-test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-test.yaml b/.github/workflows/run-test.yaml index a86fd17..7328325 100644 --- a/.github/workflows/run-test.yaml +++ b/.github/workflows/run-test.yaml @@ -41,7 +41,7 @@ jobs: run: | tox - run-test: + run-lint: name: lint runs-on: "ubuntu-latest" strategy: @@ -67,6 +67,6 @@ jobs: pip install --upgrade tox setuptools pip list - - name: Run tests + - name: Run lint run: | tox -e flake8 From fc26ce79c7538907dbf199689db8e6762944ad24 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Tue, 26 Oct 2021 20:58:42 +0200 Subject: [PATCH 3/5] Move setup information to setup.cfg --- setup.cfg | 41 +++++++++++++++++++++++++++++++++++++ setup.py | 61 +------------------------------------------------------ 2 files changed, 42 insertions(+), 60 deletions(-) diff --git a/setup.cfg b/setup.cfg index 2a9acf1..60afdbe 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,43 @@ +[metadata] +name = python-mimeparse +version = attr: mimeparse.__version__ +description = A module provides basic functions for parsing mime-type names and matching them against a list of media-ranges. +long_description = file: README.rst +long_description_content_type = text/x-rst +url = https://github.com/falconry/python-mimeparse +author = DB Tsai +author_email = dbtsai@dbtsai.com +maintainer = Falcon team +maintainer_email = mail@kgriffs.com +license = MIT +license_file = LICENSE +classifiers = + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: Implementation :: CPython + Programming Language :: Python :: Implementation :: PyPy + License :: OSI Approved :: MIT License + Operating System :: OS Independent + Development Status :: 5 - Production/Stable + Intended Audience :: Developers + Topic :: Internet :: WWW/HTTP + Topic :: Software Development :: Libraries :: Python Modules +keywords = + mime-type +project_urls = + Issue Tracker=https://github.com/falconry/python-mimeparse + +[options] +python_requires = >=3.6 +py_modules = mimeparse +install_requires = +tests_require = + pytest + [bdist_wheel] universal = 1 diff --git a/setup.py b/setup.py index 3f10ad3..6068493 100755 --- a/setup.py +++ b/setup.py @@ -1,62 +1,3 @@ -#!/usr/bin/env python - -import codecs -import os -import re - from setuptools import setup - -def get_version(filename): - """ - Return package version as listed in `__version__` in 'filename'. - """ - with open(filename) as fp: - contents = fp.read() - return re.search("__version__ = ['\"]([^'\"]+)['\"]", contents).group(1) - - -version = get_version('mimeparse.py') -if not version: - raise RuntimeError('Cannot find version information') - - -def read(fname): - path = os.path.join(os.path.dirname(__file__), fname) - with codecs.open(path, encoding='utf-8') as fp: - return fp.read() - - -setup( - name="python-mimeparse", - py_modules=["mimeparse"], - version=version, - description=("A module provides basic functions for parsing mime-type " - "names and matching them against a list of media-ranges."), - author="DB Tsai", - license="MIT", - author_email="dbtsai@dbtsai.com", - url="https://github.com/dbtsai/python-mimeparse", - download_url=("https://github.com/dbtsai/python-mimeparse/tarball/" + version), - keywords=["mime-type"], - python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', - classifiers=[ - "Programming Language :: Python", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Software Development :: Libraries :: Python Modules", - ], - long_description=read('README.rst') -) +setup() From 29ea35d0f4c415a8a390a28fa41c5fc3bc64df0a Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Tue, 26 Oct 2021 21:09:34 +0200 Subject: [PATCH 4/5] Use pep517 to build --- MANIFEST.in | 2 +- pyproject.toml | 6 ++++++ setup.cfg | 3 --- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 pyproject.toml diff --git a/MANIFEST.in b/MANIFEST.in index d071265..3bdb9ab 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include README.rst LICENSE mimeparse_test.py testdata.json +include README.rst LICENSE mimeparse_test.py testdata.json pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c4ef621 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] + build-backend = "setuptools.build_meta" + requires = [ + "setuptools>=47", + "wheel>=0.34", + ] diff --git a/setup.cfg b/setup.cfg index 60afdbe..dc7d900 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,6 +38,3 @@ py_modules = mimeparse install_requires = tests_require = pytest - -[bdist_wheel] -universal = 1 From f38f329abcc7a4cd1ab295c7d6902e7719bf6310 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Tue, 2 Nov 2021 21:34:09 +0100 Subject: [PATCH 5/5] chore: review feedback --- .github/workflows/run-test.yaml | 1 + setup.cfg | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-test.yaml b/.github/workflows/run-test.yaml index 519a444..884200a 100644 --- a/.github/workflows/run-test.yaml +++ b/.github/workflows/run-test.yaml @@ -12,6 +12,7 @@ jobs: strategy: matrix: python-version: + - "3.5" - "3.6" - "3.7" - "3.8" diff --git a/setup.cfg b/setup.cfg index dc7d900..0a232c5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,7 +33,7 @@ project_urls = Issue Tracker=https://github.com/falconry/python-mimeparse [options] -python_requires = >=3.6 +python_requires = >=3.5 py_modules = mimeparse install_requires = tests_require =