-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make this into a real package and prepare for publish on PyPi (#1)
* preparation stuff for publishing on pypi * follow some example on https://python-packaging.readthedocs.io/en/latest/command-line-scripts.html * setup with a command line installer * update the readme and cleanup code to work in module form * simplify without named args * handle weekends and weekdays and nicer readme * Update README.md * Remove codecov * cleanup for flake
- Loading branch information
Showing
12 changed files
with
244 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
on: | ||
push: | ||
branches-ignore: | ||
- 'release*' | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [2.7, 3.6, 3.7, 3.8] | ||
|
||
steps: | ||
- name: "Checkout code" | ||
uses: actions/checkout@v2 | ||
|
||
- name: "Set up Python ${{ matrix.python-version }}" | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: "Install dependencies" | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install . | ||
pip install flake8 | ||
pip install radon | ||
- name: "Run flake8" | ||
run: | | ||
flake8 --ignore=E501 | ||
- name: "Run radon" | ||
run: | | ||
radon cc ./py_markdown_diary/ -a | ||
radon mi . | ||
radon raw . -s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.6] | ||
|
||
steps: | ||
- name: "Checkout code" | ||
uses: actions/checkout@v2 | ||
|
||
- name: "Set up Python ${{ matrix.python-version }}" | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: "Replace version string with release number" | ||
run: | | ||
sed -i "s/0.0.0/${VERSION_REF##*/}/g" setup.py | ||
env: | ||
VERSION_REF: ${{ github.ref }} | ||
|
||
- name: "Install dependencies" | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install . | ||
pip install twine | ||
- name: "PyPi release" | ||
run: | | ||
python setup.py sdist | ||
twine check dist/* | ||
twine upload dist/* | ||
env: | ||
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} | ||
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,4 +104,5 @@ venv.bak/ | |
.mypy_cache/ | ||
|
||
#IntelliJ | ||
.idea/ | ||
.idea/ | ||
*.iml |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from datetime import datetime, date, timedelta | ||
import calendar | ||
import os | ||
|
||
|
||
class Diary(object): | ||
|
||
@staticmethod | ||
def valid_month(month_str): | ||
try: | ||
return datetime.strptime(month_str, '%Y-%m') | ||
except ValueError: | ||
return None | ||
|
||
@staticmethod | ||
def valid_year(year_str): | ||
try: | ||
return datetime.strptime(year_str, '%Y') | ||
except ValueError: | ||
return None | ||
|
||
@staticmethod | ||
def write_month_file(month, filename, weekdays_only): | ||
days_in_month = calendar.monthrange(month.year, month.month)[1] | ||
|
||
with open(filename, 'w') as open_file: | ||
open_file.writelines('# ' + month.strftime('%B') + '\n') | ||
open_file.writelines('\n') | ||
|
||
current_week = 0 | ||
|
||
for d in range(0, days_in_month): | ||
today_date = month + timedelta(days=d) | ||
|
||
temp_week = int(today_date.strftime('%W')) + 1 | ||
|
||
if current_week != temp_week: | ||
current_week = temp_week | ||
open_file.writelines('\n') | ||
open_file.writelines('\n') | ||
open_file.writelines('## Week ' + str(current_week) + '\n') | ||
open_file.writelines('\n') | ||
|
||
day_of_week = int(today_date.strftime('%w')) | ||
|
||
is_weekend = day_of_week == 0 or day_of_week == 6 | ||
|
||
if not is_weekend or (is_weekend and not weekdays_only): | ||
open_file.writelines('### ' + today_date.strftime('%a') + ' ' + today_date.strftime('%-d') + '\n') | ||
open_file.writelines('\n') | ||
open_file.writelines('\n') | ||
|
||
@staticmethod | ||
def create_month_file(month, weekdays_only): | ||
filename = str(month.strftime('%m')) + ' ' + str(month.strftime('%B')) + '.md' | ||
|
||
if not Diary.file_exists(filename): | ||
Diary.write_month_file(month, filename, weekdays_only) | ||
|
||
@staticmethod | ||
def create_year_files(year, weekdays_only): | ||
for m in range(1, 13): | ||
Diary.create_month_file(date(year.year, m, 1), weekdays_only) | ||
|
||
@staticmethod | ||
def file_exists(filename): | ||
if os.path.exists(filename): | ||
print('Note: Diary \'' + filename + '\' already exists. Will not be modified.') | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import sys | ||
from . import Diary | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Create markdown diary file templates.") | ||
parser.add_argument("when", help="Generate a diary file for the given month or year. e.g. 2018 or 2018-12", | ||
type=str) | ||
parser.add_argument("-w", "--weekdays", help="Only include weekdays in the produced file(s). (Excludes weekends).", action="store_true") | ||
|
||
if len(sys.argv) == 1: | ||
parser.print_help(sys.stderr) | ||
sys.exit(1) | ||
|
||
args = parser.parse_args() | ||
|
||
month = Diary.Diary.valid_month(args.when) | ||
year = Diary.Diary.valid_year(args.when) | ||
if month: | ||
Diary.Diary.create_month_file(month, args.weekdays) | ||
elif year: | ||
Diary.Diary.create_year_files(year, args.weekdays) | ||
else: | ||
print("Error: The value " + args.when + " is not a valid year/month combination") | ||
parser.print_help(sys.stderr) | ||
sys.exit(1) |
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
|
||
from setuptools import setup | ||
from os import path | ||
|
||
this_directory = path.abspath(path.dirname(__file__)) | ||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setup( | ||
name='markdown-diary', | ||
version='0.0.0', | ||
description="CLI tool to generate monthly diary files in simple Markdown format", | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
keywords='diary journal markdown cli', | ||
author='Jack Higgins', | ||
author_email='pypi@jackhiggins.ie', | ||
url='https://github.com/skhg/markdown-diary', | ||
packages=['py_markdown_diary'], | ||
entry_points={ | ||
'console_scripts': ['md-diary=py_markdown_diary.command_line:main'], | ||
}, | ||
install_requires=[ | ||
], | ||
tests_require=[ | ||
], | ||
license='MIT', | ||
classifiers=[ | ||
'Development Status :: 4 - Beta', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3.6']) |