diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f95128b..5dc195a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,3 +23,5 @@ jobs: run: python3 setup.py install --user - name: verify we can import run: python3 -c "from datemath import datemath; print(datemath('now-1d'))" + - name: verify our version + run: python3 -c "import datemath; print(datemath.__version__)" \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a4213dd..a9e9ed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [3.0.2] - 2024-08-27 +## [3.0.3] - 2024-09-12 +Please use 3.0.3 going forward! 3.0.2 has a breaking bug. + +### fixed +- Fix: issue where version wasnt getting populated +- Fix: move version out of `VERSION.txt` and into `datemath/_version.py` directly +- Fix: typos in CHANGELOG. Thank you @s00hyun! + +## [3.0.2] - 2024-09-11 ### added - Feat: Complete typing with strict type-checking [#43](https://github.com/nickmaccarthy/python-datemath/pull/43) Thank you @Avasam! +- Feat: Added `__version__` to verify the version of the module. +- Feat: Added Dockerfile and relevant verify.py to help with local development and testing + +### chore +- Chore: bumped modules in requirements.txt ### fixed - Fix: removed legacy-tests.py since we no longer support python2.x @@ -15,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix: renamed requirements-3.txt to requirements.txt to support python3 going forward - also modifed to `release.yaml` and `tests.yaml` workflows to support this - Fix: long_description should now show up in pypi https://github.com/nickmaccarthy/python-datemath/issues/33 +- Fix: move more pypi configurations to setup.cfg and out of setup.py + ## [3.0.1] - 2024-08-23 ### fixed @@ -26,7 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix: Bump certifi to latest: https://github.com/nickmaccarthy/python-datemath/pull/38 ### added - Feat: Typehint support: https://github.com/nickmaccarthy/python-datemath/issues/31 -- Feat: Revamed CHANGELOG.md to keepachangelog.org format +- Feat: Renamed CHANGELOG.md to keepachangelog.org format ### todo - todo: Fix pypi: https://github.com/nickmaccarthy/python-datemath/issues/33 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..551c3c5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use an official Python runtime as the base image +FROM python:3.9 + +# Set the working directory in the container +WORKDIR /app + +# Copy the contents of your project to the working directory +COPY . . + +# Install the required dependencies +RUN pip install -r requirements.txt + +# Run setup.py to install your module +RUN python3 setup.py install + +# Run your tests to ensure everything works as expected +RUN python3 -m unittest discover + +# Set the entrypoint command to run your module +CMD ["python3", "verify.py"] \ No newline at end of file diff --git a/LICENSE b/LICENSE index 8dada3e..cbff04e 100644 --- a/LICENSE +++ b/LICENSE @@ -178,7 +178,7 @@ APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" + boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright 2023 Chris Smith Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -199,3 +199,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index 32329a5..c4747a2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,4 @@ -include VERSION.txt include README.md include CHANGELOG.md include LICENSE -include requirements-3.txt \ No newline at end of file +include requirements.txt \ No newline at end of file diff --git a/Makefile b/Makefile index 91f7e43..6cb2c45 100644 --- a/Makefile +++ b/Makefile @@ -3,3 +3,11 @@ tests: python3 tests.py + +docker-build: + docker build -t python-datemath . + +docker-run: + docker run --rm python-datemath + +test-build: docker-build docker-run \ No newline at end of file diff --git a/RELEASE.md b/RELEASE.md index 88619e3..f91edea 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,5 +1,5 @@ # How to release * Create a new tag/release in github. -* Ensure new tag version matches VERSION.txt +* Ensure new tag version matches datemath/_version.py * Actions should take care of the rest diff --git a/VERSION.txt b/VERSION.txt deleted file mode 100644 index b502146..0000000 --- a/VERSION.txt +++ /dev/null @@ -1 +0,0 @@ -3.0.2 diff --git a/datemath/__init__.py b/datemath/__init__.py index cc2cb78..54ea156 100644 --- a/datemath/__init__.py +++ b/datemath/__init__.py @@ -1,4 +1,5 @@ from __future__ import annotations +from ._version import __version__ from datetime import datetime from typing import TYPE_CHECKING @@ -17,3 +18,12 @@ def dm(expr: str | int, **kwargs: Unpack[ParseParams]) -> Arrow: def datemath(expr: str | int, **kwargs: Unpack[ParseParams]) -> datetime: ''' does our datemath and returns a datetime object ''' return parse(expr, **kwargs).datetime + + +__all__ = [ + 'dm', + 'datemath', + 'parse', + 'DateMathException', + '__version__', +] \ No newline at end of file diff --git a/datemath/_version.py b/datemath/_version.py new file mode 100644 index 0000000..8d1c862 --- /dev/null +++ b/datemath/_version.py @@ -0,0 +1 @@ +__version__ = "3.0.3" diff --git a/datemath/helpers.py b/datemath/helpers.py index 3ea145b..f94a3e7 100644 --- a/datemath/helpers.py +++ b/datemath/helpers.py @@ -1,43 +1,3 @@ -''' -A basic utility module for parsing math like strings relating to dates - -This is inspired by Date Math features in elasticsearch and aims to replicate the same functionality for python. - -DateMath (datemath or dm) suppor addition, subtraction and rounding at various granularities of "units" (a map of units to their shorthand is below for reference). -Expressions can be chanied together and are read left to right. '+' and '-' denote addition and subtraction while '/' denotes 'round', in this case is a 'round down' or floor. -Round requires a unit (/d), while addition and subtraction require an integer value and a unit (+1d). Whitespace is not allowed in the expression. Absolute datetimes with datemath -can be made as well, with the datetime and datemath expressions delinated by '||' - example '2015-01-01||+1d' == '2015-01-02' - - -Maps: - -y or Y = 'year' -M = 'month' -m = 'minute' -d or D = 'day' -w = 'week' -h or H = 'hour' -s or S = 'second' - -Examples: - -Assuming our datetime is currently: '2016-01-01T00:00:00-00:00' - -Expression: Result: -now-1h 2015-12-31T23:00:00+00:00 -now-1y 2015-01-01T00:00:00+00:00 -now+1y+2d 2017-01-03T00:00:00+00:00 -now+12h 2016-01-01T12:00:00+00:00 -now+1d/d 2016-01-03T00:00:00+00:00 -+2h 2016-01-01T02:00:00+00:00 -+1h/h 2016-01-01T02:00:00+00:00 -now+1w/w 2016-01-11T00:00:00+00:00 -now/d+7d+12h 2016-01-08T12:00:00+00:00 -2016-01-01||+1d 2016-01-02T00:00:00+00:00 -2015-01-01||+2w 2015-01-15T00:00:00+00:00 - -''' - from __future__ import annotations import os @@ -250,8 +210,6 @@ def evaluate(expression: str, now: Arrow, timeZone: str = 'UTC', roundDown: bool if debug: print('\n\n') return now - - if __name__ == "__main__": if debug: print('NOW: {0}'.format(arrow.utcnow())) if debug: print('\n\n') diff --git a/requirements-3.txt b/requirements-3.txt deleted file mode 100644 index fa6d05c..0000000 --- a/requirements-3.txt +++ /dev/null @@ -1,33 +0,0 @@ -appdirs==1.4.3 -args==0.1.0 -arrow==1.2.3 -bleach==3.3.0 -certifi==2024.7.4 -chardet==3.0.4 -clint==0.5.1 -docutils==0.15.2 -freezegun==1.2.2 -idna==3.7 -linecache2==1.0.0 -mypy==1.7.1 -packaging==16.8 -pkginfo==1.4.2 -Pygments==2.15.0 -pyparsing==2.2.0 -python-dateutil==2.8.2 -pytz==2023.3 -readme-renderer==24.0 -requests==2.32.2 -requests-toolbelt==0.9.1 -six==1.10.0 -tqdm==4.66.3 -traceback2==1.4.0 -twine==2.0.0 -types-python-dateutil==2.8.19.20240311 -types-setuptools==73.0.0.20240822 -types-pytz==2023.3.1.1 -typing_extensions==4.7.1 -tzdata==2024.1 -urllib3==1.26.19 -webencodings==0.5.1 - diff --git a/requirements.txt b/requirements.txt index 33b01bd..6089176 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,29 +4,44 @@ arrow==1.2.3 bleach==3.3.0 certifi==2024.7.4 chardet==3.0.4 +charset-normalizer==3.3.2 clint==0.5.1 docutils==0.15.2 freezegun==1.2.2 idna==3.7 +importlib_metadata==8.4.0 +jaraco.classes==3.4.0 +jaraco.context==6.0.1 +jaraco.functools==4.0.2 +keyring==25.3.0 linecache2==1.0.0 +markdown-it-py==3.0.0 +mdurl==0.1.2 +more-itertools==10.4.0 mypy==1.7.1 -packaging==16.8 -pkginfo==1.4.2 +mypy-extensions==1.0.0 +nh3==0.2.18 +packaging==24.1 +pkginfo==1.10.0 Pygments==2.15.0 pyparsing==2.2.0 python-dateutil==2.8.2 pytz==2023.3 -readme-renderer==24.0 +readme_renderer==43.0 requests==2.32.2 requests-toolbelt==0.9.1 -six==1.10.0 +rfc3986==2.0.0 +rich==13.8.0 +setuptools==74.1.2 +six==1.16.0 tqdm==4.66.3 traceback2==1.4.0 -twine==2.0.0 +twine==5.1.1 types-python-dateutil==2.8.19.20240311 -types-setuptools==73.0.0.20240822 types-pytz==2023.3.1.1 +types-setuptools==73.0.0.20240822 typing_extensions==4.7.1 tzdata==2024.1 urllib3==1.26.19 webencodings==0.5.1 +zipp==3.20.1 diff --git a/setup.cfg b/setup.cfg index ac06c3e..5fb04a2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,11 +1,29 @@ [metadata] name = python-datemath description = "A python module to emulate the date math used in SOLR and Elasticsearch" +keywords = date math datemath elaticsearch solr long_description = file: README.md long_description_content_type = text/markdown author = Nick MacCarthy author_email = nickmaccarthy@gmail.com +license = Apache-2.0 +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Developers + Topic :: Software Development :: Build Tools + License :: OSI Approved :: Apache Software License + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 + Operating System :: OS Independent +[options] +python_requires = >=3.8 +install_requires = + arrow >= 1.0.3 [bdist_wheel] universal=1 diff --git a/setup.py b/setup.py index 169b06f..36b3376 100644 --- a/setup.py +++ b/setup.py @@ -8,17 +8,17 @@ from setuptools import setup, find_packages # To use a consistent encoding from codecs import open +import os from os import path +from typing import Dict here = path.abspath(path.dirname(__file__)) -# Get the long description from the README file -with open(path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = f.read() - long_description_content_type = "text/markdown" +version: Dict[str, str] = {} +with open(os.path.join(here, 'datemath', '_version.py')) as f: + exec(f.read(), version) + VERSION = version['__version__'] -with open(path.join(here, 'VERSION.txt'), encoding='utf-8') as fv: - version = fv.read() setup( name='python-datemath', @@ -26,51 +26,13 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version=version, - download_url = 'https://github.com/nickmaccarthy/python-datemath/tarball/{0}'.format(version), - - description='A python module to emulate the date math used in SOLR and Elasticsearch', - - long_description=long_description, - long_description_content_type='text/markdown', + version=VERSION, + download_url = 'https://github.com/nickmaccarthy/python-datemath/tarball/{0}'.format(VERSION), # The project's main homepage. url='https://github.com/nickmaccarthy/python-datemath', - # Author details - author='Nick MacCarthy', - author_email='nickmaccarthy@gmail.com', - - # Choose your license - license='Apache-2.0', - - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - # How mature is this project? Common values are - # 3 - Alpha - # 4 - Beta - # 5 - Production/Stable - 'Development Status :: 5 - Production/Stable', - - # Indicate who your project is intended for - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Build Tools', - - # Pick your license as you wish (should match "license" above) - 'Apache-2.0', - - # Specify the Python versions you support here. In particular, ensure - # that you indicate whether you support Python 2, Python 3 or both. - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - ], - - # What does your project relate to? - keywords='date math datemath elaticsearch solr', - # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). packages=find_packages(exclude=['contrib', 'docs', 'tests']), @@ -78,9 +40,6 @@ package_data={'': ['*']}, include_package_data=True, - # Alternatively, if you want to distribute just a my_module.py, uncomment - # this: - # py_modules=["my_module"], # List run-time dependencies here. These will be installed by pip when # your project is installed. For an analysis of "install_requires" vs pip's diff --git a/verify.py b/verify.py new file mode 100644 index 0000000..ec1cfdb --- /dev/null +++ b/verify.py @@ -0,0 +1,12 @@ +from datemath import datemath, __version__ + + + +print(f'datemath version is {__version__}') + + +print(f'Now is: {datemath("now")}') +print(f'1 hour was ago was: {datemath("now-1h")}') +print(f'1 week from now is {datemath("now+1w/w")}') +print(f'1 year from now is {datemath("+1y")}') +