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

Packaged for Pypi and Conda #1

Open
wants to merge 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store

# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python
Expand Down
21 changes: 0 additions & 21 deletions .semaphore/semaphore.yml

This file was deleted.

17 changes: 7 additions & 10 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
setup.cfg
setup.py
dateinfer/__init__.py
dateinfer/date_elements.py
dateinfer/examples.yaml
dateinfer/infer.py
dateinfer/ruleproc.py
dateinfer/tests.py
LICENSE
README.md
include *.in
include *.txt
include LICENSE
include Makefile
recursive-include docs *.md
recursive-include pydateinfer *.yaml
recursive-include pydateinfer *.py
94 changes: 94 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
.PHONY: clean clean-test clean-pyc clean-build docs help
.DEFAULT_GOAL := help

define BROWSER_PYSCRIPT
import os, webbrowser, sys

try:
from urllib import pathname2url
except:
from urllib.request import pathname2url

webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT

define PRINT_HELP_PYSCRIPT
import re, sys

for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT

BROWSER := python -c "$$BROWSER_PYSCRIPT"

help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts

clean-build: ## remove build artifacts
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +

clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +

clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache

lint: ## check style with flake8
flake8 pydateinfer tests

test: ## run tests quickly with the default Python
pytest

test-all: ## run tests on every Python version with tox
tox

coverage: ## check code coverage quickly with the default Python
coverage run --source pydateinfer -m pytest
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html

docs: ## generate Sphinx HTML documentation, including API docs
rm -f docs/pydateinfer.rst
rm -f docs/modules.rst
sphinx-apidoc -o docs/ pydateinfer
$(MAKE) -C docs clean
$(MAKE) -C docs html
$(BROWSER) docs/_build/html/index.html

servedocs: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .

release: dist ## package and upload a release
twine upload dist/*

dist: clean ## builds source and wheel package
#check-manifest --create
python setup.py sdist
python setup.py bdist_wheel
ls -l dist

install: clean ## install the package to the active Python's site-packages
python setup.py install

conda-build: clean ## package for anaconda
rm pydateinfer/meta.yaml
conda skeleton pypi py_dateinfer
conda build pydateinfer
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

$PYTHON setup.py install

# Add more build steps here, if they are necessary.

# See
# http://docs.continuum.io/conda/build.html
# for a list of environment variables that are set during the build process.
4 changes: 0 additions & 4 deletions dateinfer/__init__.py

This file was deleted.

4 changes: 4 additions & 0 deletions pydateinfer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__author__ = "jeffrey.starr@ztoztechnologies.com"
__version__ = "0.4.5"

from pydateinfer.infer import infer
52 changes: 32 additions & 20 deletions dateinfer/date_elements.py → pydateinfer/date_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytz

__author__ = 'jeffrey.starr@ztoztechnologies.com'
__author__ = "jeffrey.starr@ztoztechnologies.com"


class DateElement:
Expand All @@ -13,6 +13,7 @@ class DateElement:
Inheriting classes should implement a string 'directive' field that provides the relevant
directive for the datetime.strftime/strptime method.
"""

directive = None

def __eq__(self, other):
Expand All @@ -37,16 +38,17 @@ def is_numerical():
"""
Return true if the written representation of the element are digits
"""
raise NotImplementedError('is_numerical')
raise NotImplementedError("is_numerical")


class AMPM(DateElement):
"""AM | PM"""
directive = '%p'

directive = "%p"

@staticmethod
def is_match(token):
return token in ('AM', 'PM', 'am', 'pm')
return token in ("AM", "PM", "am", "pm")

@staticmethod
def is_numerical():
Expand All @@ -56,7 +58,7 @@ def is_numerical():
class DayOfMonth(DateElement):
"""1 .. 31"""

directive = '%d'
directive = "%d"

@staticmethod
def is_match(token):
Expand All @@ -78,7 +80,7 @@ class Filler(DateElement):
"""

def __init__(self, filler):
self.directive = filler.replace('%', '%%') # escape %
self.directive = filler.replace("%", "%%") # escape %

@staticmethod
def is_match(_):
Expand All @@ -91,7 +93,8 @@ def is_numerical():

class Hour12(DateElement):
"""1 .. 12 (zero padding accepted)"""
directive = '%I'

directive = "%I"

@staticmethod
def is_match(token):
Expand All @@ -108,7 +111,8 @@ def is_numerical():

class Hour24(DateElement):
"""00 .. 23"""
directive = '%H'

directive = "%H"

@staticmethod
def is_match(token):
Expand All @@ -125,7 +129,8 @@ def is_numerical():

class Minute(DateElement):
"""00 .. 59"""
directive = '%M'

directive = "%M"

@staticmethod
def is_match(token):
Expand All @@ -143,7 +148,7 @@ def is_numerical():
class MonthNum(DateElement):
"""1 .. 12"""

directive = '%m'
directive = "%m"

@staticmethod
def is_match(token):
Expand All @@ -163,7 +168,8 @@ class MonthTextLong(DateElement):

Uses calendar.month_name to provide localization
"""
directive = '%B'

directive = "%B"

@staticmethod
def is_match(token):
Expand All @@ -179,7 +185,8 @@ class MonthTextShort(DateElement):

Uses calendar.month_abbr to provide localization
"""
directive = '%b'

directive = "%b"

@staticmethod
def is_match(token):
Expand All @@ -195,7 +202,8 @@ class Second(DateElement):

Normally, seconds range from 0 to 59. In the case of a leap second, the second value may be 60.
"""
directive = '%S'

directive = "%S"

@staticmethod
def is_match(token):
Expand All @@ -212,7 +220,8 @@ def is_numerical():

class Timezone(DateElement):
"""IANA common timezones (e.g. UTC, EST, US/Eastern, ...)"""
directive = '%Z'

directive = "%Z"

@staticmethod
def is_match(token):
Expand All @@ -225,7 +234,8 @@ def is_numerical():

class UTCOffset(DateElement):
"""UTC offset +0400 -1130"""
directive = '%z'

directive = "%z"

@staticmethod
def is_match(token):
Expand All @@ -234,7 +244,7 @@ def is_match(token):
# but python apparently only uses the +/-hhmm format
# A rule will catch the preceding + and - and combine the two entries since punctuation and
# numbers are separated by the tokenizer.
offset_re = r'^\d\d\d\d$'
offset_re = r"^\d\d\d\d$"
return re.match(offset_re, token)

@staticmethod
Expand All @@ -247,7 +257,8 @@ class WeekdayLong(DateElement):

Uses calendar.day_name to provide localization
"""
directive = '%A'

directive = "%A"

@staticmethod
def is_match(token):
Expand All @@ -259,7 +270,8 @@ class WeekdayShort(DateElement):

Uses calendar.day_abbr to provide localization
"""
directive = '%a'

directive = "%a"

@staticmethod
def is_match(token):
Expand All @@ -273,7 +285,7 @@ def is_numerical():
class Year2(DateElement):
"""00 .. 99"""

directive = '%y'
directive = "%y"

@staticmethod
def is_match(token):
Expand All @@ -293,7 +305,7 @@ def is_numerical():
class Year4(DateElement):
"""0000 .. 9999"""

directive = '%Y'
directive = "%Y"

@staticmethod
def is_match(token):
Expand Down
File renamed without changes.
Loading