Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

⚙️ [actions] Implement actions #4

Merged
merged 4 commits into from
Jun 15, 2023
Merged
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
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pypi

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
10 changes: 10 additions & 0 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Ruff

on: [ push ]

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
23 changes: 23 additions & 0 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Tox

on: [ push ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
.idea
.venv

*.pyc
__pycache__

.tox
dist
build
mimetype_description.egg-info/
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
args: ['--maxkb=2300']
- id: check-xml
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.272
hooks:
- id: flake8
- id: ruff
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Christian Gutierrez
Copyright (c) 2023 Christian Gutierrez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 6 additions & 4 deletions mimetype_description/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Union

try:
import importlib.resources as pkg_resources
except ImportError:
Expand Down Expand Up @@ -29,13 +31,13 @@ def __init__(self):
ext = child.attrib['pattern'].replace('*.', '')
self._mime_types[ext] = _type

def get_description(self, mime_type: str, language: str) -> (str, None):
def get_description(self, mime_type: str, language: str) -> Union[str, None]:
try:
return self._descriptions[mime_type][language]
except KeyError:
return None

def get_mime_type(self, filename: str) -> (str, None):
def get_mime_type(self, filename: str) -> Union[str, None]:
try:
return self._mime_types.get(filename.split('.')[-1])
except IndexError:
Expand All @@ -45,11 +47,11 @@ def get_mime_type(self, filename: str) -> (str, None):
_instance = MimeTypeDescription()


def get_mime_type_description(mime_type: str, language: str = 'en') -> str:
def get_mime_type_description(mime_type: str, language: str = 'en') -> Union[str, None]:
return _instance.get_description(mime_type, language)


def guess_mime_type(filename: str) -> str:
def guess_mime_type(filename: str) -> Union[str, None]:
return _instance.get_mime_type(filename)


Expand Down
Loading