Skip to content

Commit

Permalink
Merge pull request #797 from axnsan12/prepublish
Browse files Browse the repository at this point in the history
Add prepublish compatibility checks, a composite installation action and explicitly set tox targets
  • Loading branch information
JoelLefkowitz authored Jul 18, 2022
2 parents 124f2cd + a000102 commit f4bf7ba
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 38 deletions.
29 changes: 29 additions & 0 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Install
description: Install dependencies

inputs:
python-version:
description: Python version for installing dependencies
required: true

runs:
using: composite
steps:
- name: Checkout the source code
uses: actions/checkout@v2

- name: Set the python version
uses: actions/setup-python@v3
with:
python-version: ${{ inputs.python-version }}

- name: Set up pip package caching
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: ${{ runner.os }}-pip-

- name: Install dependencies
shell: bash
run: pip install -r requirements/ci.txt
16 changes: 10 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish

on:
push:
tags:
tags:
- "*.*.*"

jobs:
Expand All @@ -13,17 +13,21 @@ jobs:
- name: Checkout the source code
uses: actions/checkout@v2

- name: Set the python version
uses: actions/setup-python@v2

# This is the version of python used to package the code. The unit
# tests will have run against python 3.6, 3.7 etc ensuring
# tests will have run against python 3.6, 3.7 etc ensuring
# compatibility with those runtimes.
# https://github.com/axnsan12/drf-yasg/pull/741#discussion_r713297594
- name: Set the python version
uses: actions/setup-python@v3
with:
python-version: 3.8

- name: Install dependencies
uses: ./.github/actions/install
with:
python-version: 3.8

- name: Install pip dependencies
- name: Install builders for publishing
run: pip install -r requirements/publish.txt

- name: Build the distributions
Expand Down
28 changes: 16 additions & 12 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@ jobs:
python: [3.6, 3.7, 3.8, 3.9]

steps:
- name: Set up pip package caching
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: ${{ runner.os }}-pip-

- name: Checkout the source code
uses: actions/checkout@v2

- name: Set the python version
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}

- name: Install dependencies
uses: ./.github/actions/install
with:
python-version: ${{ matrix.python }}

- name: Install pip dependencies
run: pip install -r requirements/ci.txt
- name: Run tests
env:
PYTHON_VERSION: ${{ matrix.python }}
run: tox -e $(tox -l | grep py${PYTHON_VERSION//.} | paste -sd "," -)

- name: Run unit tests
run: tox
- name: Check for incompatibilities with publishing to PyPi
if: ${{ matrix.python == 3.8 }}
run: |
pip install -r requirements/publish.txt
python setup.py sdist
twine check dist/*
43 changes: 23 additions & 20 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -360,26 +360,29 @@ provided out of the box - if you have ``djangorestframework-recursive`` installe
:trim:

drf-extra-fields
===============================
Integration with `drf-extra-fields <https://github.com/Hipo/drf-extra-fields>`_ has a problem with Base64 fields. The drf-yasg will generate Base64 file or image fields as Readonly and not required. Here is a workaround code for display the Base64 fields correctly.
=================

Integration with `drf-extra-fields <https://github.com/Hipo/drf-extra-fields>`_ has a problem with Base64 fields.
The drf-yasg will generate Base64 file or image fields as Readonly and not required. Here is a workaround code
for display the Base64 fields correctly.

.. code:: python
class PDFBase64FileField(Base64FileField):
ALLOWED_TYPES = ['pdf']

class Meta:
swagger_schema_fields = {
'type': 'string',
'title': 'File Content',
'description': 'Content of the file base64 encoded',
'read_only': False # <-- FIX
}

def get_file_extension(self, filename, decoded_file):
try:
PyPDF2.PdfFileReader(io.BytesIO(decoded_file))
except PyPDF2.utils.PdfReadError as e:
logger.warning(e)
else:
return 'pdf'
class PDFBase64FileField(Base64FileField):
ALLOWED_TYPES = ['pdf']
class Meta:
swagger_schema_fields = {
'type': 'string',
'title': 'File Content',
'description': 'Content of the file base64 encoded',
'read_only': False # <-- FIX
}
def get_file_extension(self, filename, decoded_file):
try:
PyPDF2.PdfFileReader(io.BytesIO(decoded_file))
except PyPDF2.utils.PdfReadError as e:
logger.warning(e)
else:
return 'pdf'
8 changes: 8 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Changelog
#########

**********
**1.21.2**
**********

*Release date: Jul 17, 2022*

**FIXED:** Fixed code block rst syntax in ``README.rst``

**********
**1.21.1**
**********
Expand Down
1 change: 1 addition & 0 deletions requirements/publish.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
setuptools-scm==7.0.5
twine==4.0.1
wheel>=0.37.0

0 comments on commit f4bf7ba

Please sign in to comment.