Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
delameter committed Sep 9, 2023
2 parents 0e87e65 + 951974e commit c4b4773
Show file tree
Hide file tree
Showing 14 changed files with 553 additions and 139 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ max_line_length = 120
tab_width = 4

[*.py]
max_line_length = 88
ij_visual_guides = 79,120
max_line_length = 100
ij_visual_guides = 88,100

[*.rst]
indent_size = 3
Expand Down
9 changes: 3 additions & 6 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
VERSION=0.0.0
PYPI_USERNAME=__token__
PYPI_PASSWORD= #api token for primary repo
PYPI_PASSWORD_DEV= #api token for dev repo
HOST_DEFAULT_PYTHON=/usr/bin/python3.10
PIPX_DEFAULT_PYTHON=/usr/bin/python3.10
VERSION=0.1.0
HATCH_INDEX_USER=__token__
HATCH_INDEX_AUTH= #api token for primary repo
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ dist-dev
venv
.coverage
docs/_build
coverage
.hatch
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) *CYR Aleksandr Shavykin
Copyright (c) 2023 Aleksandr Shavykin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
126 changes: 14 additions & 112 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
## *PROJECT_NAME ## *PROJECT_DESCRIPTION
## (C) *CYR ## A. Shavykin <0.delameter@gmail.com>
## es7s/pysuncalc ## Library for sun timings calculations
## (C) 2023 ## A. Shavykin <0.delameter@gmail.com>
##---------------------------##-------------------------------------------------------------
.ONESHELL:
.PHONY: help test docs

PROJECT_NAME = *PROJECT_NAME
PROJECT_NAME_PUBLIC = ${PROJECT_NAME}
PROJECT_NAME_PRIVATE = ${PROJECT_NAME}-test

HOST_DEFAULT_PYTHON ?= /usr/bin/python
VENV_PATH = venv
VENV_TMP_PATH = /tmp/venv
PROJECT_NAME = pysuncalc

DOTENV = .env
DOTENV_DIST = .env.dist
OUT_BUILD_RELEASE_PATH = dist
OUT_BUILD_DEV_PATH = dist-dev
OUT_DEPS_PATH = misc/depends
OUT_COVER_PATH = misc/coverage

include ${DOTENV_DIST}
-include ${DOTENV}
Expand All @@ -28,7 +19,6 @@ NOW := $(shell date '+%Y-%b-%0e.%H%M%S.%3N')
BOLD := $(shell tput -Txterm bold)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
BLUE := $(shell tput -Txterm setaf 4)
DIM := $(shell tput -Txterm dim)
RESET := $(shell printf '\e[m')
# tput -Txterm sgr0 returns SGR-0 with
Expand All @@ -38,48 +28,11 @@ RESET := $(shell printf '\e[m')
help: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v @fgrep | sed -Ee 's/^(##)\s?(\s*#?[^#]+)#*\s*(.*)/\1${YELLOW}\2${RESET}#\3/; s/(.+):(#|\s)+(.+)/## ${GREEN}\1${RESET}#\3/; s/\*(\w+)\*/${BOLD}\1${RESET}/g; 2~1s/<([*<@>.A-Za-z0-9_-]+)>/${DIM}\1${RESET}/gi' -e 's/(\x1b\[)33m#/\136m/' | column -ts# | sed -Ee 's/ {3}>/ >/'

environment: ## Show environment vars used by this Makefile
@echo HOST_DEFAULT_PYTHON=${HOST_DEFAULT_PYTHON}
echo OUT_BUILD_DEV_PATH=${PWD}/${OUT_BUILD_DEV_PATH}
echo OUT_BUILD_RELEASE_PATH=${PWD}/${OUT_BUILD_RELEASE_PATH}
echo OUT_COVER_PATH=${PWD}/${OUT_COVER_PATH}
echo OUT_DEPS_PATH=${PWD}/${OUT_DEPS_PATH}
echo PIPX_DEFAULT_PYTHON=${PIPX_DEFAULT_PYTHON}
echo VENV_PATH=${PWD}/${VENV_PATH}

init: ## Replace placeholders throughout the skeleton
./init.sh

reinit-venv: ## > Prepare environment for module building <venv>
rm -vrf ${VENV_PATH}
if [ ! -f .env.build ] ; then cp -u ${DOTENV_DIST} ${DOTENV} && sed -i -Ee '/^VERSION=/d' ${DOTENV} ; fi
${HOST_DEFAULT_PYTHON} -m venv ${VENV_PATH}
${HOST_DEFAULT_PYTHON} -m pip install pipx
${VENV_PATH}/bin/pip install -r requirements.txt -r requirements-dev.txt

all: ## Prepare, run tests, generate docs and reports, build module
all: reinit-build test coverage build


##
## Pre-build

freeze: ## Actualize the requirements.txt file(s)
mkdir -p ${VENV_TMP_PATH}
${HOST_DEFAULT_PYTHON} -m venv ${VENV_TMP_PATH}
${VENV_TMP_PATH}/bin/pip install -r requirements.txt
${VENV_TMP_PATH}/bin/pip freeze -r requirements.txt --all > requirements.txt.tmp
sed -i -Ee '/were added by pip/ s/.+//' requirements.txt.tmp
mv requirements.txt.tmp requirements.txt
rm -vrf ${VENV_TMP_PATH}

freeze-dev: ## Actualize the requirements-dev.txt file(s) <venv>
${VENV_PATH}/bin/pip freeze -r requirements-dev.txt --all --exclude-editable > requirements-dev.txt.tmp
sed -i -Ee '/were added by pip/ s/.+//' requirements-dev.txt.tmp
mv requirements-dev.txt.tmp requirements-dev.txt

demolish-build: ## Delete build output folders
rm -f -v ${OUT_BUILD_RELEASE_PATH}/* ${PROJECT_NAME_PUBLIC}.egg-info/* ${PROJECT_NAME_PRIVATE}.egg-info/*
rm -f -v ${OUT_BUILD_RELEASE_PATH}/*

show-version: ## Show current package version
@echo "Current version: ${YELLOW}${VERSION}${RESET}"
Expand All @@ -88,83 +41,32 @@ set-version: ## Set new package version
set-version: show-version
@read -p "New version (press enter to keep current): " VERSION
if [ -z $$VERSION ] ; then echo "No changes" && return 0 ; fi
sed -E -i "s/^VERSION.+/VERSION=$$VERSION/" ${DOTENV_DIST}
sed -E -i "s/^version.+/version = $$VERSION/" setup.cfg
sed -E -i "s/^VERSION.+/VERSION=$$VERSION/" ${DOTENV_DIST} ${DOTENV}
sed -E -i "s/^__version__.+/__version__ = \"$$VERSION\"/" ${PROJECT_NAME}/_version.py
echo "Updated version: ${GREEN}$$VERSION${RESET}"

depends: ## Build and display module dependency graph
rm -vrf ${OUT_DEPS_PATH}
mkdir -p ${OUT_DEPS_PATH}
./pydeps.sh ${VENV_PATH}/bin/pydeps ${PROJECT_NAME} ${OUT_DEPS_PATH}

purge-cache: ## Clean up pycache
find . -type d \( -name __pycache__ -or -name .pytest_cache \) -print -exec rm -rf {} +

##
## Testing

test: ## Run pytest
${VENV_PATH}/bin/pytest tests
hatch run test:test

test-verbose: ## Run pytest with detailed output
${VENV_PATH}/bin/pytest tests -v

test-debug: ## Run pytest with VERY detailed output
${VENV_PATH}/bin/pytest tests -v --log-file-level=DEBUG --log-file=logs/testrun.${NOW}.log
if command -v bat &>/dev/null ; then bat logs/testrun.${NOW}.log -n --wrap=never ; else less logs/testrun.${NOW}.log ; fi

coverage: ## Run coverage and make a report
rm -vrf ${OUT_COVER_PATH}
${VENV_PATH}/bin/python -m coverage run tests -vv
${VENV_PATH}/bin/coverage report
${VENV_PATH}/bin/coverage html
if [ -n $$DISPLAY ] ; then xdg-open ${OUT_COVER_PATH}/index.html ; fi
cover: ## Run coverage and make a report
hatch run test:cover

##
## Building / Packaging
### local

reinstall-local: ## > (Re)install as editable, inject latest deps <pipx>
@pipx uninstall ${PROJECT_NAME}
pipx install ${PROJECT_NAME} --pip-args="-e ."

### dev

build-dev: ## Create new private build <*-test>
build-dev: demolish-build
sed -E -i "s/^name.+/name = ${PROJECT_NAME_PRIVATE}/" setup.cfg
${VENV_PATH}/bin/python -m build --outdir ${OUT_BUILD_DEV_PATH}
sed -E -i "s/^name.+/name = ${PROJECT_NAME_PUBLIC}/" setup.cfg

upload-dev: ## Upload last private build (=> dev registry)
${VENV_PATH}/bin/twine \
upload \
--repository testpypi \
-u ${PYPI_USERNAME} \
-p ${PYPI_PASSWORD_DEV} \
--verbose \
${OUT_BUILD_DEV_PATH}/*

install-dev: ## Install latest private build from dev registry
pipx uninstall ${PROJECT_NAME_PRIVATE}
pipx install ${PROJECT_NAME_PRIVATE}==${VERSION} --pip-args="-i https://test.pypi.org/simple/"

### release

build: ## Create new *public* build
build: demolish-build
${VENV_PATH}/bin/python -m build

upload: ## Upload last *public* build (=> PRIMARY registry)
${VENV_PATH}/bin/twine \
upload \
-u ${PYPI_USERNAME} \
-p ${PYPI_PASSWORD} \
--verbose \
${OUT_BUILD_RELEASE_PATH}/*

install: ## > Install latest *public* build from PRIMARY registry
pipx install ${PROJECT_NAME_PUBLIC}
hatch --verbose -e build build

publish: ## Upload last *public* build (=> PRIMARY registry)
hatch --verbose -e build publish \
-u ${HATCH_INDEX_USER} \
-a ${HATCH_INDEX_AUTH}

##
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="https://user-images.githubusercontent.com/50381946/167810957-14b78013-00cf-436e-b535-d2b89f881c44.png">
<br>
<code>
*PROJECT_NAME
pysuncalc
</code>
<br>
</h1>
Expand All @@ -27,7 +27,7 @@ Morbi semper metus at egestas vulputate:

## Installation

pipx install *PROJECT_NAME
pipx install pysuncalc

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.

Expand Down
19 changes: 19 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ==============================================================================
# es7s/pysuncalc [Library for sun timings calculations]
# (c) 2023. A. Shavykin <0.delameter@gmail.com>
# Licensed under MIT License
# ==============================================================================
""" file responsible for doctest running and custom shared fixtures """

from doctest import ELLIPSIS

from sybil import Sybil
from sybil.parsers.codeblock import PythonCodeBlockParser
from sybil.parsers.doctest import DocTestParser

pytest_plugins = []

pytest_collect_file = Sybil(
parsers=[DocTestParser(optionflags=ELLIPSIS), PythonCodeBlockParser()],
patterns=["*.rst", "*.py"],
).pytest()
18 changes: 9 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

# -- Project information ------------------------------------------------------

project = '*PROJECT_NAME'
copyright = '*CYR, Alexandr Shavykin'
project = 'pysuncalc'
copyright = '2023, Alexandr Shavykin'
author = 'Alexandr Shavykin'
show_authors = True

github_repository = '*PROJECT_NAME'
github_repository = 'pysuncalc'
github_branch = 'master'

import *PROJECT_NAME
version = *PROJECT_NAME.__version__
import pysuncalc
version = pysuncalc.__version__
release = version

# -- General configuration ----------------------------------------------------
Expand All @@ -48,9 +48,9 @@
html_theme = 'furo'

if len(version) > 5:
html_title = f'*PROJECT_NAME<br>{version}'
html_title = f'pysuncalc<br>{version}'
else:
html_title = f'*PROJECT_NAME {version}'
html_title = f'pysuncalc {version}'

html_static_path = ['_static']
html_css_files = ['custom.css', 'custom-furo.css']
Expand All @@ -62,7 +62,7 @@
"footer_icons": [
{
"name": "pypi",
"url": "https://pypi.org/project/*PROJECT_NAME",
"url": "https://pypi.org/project/pysuncalc",
"html": """
<svg width="8.3862762mm" height="7.9437408mm" viewBox="0 0 8.3862762 7.9437408" version="1.1">
<g transform="translate(-70.327089,-65.242521)"><g transform="matrix(0.26458333,0,0,0.26458333,-104.4515,-52.03226)">
Expand All @@ -76,7 +76,7 @@
},
{
"name": "github",
"url": "*PROJECT_URL",
"url": "https://github.com/es7s/pysuncalc",
"html": """
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
Expand Down
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

.. default-role:: any

.. title:: *PROJECT_NAME
.. title:: pysuncalc

=====================
*PROJECT_NAME
pysuncalc
=====================

*PROJECT_DESCRIPTION
Python port of JS library SunCalc

.. toctree::
:maxdepth: 3
Expand Down
Loading

0 comments on commit c4b4773

Please sign in to comment.