Skip to content

Commit 3e732cf

Browse files
authored
🧙‍♂️Mischief managed / Initial Setup (#1)
1 parent efadc38 commit 3e732cf

File tree

15 files changed

+172
-208
lines changed

15 files changed

+172
-208
lines changed

.github/workflows/python-publish.yml

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,57 @@
55
# This workflow uploads a Python Package using Twine when a release is created.
66
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
77

8-
# name: Upload Python Package
8+
name: Upload Python Package
99

10-
# on:
11-
# release:
12-
# types: [created, edited]
10+
on:
11+
release:
12+
types: [ created, edited ]
1313

14-
# jobs:
15-
# tests:
16-
# if: startsWith(github.ref, 'refs/tags/v')
17-
# runs-on: ${{ matrix.os }}
18-
# strategy:
19-
# matrix:
20-
# python-version: ["3.12"]
21-
# os: [ubuntu-latest]
22-
# steps:
23-
# - uses: actions/checkout@v4
24-
# - name: Set up Python ${{ matrix.python-version }}
25-
# uses: actions/setup-python@v5
26-
# with:
27-
# python-version: ${{ matrix.python-version }}
28-
# - name: Install tox
29-
# run: |
30-
# python -m pip install --upgrade pip
31-
# pip install tox
32-
# - name: Run tox
33-
# run: |
34-
# tox
35-
36-
# build-n-publish:
37-
# name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
38-
# runs-on: ubuntu-latest
39-
# # Specifying a GitHub environment, # Specifying a GitHub environment, which is strongly recommended by PyPI: https://docs.pypi.org/trusted-publishers/adding-a-publisher/
40-
# # you have to create an environment in your repository settings and add the environment name here
41-
# environment: release
42-
# permissions:
43-
# # IMPORTANT: this permission is mandatory for trusted publishing
44-
# id-token: write
45-
# needs: tests
46-
# steps:
47-
# - uses: actions/checkout@v4
48-
# - name: Set up Python
49-
# uses: actions/setup-python@v5
50-
# with:
51-
# python-version: ${{ matrix.python-version }}
52-
# - name: Install dependencies
53-
# run: |
54-
# python -m pip install --upgrade pip
55-
# pip install -r dev_requirements/requirements-packaging.txt
56-
# - name: Build wheel and source distributions
57-
# run: |
58-
# python -m build
59-
# - name: Publish distribution 📦 to PyPI
60-
# if: startsWith(github.ref, 'refs/tags/v')
61-
# uses: pypa/gh-action-pypi-publish@release/v1
14+
jobs:
15+
tests:
16+
if: startsWith(github.ref, 'refs/tags/v')
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
python-version: [ "3.12" ]
21+
os: [ ubuntu-latest ]
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
- name: Install tox
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install tox
32+
- name: Run tox
33+
run: |
34+
tox
6235
36+
build-n-publish:
37+
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
38+
runs-on: ubuntu-latest
39+
# Specifying a GitHub environment, # Specifying a GitHub environment, which is strongly recommended by PyPI: https://docs.pypi.org/trusted-publishers/adding-a-publisher/
40+
# you have to create an environment in your repository settings and add the environment name here
41+
environment: release
42+
permissions:
43+
# IMPORTANT: this permission is mandatory for trusted publishing
44+
id-token: write
45+
needs: tests
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Set up Python
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install -r dev_requirements/requirements-packaging.txt
56+
- name: Build wheel and source distributions
57+
run: |
58+
python -m build
59+
- name: Publish distribution 📦 to PyPI
60+
if: startsWith(github.ref, 'refs/tags/v')
61+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/unittests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ${{ matrix.os }}
1010
strategy:
1111
matrix:
12-
python-version: ["3.11", "3.12"]
12+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1313
os: [ubuntu-latest]
1414
steps:
1515
- uses: actions/checkout@v4

README.md

Lines changed: 38 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,57 @@
1-
# Python Template Repository including a `tox.ini`, Unittests&Coverage, Pylint & MyPy Linting Actions and a PyPI Publishing Workflow
1+
# Chronomeleon
2+
🚧 Still Work In Progress!
23

3-
<!--- you need to replace the `organization/repo_name` in the status badge URLs --->
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5+
![Python Versions (officially) supported](https://img.shields.io/pypi/pyversions/chronomeleon.svg)
6+
![Pypi status badge](https://img.shields.io/pypi/v/chronomeleon)
7+
![Unittests status badge](https://github.com/Hochfrequenz/chronomeleon/workflows/Unittests/badge.svg)
8+
![Coverage status badge](https://github.com/Hochfrequenz/chronomeleon/workflows/Coverage/badge.svg)
9+
![Linting status badge](https://github.com/Hochfrequenz/chronomeleon/workflows/Linting/badge.svg)
10+
![Black status badge](https://github.com/Hochfrequenz/chronomeleon/workflows/Formatting/badge.svg)
411

5-
![Unittests status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Unittests/badge.svg)
6-
![Coverage status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Coverage/badge.svg)
7-
![Linting status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Linting/badge.svg)
8-
![Black status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Formatting/badge.svg)
12+
Chronomeleon is a Python package that converts date and time related objects in migration scenarios.
13+
It's meant to be used when migrate dates, datetimes or time slices/ranges from one system to another.
914

10-
This is a template repository.
11-
It doesn't contain any useful code but only a minimal working setup for a Python project including:
15+
## Rationale
16+
While converting a datetime alone is possible with either Python builtin tools or libraries like `pendulum` and `arrow`,
17+
things become more complicated when you have to convert time slices or ranges or when the source and target system interpret dates and times differently.
1218

13-
- a basic **project structure** with
14-
- tox.ini
15-
- `pyproject.toml` where the project metadata and dependencies are defined
16-
- and a requirements.txt derived from it
17-
- an example class
18-
- an example unit test (using pytest)
19-
- ready to use **Github Actions** for
20-
- [pytest](https://pytest.org)
21-
- [code coverage measurement](https://coverage.readthedocs.io) (fails below 80% by default)
22-
- [pylint](https://pylint.org/) (only accepts 10/10 code rating by default)
23-
- [mypy](https://github.com/python/mypy) (static type checks where possible)
24-
- [black](https://github.com/psf/black) code formatter check
25-
- [isort](https://pycqa.github.io/isort/) import order check
26-
- [codespell](https://github.com/codespell-project/codespell) spell check (including an ignore list)
27-
- autoresolve dev-dependencies with `tox -e compile_requirements`
28-
- ready-to-use publishing workflow for pypi (see readme section below)
19+
Think your migrating e.g., contracts from system A to system B.
20+
In system A might have an API, a data dump or something else from where you can read,
21+
that a contract starts at `2024-01-01` and ends at `2024-06-30`.
2922

30-
By default, it uses Python version 3.12.
23+
Now assume, the same contract in system B starts at `2023-12-31T23:00:00Z` and ends at `2024-06-30T21:59:59Z`.
3124

32-
This repository uses a [`src`-based layout](https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/).
33-
This approach has many advantages and basically means for developers, that all business logic lives in the `src` directory.
25+
For this little conversion, although simple, you have to consider a lot:
26+
* Are date and times implicitly "meant" in any certain time zone? Here, system A seems to implicitly assume, everything as German local time, whereas system B uses explicit UTC offsets.
27+
* What about the resolution? Although using dates only might be sufficient for the modeling the business logic, as soon as the resolution of system B is higher, you have to start interpreting stuff.
28+
* What if there was a system C, which supported microseconds but only stored the date and time in a single integer?
29+
* What about the end date (times)? It seems that system A uses the end date as inclusive (contract ends at the end of june), whereas system B uses it as exclusive (start of the followup contract == end of the previous contract).
3430

35-
## How to use this Repository on Your Machine
31+
Chronomeleon has two purposes:
32+
1. It forces you to make assumptions explicit.
33+
2. Once the assumptions are explicit, it helps you do the conversion.
3634

37-
This introduction assumes that you have tox installed already (
38-
see [installation instructions](https://tox.readthedocs.io/en/latest/installation.html)) and that a `.toxbase` environment
39-
has been created.
40-
`.toxbase` is a project independent virtual environment-template for all the tox environments on your machine. If anything is weird during the tox installation or after the installation, try turning your computer off and on again before getting too frustrated.
35+
The latter is no rocket science (and neither is any code in chronomeleon), but the former is crucial for a successful migration.
4136

42-
### Powershell restrictions on Windows
43-
Also on new windows machines it is possible that the execution policy is set to restricted and you are not allowed execute scripts. You can find detailed information [here](https://learn.microsoft.com/de-de/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.3).
44-
45-
The quickest way to solve this problem: Open an Administrator Powershell (e.g. Windows PowerShell App)
46-
```ps
47-
Set-ExecutionPolicy -ExecutionPolicy AllSigned
48-
```
49-
and try again (with your regular user, not as admin).
50-
51-
### Creating the project-specifc dev environment.
52-
If all problems are solved and you're ready to start:
53-
1. clone the repository, you want to work in
54-
2. create the `dev` environment on your machine. To do this:
55-
a) Open a Powershell
56-
b) change directory to your repository
57-
and finally type
37+
Chronomeleon makes your code more readable and makes your assumption clear.
38+
This allows you to spot errors in your or your team mates code and explain, why things are done the way they are.
5839

40+
## How to use it?
41+
Install it from pypi:
5942
```bash
60-
tox -e dev
61-
```
62-
63-
You have now created the development environment (dev environment). It is the environment which contains both the usual requirements as well as the testing and linting tools.
64-
65-
### How to use with PyCharm
66-
67-
1. You have cloned the repository, you want to work in, and have created the virtual environment, in which the repository should be executed (`your_repo/.tox/dev`). Now, to actually work inside the newly created environment, you need to tell PyCharm (your IDE) that it should use the virtual environment - to be more precise: the interpreter of this dev environment. How to do this:
68-
a) navigate to: File ➡ Settings (Strg + Alt + S) ➡ Project: your_project ➡ Python Interpreter ➡ Add interpreter ➡ Existing
69-
b) Choose as interpreter: `your_repo\.tox\dev\Scripts\python.exe` (under windows)
70-
2. Set the default test runner of your project to pytest. How to do it:
71-
a) navigate to Files ➡ Settings ➡ Tools ➡ Python integrated tools ➡ Testing: Default test runner
72-
b) Change to "pytest"
73-
If this doesn't work anymore, see [the PyCharm docs](https://www.jetbrains.com/help/pycharm/choosing-your-testing-framework.html)
74-
3. Set the `src` directory as sources root. How to do this:
75-
right click on 'src' ➡ "Mark directory as…" ➡ sources root
76-
If this doesn't work anymore, see: [PyCharm docs](https://www.jetbrains.com/help/pycharm/content-root.html).
77-
Setting the `src` directory right, allows PyCharm to effectively suggest import paths.
78-
If you ever see something like `from src.mypackage.mymodule import ...`, then you probably forgot this step.
79-
5. Set the working directory of the unit tests to the project root (instead of the unittest directory). How to do this:
80-
a) Open any test file whose name starts with `test_` in unit tests/tests
81-
b) Right click inside the code ➡ More Run/Debug ➡ Modify Run Configuration ➡ expand Environment collapsible ➡ Working directory
82-
c) Change to `your_repo` instead of `your_repo\unittests`
83-
By doing so, the import and other file paths in the tests are relative to the repo root.
84-
If this doesn't work anymore, see: [working directory of the unit tests](https://www.jetbrains.com/help/pycharm/creating-run-debug-configuration-for-tests.html)
85-
86-
### How to use with VS Code
87-
All paths mentioned in this section are relative to the repository root.
88-
89-
1. Open the folder with VS Code.
90-
2. **Select the python interpreter** ([official docs](https://code.visualstudio.com/docs/python/environments#_manually-specify-an-interpreter)) which is created by tox. Open the command pallett with `CTRL + P` and type `Python: Select Interpreter`. Select the interpreter which is placed in `.tox/dev/Scripts/python.exe` under Windows or `.tox/dev/bin/python` under Linux and macOS.
91-
3. **Set up pytest and pylint**. Therefore we open the file `.vscode/settings.json` which should be automatically generated during the interpreter setup. If it doesn't exist, create it. Insert the following lines into the settings:
92-
93-
```json
94-
{
95-
"python.testing.unittestEnabled": false,
96-
"python.testing.nosetestsEnabled": false,
97-
"python.testing.pytestEnabled": true,
98-
"pythonTestExplorer.testFramework": "pytest",
99-
"python.testing.pytestArgs": ["unittests"],
100-
"python.linting.pylintEnabled": true
101-
}
102-
```
103-
104-
4. Create a `.env` file and insert the following line
105-
106-
For Windows:
107-
108-
```
109-
PYTHONPATH=src;${PYTHONPATH}
43+
pip install chronomeleon
11044
```
11145

112-
For Linux and Mac:
113-
114-
```
115-
PYTHONPATH=src:${PYTHONPATH}
46+
Then, in your code: Make assumptions about the source and target system explicit.
47+
To do so, chronomeleon provides you with so-called ChronoConfig objects.
48+
```python
11649
```
11750

118-
This makes sure, that the imports are working for the unittests.
119-
At the moment I am not totally sure that it is the best practise, but it's getting the job done.
120-
121-
5. Enjoy 🤗
12251

123-
## Publishing on PyPI
124-
125-
This repository contains all necessary CI steps to publish any project created from it on PyPI.
126-
It uses the trusted publishers workflow as described in the [official Python documentation](https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/).
127-
It just requires some manual adjustments/settings depending on your project:
128-
129-
1. Fill out the metadata in the [`pyproject.toml`](pyproject.toml); Namely the package name and the dependencies which should be in sync with your `requirements.in`.
130-
2. Uncomment the lines in [`.github/workflows/python-publish.yml`](.github/workflows/python-publish.yml)
131-
3. Create a [new environment in your GitHub repository](https://github.com/Hochfrequenz/python_template_repository/settings/environments) and call it `release`.
132-
4. Set up a new trusted publisher [in your PYPI account](https://pypi.org/manage/account/publishing/).
133-
1. PyPI Project Name: The name which you defined in the `pyproject.toml` is the name of the project which you have to enter here.
134-
2. Owner: The GitHub organization name or GitHub username that owns the repository
135-
3. Repository name: The name of the GitHub repository that contains the publishing workflow
136-
4. Workflow name: The filename of the publishing workflow. This file should exist in the .github/workflows/ directory in the repository configured above. Here in our case: `python-publish.yml`
137-
5. Environment name: The name of the GitHub Actions environment that the above workflow uses for publishing. Here in our case: `release`
138-
5. Now create a release by clicking on "Create new release" in the right Github sidebar (or visit `github.com/your-username/your-reponame/releases/new`). This should trigger the workflow (see the "Actions" tab of your repo).
139-
6. Check if the action failed. If it succeeded your PyPI account should now show the new project. It might take some minutes until the package can be installed via `pip install packagename` because the index has to be updated.
140-
7. Now create another PyPI token with limited scope and update the Github repository secret accordingly.
52+
## Setup for Local Development
53+
Follow the instructions from our [template repository](https://github.com/Hochfrequenz/python_template_repository?tab=readme-ov-file#how-to-use-this-repository-on-your-machine).
54+
tl;dr: `tox`.
14155

14256
## Contribute
143-
14457
You are very welcome to contribute to this template repository by opening a pull request against the main branch.
145-
146-
### GitHub Actions
147-
148-
- Dependabot auto-approve / -merge:
149-
- If the actor is the Dependabot bot (i.e. on every commit by Dependabot)
150-
the pull request is automatically approved and auto merge gets activated
151-
(using squash merge).
152-
Note that if you haven't enabled "auto merge" for your repository, the auto merge activation will fail.
153-
If you want to use a merge type other than "squash merge" you have to edit the workflow.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# specific requirements for the tox type_check environment
22
mypy
3+
types-pytz
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# SHA1:7983aaa01d64547827c20395d77e248c41b2572f
21
#
3-
# This file is autogenerated by pip-compile-multi
4-
# To update, run:
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
54
#
6-
# pip-compile-multi
5+
# pip-compile requirements-type_check.in
76
#
87
mypy==1.10.0
9-
# via -r dev_requirements/requirements-type_check.in
8+
# via -r requirements-type_check.in
109
mypy-extensions==1.0.0
1110
# via mypy
11+
types-pytz==2024.1.0.20240417
12+
# via -r requirements-type_check.in
1213
typing-extensions==4.10.0
1314
# via mypy

pyproject.toml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[project]
2-
name = "your-favourite-package-name"
3-
description = "Description of your package"
2+
name = "chronomeleon"
3+
description = "A python package to flexibly adapt start and end date(times) to your system background"
44
license = { text = "MIT" }
5-
requires-python = ">=3.11"
6-
authors = [{ name = "your name", email = "[email protected]" }]
7-
keywords = ["your", "important", "keywords"]
5+
requires-python = ">=3.8"
6+
authors = [{ name = "Hochfrequenz Unternehmensberatung GmbH", email = "[email protected]" }]
7+
keywords = ["date", "time", "conversion", "migration", "inclusive", "exclusive", "dateonly"]
88
classifiers = [
99
"Development Status :: 4 - Beta",
1010
"Environment :: Console",
@@ -13,19 +13,24 @@ classifiers = [
1313
"Operating System :: OS Independent",
1414
"Programming Language :: Python",
1515
"Programming Language :: Python :: 3 :: Only",
16+
"Programming Language :: Python :: 3.8",
17+
"Programming Language :: Python :: 3.9",
18+
"Programming Language :: Python :: 3.10",
1619
"Programming Language :: Python :: 3.11",
1720
"Programming Language :: Python :: 3.12",
1821
]
19-
dependencies = [] # add all the dependencies here
22+
dependencies = [
23+
"pytz"
24+
] # add all the dependencies here
2025
dynamic = ["readme", "version"]
2126

2227
[project.urls]
23-
Changelog = "https://github.com/Hochfrequenz/python_template_repository/releases"
24-
Homepage = "https://github.com/Hochfrequenz/python_template_repository"
28+
Changelog = "https://github.com/Hochfrequenz/chronomeleon/releases"
29+
Homepage = "https://github.com/Hochfrequenz/chronomeleon"
2530

2631
[tool.black]
2732
line-length = 120
28-
target_version = ["py311", "py312"]
33+
target_version = ["py38", "py39", "py310", "py311", "py312"]
2934

3035
[tool.isort]
3136
line_length = 120
@@ -52,7 +57,7 @@ fragments = [{ path = "README.md" }]
5257
source = "vcs"
5358

5459
[tool.hatch.build.hooks.vcs]
55-
version-file = "src/_your_package_version.py"
60+
version-file = "src/_chronomeleon_version.py"
5661
template = '''
5762
version = "{version}"
5863
'''

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
#
55
# pip-compile pyproject.toml
66
#
7+
pytz==2024.1
8+
# via chronomeleon (pyproject.toml)

src/chronomeleon/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Chronomeleon is a Python package that helps you to migrate datetimes from one system to another.
3+
"""

0 commit comments

Comments
 (0)