Skip to content

Commit

Permalink
Merge pull request #19 from FelixLuciano/setuptools
Browse files Browse the repository at this point in the history
Setuptools
  • Loading branch information
FelixLuciano committed Aug 29, 2022
2 parents 7633938 + 12ab2f1 commit e8982c2
Show file tree
Hide file tree
Showing 25 changed files with 283 additions and 175 deletions.
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,3 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Google API oauth2 client credentials secrets
# Sensitive file! It must never be exposed.
/credentials.json

# Google API authorized user file
# Sensitive file! It must never be exposed.
/token.json
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Mail templating and sending with Jupyter
</p>
<p align="center">
<img src="public/image/example.jpg" alt="Page example" />
<img src="assets/image/example.jpg" alt="Page example" />
</p>


Expand All @@ -19,12 +19,22 @@ In order to send the pages by Gmail or fetch data from Google Sheets, Google Clo
See the [Getting started with authentication](https://cloud.google.com/docs/authentication/getting-started) for Google Cloud API. Then put your key at `[PROJECT FOLDER]/credentials.json`. and it's ready to use!


## Install dependencies
## Install

This project has some dependencies (see [`requirements.txt`](requirements.txt)) that are not included in the standard python library, so it is necessary to install them runnung the following command:
```bash
pip install https://github.com/FelixLuciano/pypers/archive/refs/tags/1.0.0.tar.gz
```

You can also [download the latest version](https://github.com/FelixLuciano/pypers/archive/main.tar.gz) (but not recommended) of the package and install it locally. Or directly:

```bash
pip install https://github.com/FelixLuciano/pypers/archive/main.tar.gz
```

## Create a new page

```bash
pip install -r requirements.txt
python -m pypers create [path/to/page]
```


Expand Down
File renamed without changes
1 change: 0 additions & 1 deletion pages/examples/newsletter.ipynb

This file was deleted.

2 changes: 0 additions & 2 deletions public/python/utils.py

This file was deleted.

94 changes: 9 additions & 85 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,85 +1,9 @@
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
asttokens==2.0.5
attrs==21.4.0
backcall==0.2.0
beautifulsoup4==4.11.1
bleach==5.0.1
cachetools==5.2.0
certifi==2022.6.15
cffi==1.15.1
charset-normalizer==2.1.0
colorama==0.4.5
cssutils==2.5.1
debugpy==1.6.2
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
executing==0.9.0
fastjsonschema==2.16.1
google-api-core==2.8.2
google-api-python-client==2.54.0
google-auth==2.9.1
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.5.2
googleapis-common-protos==1.56.4
httplib2==0.20.4
idna==3.3
ipykernel==6.15.1
ipython==8.4.0
ipython-genutils==0.2.0
ipywidgets==7.7.1
jedi==0.18.1
Jinja2==3.1.2
jsonschema==4.7.2
jupyter-client==7.3.4
jupyter-core==4.11.1
jupyterlab-pygments==0.2.2
jupyterlab-widgets==1.1.1
MarkupSafe==2.1.1
matplotlib-inline==0.1.3
mistune==0.8.4
nbclient==0.6.6
nbconvert==6.5.0
nbformat==5.4.0
nest-asyncio==1.5.5
notebook==6.4.12
numpy==1.23.1
oauthlib==3.2.0
packaging==21.3
pandas==1.4.3
pandocfilters==1.5.0
parso==0.8.3
pickleshare==0.7.5
prometheus-client==0.14.1
prompt-toolkit==3.0.30
protobuf==4.21.3
psutil==5.9.1
pure-eval==0.2.2
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
Pygments==2.12.0
pyparsing==3.0.9
pyrsistent==0.18.1
python-dateutil==2.8.2
pytz==2022.1
pywin32==304
pywinpty==2.0.6
pyzmq==23.2.0
requests==2.28.1
requests-oauthlib==1.3.1
rsa==4.9
Send2Trash==1.8.0
six==1.16.0
soupsieve==2.3.2.post1
stack-data==0.3.0
terminado==0.15.0
tinycss2==1.1.1
tornado==6.2
traitlets==5.3.0
uritemplate==4.1.1
urllib3==1.26.10
wcwidth==0.2.5
webencodings==0.5.1
widgetsnbextension==3.6.1
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
jinja2
beautifulsoup4
cssutils
pandas
ipykernel
ipywidgets
22 changes: 22 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from setuptools import setup


def parse_requirements(filename):
lines = (line.strip() for line in open(filename))

return [line for line in lines if line and not line.startswith("#")]


if __name__ == "__main__":
setup(
name="Pypers",
version="1.0.0",
description="Mail templating and sending with Jupyter",
url="https://github.com/FelixLuciano/pypers",
author="Luciano Felix",
packages=["pypers"],
package_dir={"pypers": "src"},
package_data={"pypers": ["data/*"]},
license="MIT",
install_requires=parse_requirements("requirements.txt"),
)
6 changes: 4 additions & 2 deletions src/Create.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


class Create:
BASEDIR = Path("pages")
TEMPLATE_FILENAME = Path("public", "template", "New Page.ipynb")
BASEDIR = Path.cwd()
TEMPLATE_FILENAME = Path(__file__).parent.joinpath("data", "New Page.ipynb")

def __init__(self, filename: Path):
self.filename = self.BASEDIR.joinpath(filename).with_suffix(
Expand All @@ -27,3 +27,5 @@ def create_file(self):

with open(self.filename, "w", encoding="utf-8") as page_file:
json.dump(template, page_file)

print(f"Created {self.filename.absolute()}")
4 changes: 2 additions & 2 deletions src/Google.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Google:
@cache
@staticmethod
def authenticate(_is_retry=False):
credentials_file = Path("env", "credentials.json")
token_file = Path("env", "token.json")
credentials_file = Path("credentials.json")
token_file = Path("token.json")

if token_file.exists():
Google.credentials = Credentials.from_authorized_user_file(
Expand Down
18 changes: 13 additions & 5 deletions src/Preview.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import ipywidgets as widgets
from bs4 import BeautifulSoup
from IPython.display import HTML, clear_output, display
Expand All @@ -11,10 +13,9 @@ class Preview:
@staticmethod
def render(page, user):
content = BeautifulSoup(page.render(user), "html.parser")
template = Path(__file__).parent.joinpath("data", "preview.html")

with open(
"public/template/preview.html", "r", encoding="utf-8"
) as template_file:
with open(template, "r", encoding="utf-8") as template_file:
template = BeautifulSoup(template_file, "html.parser")

anchor = template.select_one("page-preview")
Expand All @@ -29,9 +30,16 @@ def display(page):

if hasattr(users, "name_column"):
if isinstance(users.name_column, str):
mails = users[users.name_column] + " <" + users[users.email_column] + ">"
mails = (
users[users.name_column] + " <" + users[users.email_column] + ">"
)
else:
mails = users.loc[:, users.name_column].apply(' - '.join, 1) + " <" + users[users.email_column] + ">"
mails = (
users.loc[:, users.name_column].apply(" - ".join, 1)
+ " <"
+ users[users.email_column]
+ ">"
)
else:
mails = users[users.email_column]

Expand Down
18 changes: 3 additions & 15 deletions src/Workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@


class Workspace:
HIDDEN_FILES = (
"**/env",
"**/src",
"**/.vscode",
"**/public/image",
"**/public/template",
".gitignore",
"requirements.txt",
)

@staticmethod
def check_vsc_ipynb_file():
def get_ipynb_file():
scope = vars(__main__)

if "__vsc_ipynb_file__" not in scope:
raise Exception("Pypers only work at VS Code Jupyter!")

@staticmethod
def get_ipynb_file():
return Path(vars(__main__)["__vsc_ipynb_file__"])
return scope["__vsc_ipynb_file__"]

@staticmethod
def get_ipynb():
Expand All @@ -43,6 +31,6 @@ def get_html_source():
cell_source = cell["source"]

if len(cell_source) > 1 and cell_source[0] == "%%script html\n":
source.extend(cell["source"][1:])
source.extend(cell_source[1:])

return "".join(source)
31 changes: 15 additions & 16 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import logging
import warnings
if __name__ != "__main__":
import logging
import warnings

import cssutils
import cssutils

from .Create import Create as create
from .Google import Google as google
from .Page import Page as page
from .Preview import Preview as preview
from .Send import Send as send
from .Workspace import Workspace as workspace
from .Create import Create as create
from .Google import Google as google
from .Page import Page as page
from .Preview import Preview as preview
from .Send import Send as send
from .Workspace import Workspace as workspace


workspace.check_vsc_ipynb_file()
warnings.simplefilter(action="ignore")

warnings.simplefilter(action='ignore')
cssutils.ser.prefs.keepComments = False
cssutils.ser.prefs.lineSeparator = ""
cssutils.ser.prefs.propertyNameSpacer = ""

cssutils.ser.prefs.keepComments = False
cssutils.ser.prefs.lineSeparator = ""
cssutils.ser.prefs.propertyNameSpacer = ""

cssutils.log.setLevel(logging.CRITICAL)
cssutils.log.setLevel(logging.CRITICAL)
12 changes: 2 additions & 10 deletions src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@


def main(args):
if args.action == "setup":
import subprocess
import venv

venv.create("env", with_pip=True)
subprocess.run([Path("env", "Scripts", "pip"), "-r", "requirements.txt"])

elif args.action == "create":
if args.action == "create":
from os import startfile

from Create import Create
from .Create import Create

new_page = Create(args.dest)

Expand All @@ -27,7 +20,6 @@ def main(args):
def parse_arguments():
parser = argparse.ArgumentParser()
subparser = parser.add_subparsers(dest="action")
setup = subparser.add_parser("setup")
create = subparser.add_parser("create")

create.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions public/template/new page.ipynb → src/data/new page.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"outputs": [],
"source": [
"import pandas as pd\n",
"from src import page\n",
"from pypers import page\n",
"\n",
"users = pd.read_csv(\"public/data/mailing-list.csv\")\n",
"users.email_column = \"email\"\n",
Expand Down Expand Up @@ -171,7 +171,7 @@
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "359d27c1ede3156a31bf43fc0e3aefa4af1cc43923c1239e05b911c5a2f535d7"
"hash": "06533af5f6072c33c887b7ac5ff0332542541b8cfbdba87749e169dacaf4c9ce"
}
}
},
Expand Down
File renamed without changes.
Loading

0 comments on commit e8982c2

Please sign in to comment.