Skip to content

Commit

Permalink
Defineif initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hakancelikdev committed Nov 24, 2022
1 parent 64abe71 commit 3fc9a96
Show file tree
Hide file tree
Showing 28 changed files with 460 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
## Review the Contributing Guidelines
Before submitting a pull request, verify it meets all requirements in the
[Contributing Guidelines](https://github.com/hakancelikdev/{{project-name}}/blob/main/docs/contributing.md).
[Contributing Guidelines](https://github.com/hakancelikdev/defineif/blob/main/docs/contributing.md).
-->
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- stable
jobs:
deploy:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
Expand All @@ -16,8 +16,10 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -I .[docs]
python -m pip install .[docs]
- name: Build Docs
run: |
git fetch --all
git config --local user.email "[email protected]"
git config --local user.name "Hakan Celik"
git fetch --all
mkdocs gh-deploy -m "Update Docs" --remote-branch gh-pages
15 changes: 15 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: pre-commit
on: [push, pull_request]
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Install dependencies for pre-commit
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: pre-commit
run: |
tox -e pre-commit
21 changes: 0 additions & 21 deletions .github/workflows/publish.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: publish-package-on-pypi
on:
push:
tags:
- "**"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: "3.8"
architecture: "x64"

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build
- run: python -m build
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
verbose: true

publish:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: "3.8"
architecture: "x64"

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade build
- run: python -m build
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true
25 changes: 8 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Test
name: test
on: [push, pull_request]
jobs:
build:
run:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10"]
os: [ubuntu-latest, macos-latest]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/[email protected]

Expand All @@ -16,19 +16,10 @@ jobs:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install Dependencies
- name: Install Dependencies for Python${{ matrix.python-version }}
run: |
python -m pip install --upgrade pip
python -m pip install -I .[tests]
- name: Test with pytest
run: |
python -m pytest tests -v
- name: Generate coverage report
python -m pip install tox
- name: Test with pytest for Python${{ matrix.python-version }}
run: |
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{secrets.CODECOV_TOKEN }}
tox -e ${{ matrix.python-version }}
22 changes: 8 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,36 @@

repos:
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.10.0
hooks:
- id: black
args: [--line-length=79]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/hakancelikdev/unimport
rev: 0.9.6
rev: 0.12.2
hooks:
- id: unimport
args: [--remove, --include-star-import]

- repo: https://github.com/myint/docformatter
rev: v1.4
rev: v1.5.0
hooks:
- id: docformatter
args: [--in-place]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.961
rev: v0.991
hooks:
- id: mypy
args: [--no-strict-optional, --ignore-missing-imports, --show-error-codes]
additional_dependencies: [types-toml==0.1.3]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
exclude: tests/

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
rev: v3.0.0-alpha.4
hooks:
- id: prettier
args: [--prose-wrap=always, --print-width=88]
Expand All @@ -51,7 +45,7 @@ repos:
files: "\\.(py|.txt|.yaml|.json|.in|.md|.toml|.cfg|.html|.yml)$"

- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
rev: v3.2.2
hooks:
- id: pyupgrade
args: [--py38-plus]
args: [--py36-plus]
7 changes: 0 additions & 7 deletions .pre-commit-hooks.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include LICENSE
include MANIFEST.in
include *.md
graft {{project-name}}
graft defineif
graft docs
graft tests
global-exclude __pycache__
Expand Down
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
install:
pip install -e .[tests]

lint:
git add .
pre-commit run --all-files

test:
pytest tests -x -v --disable-warnings

clean:
rm -rf `find . -name __pycache__`
rm -f `find . -type f -name '*.py[co]' `
rm -f `find . -type f -name '*~' `
rm -f `find . -type f -name '.*~' `
rm -rf .cache
rm -rf .pytest_cache
rm -rf .mypy_cache
rm -rf htmlcov
rm -rf *.egg-info
rm -f .coverage
rm -f .coverage.*
rm -rf .tox
rm -rf build

push:
git push origin head

amend:
git add .
git commit --amend --no-edit
git push origin head -f

stable:
git checkout main
git branch -D stable
git checkout -b stable
git push origin head -f
git checkout main
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
# {{project-name}}
# Define If

**If the condition is true, define the method.**

[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/hakancelikdev/defineif/main.svg)](https://results.pre-commit.ci/latest/github/hakancelikdev/defineif/main)
[![test](https://github.com/hakancelikdev/defineif/actions/workflows/tests.yml/badge.svg)](https://github.com/hakancelikdev/defineif/actions/workflows/tests.yml)
[![build-docs](https://github.com/hakancelikdev/defineif/actions/workflows/docs.yml/badge.svg)](https://github.com/hakancelikdev/defineif/actions/workflows/docs.yml)
[![publish-package-on-pypi](https://github.com/hakancelikdev/defineif/actions/workflows/pypi.yml/badge.svg)](https://github.com/hakancelikdev/defineif/actions/workflows/pypi.yml)

[![Pypi](https://img.shields.io/pypi/v/defineif)](https://pypi.org/project/defineif/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/defineif)
[![Downloads](https://static.pepy.tech/personalized-badge/defineif?period=total&units=international_system&left_color=grey&right_color=red&left_text=downloads)](https://pepy.tech/project/defineif)
[![License](https://img.shields.io/github/license/hakancelikdev/defineif.svg)](https://github.com/hakancelikdev/defineif/blob/main/LICENSE)

[![Forks](https://img.shields.io/github/forks/hakancelikdev/defineif)](https://github.com/hakancelikdev/defineif/fork)
[![Issues](https://img.shields.io/github/issues/hakancelikdev/defineif)](https://github.com/hakancelikdev/defineif/issues)
[![Stars](https://img.shields.io/github/stars/hakancelikdev/defineif)](https://github.com/hakancelikdev/defineif/stargazers)

[![Codecov](https://codecov.io/gh/hakancelikdev/defineif/branch/main/graph/badge.svg)](https://codecov.io/gh/hakancelikdev/defineif)
[![Contributors](https://img.shields.io/github/contributors/hakancelikdev/defineif)](https://github.com/hakancelikdev/defineif/graphs/contributors)
[![Last Commit](https://img.shields.io/github/last-commit/hakancelikdev/defineif.svg)](https://github.com/hakancelikdev/defineif/commits/main)

For more information see: https://defineif.hakancelik.dev/

## How to install ?

```
pip install defineif
```

## How to use it ?

```python
import os

from defineif import DefineIf


class Klass(DefineIf):

@staticmethod
@DefineIf(os.name == 'nt')
def get_platform():
return 'Windows'

@staticmethod
@DefineIf(os.name == 'posix')
def get_platform():
return 'Linux'

platform = Klass.get_platform()

print(platform)
```
38 changes: 38 additions & 0 deletions docs/CHANGLOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Changelog

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).

## [Unreleased] - YYYY-MM-DD

## [0.1.0] - 2022-11-24

### Added

- DefineIf class implemented, we can now use it via inheritance and decorators. For
example:

```python
import os

from defineif import DefineIf


class Klass(DefineIf):

@staticmethod
@DefineIf(os.name == 'nt')
def get_platform():
return 'Windows'

@staticmethod
@DefineIf(os.name == 'posix')
def get_platform():
return 'Linux'

platform = Klass.get_platform()

print(platform)
```
2 changes: 1 addition & 1 deletion docs/CNAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{project-name}}.hakancelik.dev
defineif.hakancelik.dev
2 changes: 1 addition & 1 deletion docs/authors.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Authors

- Hakan Çelik (@hakancelikdev) <[email protected]>
- Hakan Çelik (@hakancelikdev) <[email protected]>

## Contributors

Expand Down
7 changes: 0 additions & 7 deletions docs/changelog.md

This file was deleted.

Loading

0 comments on commit 3fc9a96

Please sign in to comment.