Skip to content

Support all IANA mime types #82

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ jobs:
with:
python-version: 3.9

- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: "1.7.1"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install --dev
poetry install

- name: Run linters
run: |
pipenv run mypy ./src
make lint

- name: Run tests
run: |
pipenv run python setup.py install
pipenv run pytest
make test
12 changes: 5 additions & 7 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ jobs:
- name: Checkout Git
uses: actions/checkout@v2

- name: Install Python 3
uses: actions/setup-python@v2
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
python-version: 3.9
poetry-version: "1.7.1"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install --dev
poetry install

- name: Build package
run: |
pipenv run python -m build --no-isolation
make build

- name: Publish package
if: startsWith(github.ref, 'refs/tags')
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ cython_debug/
# VS Code
.history
.vscode

#pyenv
.python-version
34 changes: 19 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
.DEFAULT_GOAL := help
.PHONY: help build test

PYPI_TOKEN := $(shell echo ${PYPI_TOKEN})
PYPI_TEST_TOKEN := $(shell echo ${PYPI_TEST_TOKEN})


build: ## Build an application
@pipenv run python -m build --no-isolation
@poetry build

configure_pypi_publishing: ## Configure publishing to PyPI
@if [ -z "${PYPI_TOKEN}" ] ; then echo "you need to export PYPI_TOKEN before running this command" ; false ; fi
@if [ -z "${PYPI_TOKEN}" ] ; then echo "you need to export PYPI_TEST_TOKEN before running this command" ; false ; fi
@poetry config repositories.test-pypi https://test.pypi.org/legacy/
@poetry config pypi-token.test-pypi $(PYPI_TEST_TOKEN)
@poetry config pypi-token.pypi $(PYPI_TOKEN)

publish-test: ## Upload package to test PyPI
@pipenv run twine upload --repository testpypi dist/*
@poetry publish -r test-pypi

publish: build ## Upload package to PyPI
@pipenv run twine upload dist/*
@poetry publish
@make clean

install: build ## Install application to Pip environment
@pipenv run python -m pip install

install-dev: ## Install application to Pip development environment
@pipenv run python -m pip install -e
@make clean
install: build ## Install application to Poetry environment
@poetry install

clean: ## Remove build files
@rm -Rf build/ dist/ *.egg-info .pytest_cache/ .mypy_cache/ .pytype/ .eggs/ src/*.egg-info
@echo "Temporary files were clear"

test: ## Run code tests
@pipenv run python -m pytest -q

sync: ## Sync with Pipfile packages list
@pipenv sync
@poetry run pytest -vv

lint: ## Run code linters
@echo "Run code linters..."
@pipenv run mypy ./src
@poetry run mypy ./src

help: ## Show this message
@echo "Application management"
@echo
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
18 changes: 0 additions & 18 deletions Pipfile

This file was deleted.

918 changes: 0 additions & 918 deletions Pipfile.lock

This file was deleted.

9 changes: 9 additions & 0 deletions build_mime_types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# build-mime-types

Builds a class file for ContentType enum from the IANA mime types list.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the approach with code-generation based on the standards, but since there is no automation to get the latest version of those csv files - it makes the module useful just for one-time execution. I think there is no need to include it into the repository since the process of extending will be identical (update csv of the actual python enum file)

Copy link
Author

@dkoston dkoston Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would the code live if it doesn't live in this repo?

since the process of extending will be identical (update csv of the actual python enum file)

Process:

  1. Download CSV files
  2. Run build_mime_types.py

If you delete build_mime_types.py you'll have to add thousands of enum lines by hand or do a manual diff. Maybe I'm missing something?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this approach, but for now it's semi-automated. I meant that if we go with code generation, then we can exclude CSV files from the git and make them downloadable directly in the script to have all the latest versions w/o manual actions

Copy link
Owner

@manchenkoff manchenkoff Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case your suggestion with enum map for existing values would work fine as well, so it is up to you: update it now or leave PR as is and wait till the major version update w/o BC (but I have no time estimate on that for now)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the maps. There are some open api specific content-types not listed in IANA that I added / generated and some that this library names specifically so I added logic for those to keep everything backwards compatible.


Contents:


- *.csv - Lists of media-types [from IANA](https://www.iana.org/assignments/media-types/media-types.xhtml)
- [build_mime_types.py](build_mime_types.py) - Script to build class file (run automatically by poetry build)
Loading