From a73682870b164fca712f394b05e3bd813dbf01a4 Mon Sep 17 00:00:00 2001 From: ramanaditya Date: Thu, 31 Dec 2020 21:32:24 +0530 Subject: [PATCH 1/9] Readme --- README.rst | 291 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 291 insertions(+) create mode 100644 README.rst diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..3062941 --- /dev/null +++ b/README.rst @@ -0,0 +1,291 @@ +############### +Email Service +############### + +Python package to quickly integrate different email services with your Application with just 3 lines of code. + +.. image:: https://img.shields.io/pypi/v/email-service.svg?color=2897A6 + :target: https://pypi.org/project/email-service/ + :alt: pypi +.. image:: https://img.shields.io/pypi/pyversions/email-service.svg + :target: https://pypi.org/project/email-service/ + :alt: python +.. image:: https://img.shields.io/badge/license-MIT-red.svg?style=flat-square + :target: https://github.com/ramanaditya/email-service + :alt: license +.. image:: https://img.shields.io/github/v/release/ramanaditya/email-service.svg + :target: https://github.com/ramanaditya/email-service/releases/ + :alt: GitHub Release +.. image:: https://img.shields.io/github/stars/ramanaditya/email-service.svg?logo=github + :target: https://github.com/ramanaditya/email-service/stargazers + :alt: GitHub stars +.. image:: https://img.shields.io/github/forks/ramanaditya/email-service.svg?logo=github&color=teal + :target: https://github.com/ramanaditya/email-service/network/members + :alt: GitHub forks + + +---- + + +Send Your email without caring about the backend code. + +:GitHub: `ramanaditya/email-service `__ +:PyPI: `pypi.org/project/email-service `__ + + +Usage +====== + + +Install it with pip +-------------------- +.. code-block:: console + + $ pip install email-service + + +Email Integration +-------------------- +``Save the`` **API_KEY** ``in the`` **.env** ``file as`` + + +.. code-block:: text + + SENDGRID_API_KEY=api_key + + +Import EmailHandler +-------------------- +.. code-block:: python + + >>> from email_service.email_handler import EmailHandler + + +Form the dictionary of data +------------------------------ +.. code-block:: python + + data = { + "from_email": "Name WithSpace ", # Required + "subject": "This is the test for the Individual email", # Required + "reply_to_addresses": "email1@gmail.com", + "html_body": "

Email Template for Individual email

", # Either of html_body or text_body is required + "text_body": "Email Template for Individual email", + "to_for_bulk": [{"name": "Name", "email": "email@gmail.com"},], # Required for Bulk Email + "receipients": { + "to": [{"name": "name1", "email": "email1@gmail.com"},], # Required + "cc": [{"name": "name2", "email": "email2@google.com"},], + "bcc": [{"name": "name3", "email": "email3@google.com"},], + }, + "attachments": [ + "file_path (pdf)", "calender invite (ics)", "image_path (png/jpg/jpeg)" + ] + } + + +Send the email +----------------- +.. code-block:: python + + >>> # For Individual Email + >>> send_email = EmailHandler() + + >>> # For Bulk Email + >>> send_email = EmailHandler(email_type="BULK") + + +Sendgrid Integration +---------------------- +.. code-block:: python + + >>> # Send it using sendgrid + >>> response = send_email.sendgrid(data) + + +Response +----------- +.. code-block:: yaml + + status_code: + 202: OK, + 400: Error + message: Error or Success Message + + +Development +============ + +.. image:: https://img.shields.io/github/languages/code-size/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/ + :alt: GitHub code size in bytes +.. image:: https://img.shields.io/github/repo-size/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/ + :alt: GitHub repo size +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square + :target: https://github.com/ramanaditya/email-service + :alt: black + + +Setup +------- + + +Clone the repository +^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ git clone https://github.com/ramanaditya/email-service + + +Create a virtual environment using virtualenv or venv. +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m venv venv + $ source venv/bin/activate + + +Upgrade pip +^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m pip install --upgrade pip + + +Install python packages +^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m pip install -r requirements.txt + + +Git Flow +---------- + + +Create new Branch from `develop` branch +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ git checkout -b develop origin/develop + $ git checkout -b feature_branch + + +Push the Code +^^^^^^^^^^^^^^^ +.. code-block:: console + + $ git add file_which_was_changed + $ git commit -m "Commit Message" + $ git push -u origin feature_branch + + +PyPI +----- + + +This is just for the reference and need not to be run, +If you want to run these scripts, please take a note of this + +* For testing, we maintain the test package at `testpypi `__ +* PyPI or Test PyPI, does not accept same file name, you can change the file name or version in the `./setup.py `__ +* You will be prompted to enter + - Either username and password + - or, username as "__token__" and password as token (can be generated from the pypi website) +* It will be uploaded to your pypi or testpypi account + + +Generating distribution archives +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ # Downloading latest version of setuptools + $ python -m pip install --user --upgrade setuptools wheel + + $ python setup.py sdist bdist_wheel + + +Uploading to Test PyPI +^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ # Upload to Test PyPI https://test.pypi.org/ + $ python -m twine upload --repository testpypi dist/* + + +Download the package from Test PyPI +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m pip install -i https://test.pypi.org/simple/ email-service + + +Check against the code +^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ # Edit the file inside /example to have some valid data + $ # export SENDGRID_API_KEY before running the script + $ python individual_email.py # For individual email + $ python bulk.py # For bulk email + + +Uploading to PyPI +^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ # Upload to PyPI https://pypi.org/ + $ python -m twine upload dist/* + + +Download the package from Test PyPI +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m pip install -i https://test.pypi.org/simple/ email-service + + +Issues +======== + + +.. image:: https://img.shields.io/github/issues/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/issues + :alt: GitHub issues +.. image:: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat&logo=git&logoColor=white + :target: https://github.com/ramanaditya/email-service/pulls + :alt: PRs Welcome +.. image:: https://img.shields.io/github/last-commit/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/ + :alt: GitHub last commit + +.. csv-table:: Issues + :header: "Issue No.", "Issue" + + , + + +**NOTE**: **Feel free to** `open issues `__. Make sure you follow the Issue Template provided. + + +Contribution Guidelines +======================== + +.. image:: https://img.shields.io/github/issues-pr-raw/ramanaditya/email-service?logo=git&logoColor=white + :target: https://github.com/ramanaditya/email-service/compare + :alt: GitHub pull requests +.. image:: https://img.shields.io/github/contributors/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/graphs/contributors + :alt: GitHub contributors + + +* Write clear meaningful git commit messages (Do read `this `__). +* Make sure your PR's description contains GitHub's special keyword references that automatically close the related issue when the PR is merged. (Check `this `__ for more info) +* When you make very very minor changes to a PR of yours (like for example fixing a text in button, minor changes requested by reviewers) make sure you squash your commits afterward so that you don't have an absurd number of commits for a very small fix. (Learn how to squash at `here `__) +* Please follow the `PR Template `__ to create the PR. +* Always open PR to ``develop`` branch. +* Please read our `Code of Conduct `__. +* Refer `this `__ for more. + + +``If you`` ❤️ ``this`` `repository `__ ``, support it by star 🌟`` From bb81395cb9784b9a1611d6717f15bda0153e3184 Mon Sep 17 00:00:00 2001 From: ramanaditya Date: Thu, 31 Dec 2020 21:49:39 +0530 Subject: [PATCH 2/9] added pylint, editorconfig, flake8, gitattributes --- .editorconfig | 36 ++++++++++++++++++++++++++++ .flake8 | 2 ++ .gitattributes | 1 + .github/workflows/python-publish.yml | 2 +- .pylintrc | 14 +++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .flake8 create mode 100644 .gitattributes create mode 100644 .pylintrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0e86ea3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,36 @@ +# http://editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{py,rst,ini}] +indent_style = space +indent_size = 4 + +[*.py] +max_line_length = 120 +multi_line_output = 3 +recursive = true +skip = venv/ +include_trailing_comma = true +force_grid_wrap = 0 +use_parentheses = true + +[*.yml] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false + +[{Makefile, *.bat}] +indent_style = tab +indent_size = 4 + +[*.bat] +end_of_line = crlf diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..6deafc2 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 120 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index d0bed7d..ab86ac5 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -29,4 +29,4 @@ jobs: TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} run: | python setup.py sdist bdist_wheel - twine upload dist/* + python -m twine upload dist/* diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..0cd27d7 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,14 @@ +[MASTER] +load-plugins=pylint_django, pylint_celery + +[FORMAT] +max-line-length=120 + +[MESSAGES CONTROL] +disable=missing-docstring,invalid-name + +[DESIGN] +max-parents=13 + +[TYPECHECK] +generated-members=REQUEST,acl_users,aq_parent,"[a-zA-Z]+_set{1,2}",save,delete From 6afb3d5b5372e3eca2882118b5be550228399e1c Mon Sep 17 00:00:00 2001 From: ramanaditya Date: Thu, 31 Dec 2020 21:58:02 +0530 Subject: [PATCH 3/9] Markdown replaced with rst --- README.md | 175 ----------------------------------------------------- README.rst | 3 +- 2 files changed, 2 insertions(+), 176 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 6397c76..0000000 --- a/README.md +++ /dev/null @@ -1,175 +0,0 @@ -# Email Service - -Python package to quickly integrate different email services with your Application with just 3 lines of code. - -[![pypi](https://img.shields.io/pypi/v/email-service.svg?color=2897A6)](https://pypi.org/project/email-service/) -[![python](https://img.shields.io/pypi/pyversions/email-service.svg)](https://pypi.org/project/email-service/) -[![license](https://img.shields.io/badge/license-MIT-red.svg?style=flat-square)](https://github.com/ramanaditya/email-service) -[![black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/ramanaditya/email-service) -[![GitHub Release](https://img.shields.io/github/v/release/ramanaditya/email-service.svg)](https://github.com/ramanaditya/email-service/releases/) -[![GitHub stars](https://img.shields.io/github/stars/ramanaditya/email-service.svg?logo=github)](https://github.com/ramanaditya/email-service/stargazers) -[![GitHub forks](https://img.shields.io/github/forks/ramanaditya/email-service.svg?logo=github&color=teal)](https://github.com/ramanaditya/email-service/network/members) - -
- -Send Your email without caring about the backend code. - -- GitHub: https://github.com/ramanaditya/email-service -- PyPI: https://pypi.org/project/email-service/ - -## Install it with pip -```bash -pip install email-service -``` - -## Email Integration -> Save the `API_KEY` in the `.env` file as -> -> SENDGRID_API_KEY=api_key -> - -### Import EmailHandler -```python -from email_service.email_handler import EmailHandler -``` - -### Form the dictionary of data -```python -data = { - "from_email": "Name WithSpace ", # Required - "subject": "This is the test for the Individual email", # Required - "reply_to_addresses": "email1@gmail.com", - "html_body": "

Email Template for Individual email

", # Either of html_body or text_body is required - "text_body": "Email Template for Individual email", - "to_for_bulk": [{"name": "Name", "email": "email@gmail.com"},], # Required for Bulk Email - "receipients": { - "to": [{"name": "name1", "email": "email1@gmail.com"},], # Required - "cc": [{"name": "name2", "email": "email2@google.com"},], - "bcc": [{"name": "name3", "email": "email3@google.com"},], - }, - "attachments": [ - "file_path (pdf)", "calender invite (ics)", "image_path (png/jpg/jpeg)" - ] -} - -``` - -### Send the email -```python - -# For Individual Email -send_email = EmailHandler() - -# For Bulk Email -send_email = EmailHandler(email_type="BULK") - -``` - -### Sendgrid Integration - -```python -# Send it using sendgrid -response = send_email.sendgrid(data) - -``` - -### Response -```yaml -status_code: - 202: OK, - 400: Error -message: Error or Success Message -``` - -# Development - -## Setup -[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ramanaditya/email-service?logo=github)](https://github.com/ramanaditya/email-service/) -[![GitHub repo size](https://img.shields.io/github/repo-size/ramanaditya/email-service?logo=github)](https://github.com/ramanaditya/email-service/) - -1. Clone the repository - ```bash - git clone https://github.com/ramanaditya/email-service - ``` - -2. Create a virtual environment using virtualenv or venv. - ```bash - python -m venv venv - source venv/bin/activate - ``` - -3. Upgrade pip - ```bash - python -m pip install --upgrade pip - ``` -4. Install python packages - ```bash - python -m pip install -r requirements.txt - ``` - -5. Create new Branch from `develop` branch - ```bash - git checkout -b develop origin/develop - git checkout -b feature_branch - ``` - -6. Generating distribution archives - ```bash - # Downloading latest version of setuptools - python -m pip install --user --upgrade setuptools wheel - - python setup.py sdist bdist_wheel - ``` - -7. Uploading to Test PyPI - ```bash - # Upload to Test PyPI https://test.pypi.org/ - python -m twine upload --repository testpypi dist/* - ``` - -8. Download the package - ```bash - python -m pip install -i https://test.pypi.org/simple/ email-service - ``` - -9. Check against the code - ```bash - # Edit the file inside /example to have some valid data - # export SENDGRID_API_KEY before running the script - python individual_email.py # For individual email - python bulk.py # For bulk email - ``` - -10. Push the Code - ```bash - git add file_which_was_changed - git commit -m "Commit Message" - git push -u origin feature_branch - ``` - -## Issues - -[![GitHub issues](https://img.shields.io/github/issues/ramanaditya/email-service?logo=github)](https://github.com/ramanaditya/email-service/issues) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat&logo=git&logoColor=white)](https://github.com/ramanaditya/email-service/pulls) -[![GitHub last commit](https://img.shields.io/github/last-commit/ramanaditya/email-service?logo=github)](https://github.com/ramanaditya/email-service/) - -> 1. Integrating Mailgun -> 2. Integrating Amazon SES - -**NOTE**: **Feel free to [open issues](https://github.com/ramanaditya/email-service/issues/new/choose)**. Make sure you follow the Issue Template provided. - -## Contribution Guidelines - -[![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/ramanaditya/email-service?logo=git&logoColor=white)](https://github.com/ramanaditya/email-service/compare) -[![GitHub contributors](https://img.shields.io/github/contributors/ramanaditya/email-service?logo=github)](https://github.com/ramanaditya/email-service/graphs/contributors) - -- Write clear meaningful git commit messages (Do read [this](http://chris.beams.io/posts/git-commit/)). -- Make sure your PR's description contains GitHub's special keyword references that automatically close the related issue when the PR is merged. (Check [this](https://github.com/blog/1506-closing-issues-via-pull-requests) for more info) -- When you make very very minor changes to a PR of yours (like for example fixing a text in button, minor changes requested by reviewers) make sure you squash your commits afterward so that you don't have an absurd number of commits for a very small fix. (Learn how to squash at [here](https://davidwalsh.name/squash-commits-git)) - -- Please follow the [PR Template](https://github.com/ramanaditya/email-service/blob/master/.github/PULL_REQUEST_TEMPLATE.md) to create the PR. -- Always open PR to `develop` branch. -- Please read our [Code of Conduct](./CODE_OF_CONDUCT.md). -- Refer [this](https://github.com/ramanaditya/email-service/blob/master/CONTRIBUTING.md) for more. - -> If you like this [repository](https://github.com/ramanaditya/email-service), support it by star :star2: diff --git a/README.rst b/README.rst index 3062941..cf65e6e 100644 --- a/README.rst +++ b/README.rst @@ -259,6 +259,7 @@ Issues :target: https://github.com/ramanaditya/email-service/ :alt: GitHub last commit + .. csv-table:: Issues :header: "Issue No.", "Issue" @@ -288,4 +289,4 @@ Contribution Guidelines * Refer `this `__ for more. -``If you`` ❤️ ``this`` `repository `__ ``, support it by star 🌟`` +``If you ❤️ this`` `repository `__ ``, support it by star 🌟`` From 6030c37b58073df74eea52078ba7cc66ceeb3d7c Mon Sep 17 00:00:00 2001 From: ramanaditya Date: Thu, 31 Dec 2020 22:00:01 +0530 Subject: [PATCH 4/9] readme --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index cf65e6e..11adcff 100644 --- a/README.rst +++ b/README.rst @@ -260,6 +260,7 @@ Issues :alt: GitHub last commit + .. csv-table:: Issues :header: "Issue No.", "Issue" From 6ecad65dbe119e84809d6ca98d2abe6964b0e078 Mon Sep 17 00:00:00 2001 From: ramanaditya Date: Thu, 31 Dec 2020 22:03:00 +0530 Subject: [PATCH 5/9] Issue Table reformatted --- README.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 11adcff..5f83e3d 100644 --- a/README.rst +++ b/README.rst @@ -260,11 +260,11 @@ Issues :alt: GitHub last commit - -.. csv-table:: Issues - :header: "Issue No.", "Issue" - - , ++-------------+-------------+ +| Issue No. | Issue | ++=============+=============+ +| | | ++-------------+-------------+ **NOTE**: **Feel free to** `open issues `__. Make sure you follow the Issue Template provided. From cf9a74bff5efe0ca5979f5a2c417eeccca7edb11 Mon Sep 17 00:00:00 2001 From: ramanaditya Date: Thu, 31 Dec 2020 22:56:51 +0530 Subject: [PATCH 6/9] version file detached from setup --- README.rst | 2 +- email_service/version.py | 11 +++++++++++ setup.py | 32 +++++++++++++++++++------------- 3 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 email_service/version.py diff --git a/README.rst b/README.rst index 5f83e3d..2f7a76f 100644 --- a/README.rst +++ b/README.rst @@ -290,4 +290,4 @@ Contribution Guidelines * Refer `this `__ for more. -``If you ❤️ this`` `repository `__ ``, support it by star 🌟`` +``If you`` ❤️ ``this`` `repository `__ ``, support it by star 🌟`` diff --git a/email_service/version.py b/email_service/version.py new file mode 100644 index 0000000..f821a30 --- /dev/null +++ b/email_service/version.py @@ -0,0 +1,11 @@ +import os +from datetime import datetime + +import pytz + +__version__ = "1.0.0" + +# Add datetime.now() for test PyPI to skip conflicts in file name +test_version = os.environ.get("TESTPYPI", default=False) +if test_version: + __version__ += "." + datetime.now(pytz.timezone("UTC")).strftime("%y.%m.%d.%H.%M") diff --git a/setup.py b/setup.py index ab4f322..6060a56 100644 --- a/setup.py +++ b/setup.py @@ -1,24 +1,24 @@ #!/usr/bin/env python - -import os -from datetime import datetime - -import pytz +from collections import OrderedDict try: from setuptools import setup, find_packages except ImportError: from distutils.core import setup -with open("README.md", "r") as readme_file: - long_description = readme_file.read() +from pathlib import Path -version = "1.0.0" +ROOT_DIR = Path(__file__).resolve(strict=True).parent +PACKAGE_DIR = ROOT_DIR / "email_service" -# Add datetime.now() for test PyPI to skip conflicts in file name -test_version = os.environ.get("TESTPYPI", default=False) -if test_version: - version += "." + datetime.now(pytz.timezone("UTC")).strftime("%y.%m.%d.%H") + "" +with open(PACKAGE_DIR / "version.py", encoding="utf-8") as version_file: + code_obj = compile(version_file.read(), PACKAGE_DIR / "version.py", "exec") + __version__ = dict() + exec(code_obj, __version__) + version = __version__["__version__"] + +with open("README.rst", "r") as readme_file: + long_description = readme_file.read() setup( name="email-service", @@ -29,7 +29,7 @@ description="Package to integrate different email services with your application " "in just three lines of code.", long_description=long_description, - long_description_content_type="text/markdown", + long_description_content_type="text/x-rst", url="https://github.com/ramanaditya/email-service", packages=find_packages(), install_requires=["sendgrid==6.4.8"], @@ -48,4 +48,10 @@ keywords=( "python, email, sendgrid, amazon, ses, mailgun, project, email client, setup.py" ), + project_urls=OrderedDict( + [ + ("Source", "https://github.com/ramanaditya/email-service"), + ("Tracker", "https://github.com/ramanaditya/email-service/issues"), + ] + ), ) From db970ad6065440d35570e085bb32e54f71c81397 Mon Sep 17 00:00:00 2001 From: Aditya Raman Date: Fri, 1 Jan 2021 01:59:04 +0530 Subject: [PATCH 7/9] Ci (#5) * flake8 integrated * v1.1.0 changes in setup.py flake8 external version file added * Grammatical error corrected --- .flake8 | 3 +++ .github/PULL_REQUEST_TEMPLATE.md | 4 ++-- .github/workflows/ci.yml | 33 ++++++++++++++++++++++++++++++ .pylintrc | 14 ------------- README.rst | 11 ++++++++++ email_service/sendgrid/sendgrid.py | 19 +++++++++++++++-- email_service/version.py | 2 +- requirements.txt | 3 ++- setup.cfg | 2 ++ setup.py | 5 +++-- 10 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .pylintrc create mode 100644 setup.cfg diff --git a/.flake8 b/.flake8 index 6deafc2..cb5aa51 100644 --- a/.flake8 +++ b/.flake8 @@ -1,2 +1,5 @@ [flake8] max-line-length = 120 +exclude = .tox,.git,docs,venv,examples,build,dist,email_service.egg-info +max-complexity = 18 +ignore = E203 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 37a7626..e15ce50 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -17,11 +17,11 @@ Please delete options that are not relevant. # Checklist: -- [ ] I have optimized the import, on pycharm it can be done using `ctrl + alt/option + o` +- [ ] I have optimized the import, on Pycharm it can be done using `ctrl + alt/option + o` - [ ] I have used Black for Code Formatting, this enhances code readability. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code -- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6289635 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI + +on: + pull_request: + branches: [ "main" ] + paths-ignore: [ "docs/**" ] + + push: + branches: [ "main" ] + paths-ignore: [ "docs/**" ] + + +jobs: + flake8: + runs-on: ubuntu-latest + + steps: + + - name: Checkout Code Repository + uses: actions/checkout@v2 + + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + + - name: Install flake8 + run: | + python -m pip install --upgrade pip + pip install flake8 + + - name: Lint with flake8 + run: flake8 diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index 0cd27d7..0000000 --- a/.pylintrc +++ /dev/null @@ -1,14 +0,0 @@ -[MASTER] -load-plugins=pylint_django, pylint_celery - -[FORMAT] -max-line-length=120 - -[MESSAGES CONTROL] -disable=missing-docstring,invalid-name - -[DESIGN] -max-parents=13 - -[TYPECHECK] -generated-members=REQUEST,acl_users,aq_parent,"[a-zA-Z]+_set{1,2}",save,delete diff --git a/README.rst b/README.rst index 2f7a76f..2f48a7b 100644 --- a/README.rst +++ b/README.rst @@ -180,6 +180,17 @@ Push the Code $ git push -u origin feature_branch +Build Package for Local Testing +================================ +.. code-block:: console + + $ # Build the package + $ python setup.py build + + $ # Install the package + $ python setup.py install + + PyPI ----- diff --git a/email_service/sendgrid/sendgrid.py b/email_service/sendgrid/sendgrid.py index b12928c..e940195 100644 --- a/email_service/sendgrid/sendgrid.py +++ b/email_service/sendgrid/sendgrid.py @@ -1,7 +1,22 @@ import base64 from sendgrid import SendGridAPIClient -from sendgrid.helpers.mail import * +from sendgrid.helpers.mail import ( + Attachment, + Bcc, + Cc, + Content, + Disposition, + FileContent, + FileName, + FileType, + From, + Mail, + MimeType, + ReplyTo, + Subject, + To, +) from email_service.utils.clean_data import CleanData from email_service.utils.constants import ATTACHMENT_FILE_TYPES @@ -85,7 +100,7 @@ def send_email(self, message) -> dict: } # For accepting Other errors - except: + except Exception: status = { "status_code": 400, "message": f"Something Went Wrong", diff --git a/email_service/version.py b/email_service/version.py index f821a30..78212a0 100644 --- a/email_service/version.py +++ b/email_service/version.py @@ -3,7 +3,7 @@ import pytz -__version__ = "1.0.0" +__version__ = "1.1.0" # Add datetime.now() for test PyPI to skip conflicts in file name test_version = os.environ.get("TESTPYPI", default=False) diff --git a/requirements.txt b/requirements.txt index c07595e..9a5b944 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ sendgrid==6.4.8 # https://github.com/sendgrid/sendgrid-python/ # Others # ======================================================================= -pytz==2020.5 # https://github.com/stub42/pytz +pytz==2020.5 # https://github.com/stub42/pytz +flake8==3.8.4 # https://github.com/PyCQA/flake8 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..0c9e0fc --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +license_file = LICENSE diff --git a/setup.py b/setup.py index 6060a56..2fcf573 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ #!/usr/bin/env python from collections import OrderedDict +from pathlib import Path try: from setuptools import setup, find_packages except ImportError: from distutils.core import setup -from pathlib import Path ROOT_DIR = Path(__file__).resolve(strict=True).parent PACKAGE_DIR = ROOT_DIR / "email_service" @@ -23,7 +23,7 @@ setup( name="email-service", version=version, - License="MIT License", + license="MIT License", author="Aditya Raman", author_email="adityaraman96@gmail.com", description="Package to integrate different email services with your application " @@ -32,6 +32,7 @@ long_description_content_type="text/x-rst", url="https://github.com/ramanaditya/email-service", packages=find_packages(), + zip_safe=False, install_requires=["sendgrid==6.4.8"], classifiers=[ "Development Status :: 4 - Beta", From a17064e93ba6d2edc5175ce562ab92a275dfae48 Mon Sep 17 00:00:00 2001 From: ramanaditya Date: Fri, 1 Jan 2021 02:24:06 +0530 Subject: [PATCH 8/9] docs --- .readthedocs.yml | 10 ++ docs/Makefile | 30 ++++ docs/__init__.py | 0 docs/conf.py | 96 +++++++++++++ docs/email-service.rst | 304 +++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 22 +++ docs/make.bat | 46 +++++++ docs/requirements.txt | 5 + 8 files changed, 513 insertions(+) create mode 100644 .readthedocs.yml create mode 100644 docs/Makefile create mode 100644 docs/__init__.py create mode 100644 docs/conf.py create mode 100644 docs/email-service.rst create mode 100644 docs/index.rst create mode 100644 docs/make.bat create mode 100644 docs/requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 0000000..d1e3f47 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,10 @@ +version: 2 + +sphinx: + configuration: docs/conf.py + +python: + version: 3.9 + install: + - requirements: docs/requirements.txt + - requirements: requirements.txt diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..644e6e7 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,30 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build -c . +SOURCEDIR = . +BUILDDIR = ./_build +PACKAGE = ../email_service + + +.PHONY: help livehtml apidocs Makefile + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +# Build, watch and serve docs with live reload +livehtml: + sphinx-autobuild -b html --open-browser --port 7000 --watch $(PACKAGE) -c . $(SOURCEDIR) $(BUILDDIR)/html + +# Outputs rst files from application code +apidocs: + sphinx-apidoc -o $(SOURCEDIR)/api $(PACKAGE) + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -b $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/__init__.py b/docs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..8a66e1f --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,96 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. + +from datetime import date +from pathlib import Path + +ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent +PACKAGE_DIR = ROOT_DIR / "email_service" +DOCS_DIR = ROOT_DIR / "email_service" +version_file_path = PACKAGE_DIR / "version.py" + +code_obj = compile(version_file_path.read_text(), version_file_path, "exec") +__version__ = dict() +exec(code_obj, __version__) +version = __version__["__version__"] + +# -- Project information ----------------------------------------------------- + +project = "Email Service" +copyright = """2020, Aditya Raman""" +author = "Aditya Raman" + +# The full version, including alpha/beta/rc tags +version = release = f"v{version}" +today = str(date.today()) +language = "en" + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx_rtd_theme", + "sphinx.ext.autodoc", + "sphinx.ext.napoleon", + "sphinx.ext.viewcode", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "sphinx_rtd_theme" # alternate: "alabaster" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] +# These paths are either relative to html_static_path +# or fully qualified paths (eg. https://...) +# html_css_files = [] +# +# html_style = "" + +master_doc = "index" + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + "papersize": "a4paper", + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + "preamble": "\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of contents}}", + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} +latex_show_urls = "footnote" + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +add_module_names = False +add_function_parentheses = False +show_authors = True diff --git a/docs/email-service.rst b/docs/email-service.rst new file mode 100644 index 0000000..2f48a7b --- /dev/null +++ b/docs/email-service.rst @@ -0,0 +1,304 @@ +############### +Email Service +############### + +Python package to quickly integrate different email services with your Application with just 3 lines of code. + +.. image:: https://img.shields.io/pypi/v/email-service.svg?color=2897A6 + :target: https://pypi.org/project/email-service/ + :alt: pypi +.. image:: https://img.shields.io/pypi/pyversions/email-service.svg + :target: https://pypi.org/project/email-service/ + :alt: python +.. image:: https://img.shields.io/badge/license-MIT-red.svg?style=flat-square + :target: https://github.com/ramanaditya/email-service + :alt: license +.. image:: https://img.shields.io/github/v/release/ramanaditya/email-service.svg + :target: https://github.com/ramanaditya/email-service/releases/ + :alt: GitHub Release +.. image:: https://img.shields.io/github/stars/ramanaditya/email-service.svg?logo=github + :target: https://github.com/ramanaditya/email-service/stargazers + :alt: GitHub stars +.. image:: https://img.shields.io/github/forks/ramanaditya/email-service.svg?logo=github&color=teal + :target: https://github.com/ramanaditya/email-service/network/members + :alt: GitHub forks + + +---- + + +Send Your email without caring about the backend code. + +:GitHub: `ramanaditya/email-service `__ +:PyPI: `pypi.org/project/email-service `__ + + +Usage +====== + + +Install it with pip +-------------------- +.. code-block:: console + + $ pip install email-service + + +Email Integration +-------------------- +``Save the`` **API_KEY** ``in the`` **.env** ``file as`` + + +.. code-block:: text + + SENDGRID_API_KEY=api_key + + +Import EmailHandler +-------------------- +.. code-block:: python + + >>> from email_service.email_handler import EmailHandler + + +Form the dictionary of data +------------------------------ +.. code-block:: python + + data = { + "from_email": "Name WithSpace ", # Required + "subject": "This is the test for the Individual email", # Required + "reply_to_addresses": "email1@gmail.com", + "html_body": "

Email Template for Individual email

", # Either of html_body or text_body is required + "text_body": "Email Template for Individual email", + "to_for_bulk": [{"name": "Name", "email": "email@gmail.com"},], # Required for Bulk Email + "receipients": { + "to": [{"name": "name1", "email": "email1@gmail.com"},], # Required + "cc": [{"name": "name2", "email": "email2@google.com"},], + "bcc": [{"name": "name3", "email": "email3@google.com"},], + }, + "attachments": [ + "file_path (pdf)", "calender invite (ics)", "image_path (png/jpg/jpeg)" + ] + } + + +Send the email +----------------- +.. code-block:: python + + >>> # For Individual Email + >>> send_email = EmailHandler() + + >>> # For Bulk Email + >>> send_email = EmailHandler(email_type="BULK") + + +Sendgrid Integration +---------------------- +.. code-block:: python + + >>> # Send it using sendgrid + >>> response = send_email.sendgrid(data) + + +Response +----------- +.. code-block:: yaml + + status_code: + 202: OK, + 400: Error + message: Error or Success Message + + +Development +============ + +.. image:: https://img.shields.io/github/languages/code-size/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/ + :alt: GitHub code size in bytes +.. image:: https://img.shields.io/github/repo-size/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/ + :alt: GitHub repo size +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square + :target: https://github.com/ramanaditya/email-service + :alt: black + + +Setup +------- + + +Clone the repository +^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ git clone https://github.com/ramanaditya/email-service + + +Create a virtual environment using virtualenv or venv. +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m venv venv + $ source venv/bin/activate + + +Upgrade pip +^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m pip install --upgrade pip + + +Install python packages +^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m pip install -r requirements.txt + + +Git Flow +---------- + + +Create new Branch from `develop` branch +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ git checkout -b develop origin/develop + $ git checkout -b feature_branch + + +Push the Code +^^^^^^^^^^^^^^^ +.. code-block:: console + + $ git add file_which_was_changed + $ git commit -m "Commit Message" + $ git push -u origin feature_branch + + +Build Package for Local Testing +================================ +.. code-block:: console + + $ # Build the package + $ python setup.py build + + $ # Install the package + $ python setup.py install + + +PyPI +----- + + +This is just for the reference and need not to be run, +If you want to run these scripts, please take a note of this + +* For testing, we maintain the test package at `testpypi `__ +* PyPI or Test PyPI, does not accept same file name, you can change the file name or version in the `./setup.py `__ +* You will be prompted to enter + - Either username and password + - or, username as "__token__" and password as token (can be generated from the pypi website) +* It will be uploaded to your pypi or testpypi account + + +Generating distribution archives +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ # Downloading latest version of setuptools + $ python -m pip install --user --upgrade setuptools wheel + + $ python setup.py sdist bdist_wheel + + +Uploading to Test PyPI +^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ # Upload to Test PyPI https://test.pypi.org/ + $ python -m twine upload --repository testpypi dist/* + + +Download the package from Test PyPI +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m pip install -i https://test.pypi.org/simple/ email-service + + +Check against the code +^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ # Edit the file inside /example to have some valid data + $ # export SENDGRID_API_KEY before running the script + $ python individual_email.py # For individual email + $ python bulk.py # For bulk email + + +Uploading to PyPI +^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ # Upload to PyPI https://pypi.org/ + $ python -m twine upload dist/* + + +Download the package from Test PyPI +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. code-block:: console + + $ python -m pip install -i https://test.pypi.org/simple/ email-service + + +Issues +======== + + +.. image:: https://img.shields.io/github/issues/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/issues + :alt: GitHub issues +.. image:: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat&logo=git&logoColor=white + :target: https://github.com/ramanaditya/email-service/pulls + :alt: PRs Welcome +.. image:: https://img.shields.io/github/last-commit/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/ + :alt: GitHub last commit + + ++-------------+-------------+ +| Issue No. | Issue | ++=============+=============+ +| | | ++-------------+-------------+ + + +**NOTE**: **Feel free to** `open issues `__. Make sure you follow the Issue Template provided. + + +Contribution Guidelines +======================== + +.. image:: https://img.shields.io/github/issues-pr-raw/ramanaditya/email-service?logo=git&logoColor=white + :target: https://github.com/ramanaditya/email-service/compare + :alt: GitHub pull requests +.. image:: https://img.shields.io/github/contributors/ramanaditya/email-service?logo=github + :target: https://github.com/ramanaditya/email-service/graphs/contributors + :alt: GitHub contributors + + +* Write clear meaningful git commit messages (Do read `this `__). +* Make sure your PR's description contains GitHub's special keyword references that automatically close the related issue when the PR is merged. (Check `this `__ for more info) +* When you make very very minor changes to a PR of yours (like for example fixing a text in button, minor changes requested by reviewers) make sure you squash your commits afterward so that you don't have an absurd number of commits for a very small fix. (Learn how to squash at `here `__) +* Please follow the `PR Template `__ to create the PR. +* Always open PR to ``develop`` branch. +* Please read our `Code of Conduct `__. +* Refer `this `__ for more. + + +``If you`` ❤️ ``this`` `repository `__ ``, support it by star 🌟`` diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..5897f43 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,22 @@ +.. Email Service documentation master file, created by + sphinx-quickstart. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Email Service's documentation! +====================================================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + email-service + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..30e294e --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,46 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build -c . +) +set SOURCEDIR=_source +set BUILDDIR=_build +set PACKAGE= ../email_service + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.Install sphinx-autobuild for live serving. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -b %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:livehtml +sphinx-autobuild -b html --open-browser -p 7000 --watch %PACKAGE% -c . %SOURCEDIR% %BUILDDIR%/html +GOTO :EOF + +:apidocs +sphinx-apidoc -o %SOURCEDIR%/api %PACKAGE% +GOTO :EOF + +:help +%SPHINXBUILD% -b help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..edf4b3b --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,5 @@ +# Documentation +# ------------------------------------------------------------------------------ +sphinx==3.4.1 # https://github.com/sphinx-doc/sphinx +sphinx-autobuild==2020.9.1 # https://github.com/GaretJax/sphinx-autobuild +sphinx-rtd-theme==0.5.0 # https://github.com/readthedocs/sphinx_rtd_theme From 628839879a2b2c8f5387b6293051cefd701e59fd Mon Sep 17 00:00:00 2001 From: ramanaditya Date: Fri, 1 Jan 2021 02:30:55 +0530 Subject: [PATCH 9/9] modified f-string for flake8 --- email_service/sendgrid/sendgrid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/email_service/sendgrid/sendgrid.py b/email_service/sendgrid/sendgrid.py index e940195..cadc239 100644 --- a/email_service/sendgrid/sendgrid.py +++ b/email_service/sendgrid/sendgrid.py @@ -103,7 +103,7 @@ def send_email(self, message) -> dict: except Exception: status = { "status_code": 400, - "message": f"Something Went Wrong", + "message": "Something Went Wrong", } return status