Skip to content

Commit 535dfcb

Browse files
committed
inital commit
0 parents  commit 535dfcb

File tree

9 files changed

+228
-0
lines changed

9 files changed

+228
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Python Files
2+
/.venv/
3+
__pychache__/
4+
*.pyc
5+
6+
# Build files:
7+
/build/
8+
/dist/
9+
*.egg-info/
10+
.eggs
11+
*.egg

.pre-commit-config.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
repos:
3+
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.3.0
6+
hooks:
7+
- name: remove trailing whitespace
8+
id: trailing-whitespace
9+
- name: add newline to end of files
10+
id: end-of-file-fixer
11+
- name: sort requirements.txt
12+
id: requirements-txt-fixer
13+
14+
- repo: https://github.com/pycqa/isort
15+
rev: 5.10.1
16+
hooks:
17+
- name: sort python imports
18+
id: isort
19+
20+
- repo: https://github.com/psf/black
21+
rev: 22.6.0
22+
hooks:
23+
- name: re-format with black
24+
id: black
25+
language_version: python3
26+
27+
- repo: https://github.com/pycqa/flake8
28+
rev: 5.0.4
29+
hooks:
30+
- name: check syntax with flake8
31+
id: flake8
32+
33+
- repo: https://github.com/asottile/setup-cfg-fmt
34+
rev: v2.0.0
35+
hooks:
36+
- name: format setup.cfg
37+
id: setup-cfg-fmt
38+
args: [--include-version-classifiers]

LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT Licence
2+
3+
Copyright (c) 2022 Jan Wille
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# makeclean.py
3+
4+
A clean-up utility in python that removes files and folders. It is meant as a portable replacement for `rm -r` in `clean:` targets of makefiles, but
5+
can be used for other similar situations.
6+
7+
It accepts an arbitrary number of path-objects and removes them if they exist, while ignoring non-existent ones.
8+
9+
10+
## Install
11+
12+
Currently, the package is not release, so you have to install it from the repo.
13+
14+
Install via pip:
15+
16+
```bash
17+
pip install git+https://github.com/Cube707/python-makeclean
18+
```
19+
20+
21+
## Usage
22+
23+
You can use it directly from the terminal:
24+
25+
```bash
26+
makeclean foo.txt bar/
27+
```
28+
29+
But it gets really helpful if you use it as the `clean:` target of a makefile, making it fully portable:
30+
31+
```makefile
32+
TRASH = foo.txt bar/
33+
34+
clean:
35+
makeclean $(TRASH)
36+
```
37+
38+
Use `makeclean --help` for more details.
39+
40+
---
41+
42+
*Copyright 2022 Jan Wille*

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
click
2+
pre-commit
3+
wheel

setup.cfg

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[metadata]
2+
version = attr: makeclean.__version__
3+
description = remove lists of files and folders
4+
long_description = file: README.md
5+
long_description_content_type = text/markdown
6+
url = https://github.com/Cube707/python-makeclean
7+
author = Jan Wille
8+
author_email = [email protected]
9+
license = MIT
10+
license_files = LICENCE
11+
classifiers =
12+
Development Status :: 3 - Alpha
13+
Environment :: Console
14+
Intended Audience :: Developers
15+
License :: OSI Approved :: MIT License
16+
Programming Language :: Python :: 3
17+
Programming Language :: Python :: 3 :: Only
18+
Programming Language :: Python :: 3.10
19+
Topic :: Software Development :: Build Tools
20+
keywords =
21+
make
22+
makefiles
23+
cleanup
24+
project_urls =
25+
Download = https://pypi.org/project/makeclean/#files
26+
Bug Tracker = https://github.com/Cube707/python-makeclean/issues
27+
Source Code = https://github.com/Cube707/python-makeclean
28+
29+
[options]
30+
python_requires = >=3.10
31+
package_dir =
32+
= src
33+
install_requires =
34+
click
35+
setuptools
36+
wheel
37+
38+
[options.entry_points]
39+
console_scripts =
40+
makeclean = makeclean:main
41+
42+
[flake8]
43+
max-complexity = 12
44+
max-line-length = 88
45+
exclude =
46+
__pycache__/
47+
.git/
48+
.venv/
49+
50+
[isort]
51+
profile = black
52+
src_paths = src
53+
lines_after_imports = 2

setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from setuptools import setup
2+
3+
4+
setup(
5+
# name is here to make GitHubs dependency displayer happy
6+
name="makeclean"
7+
)

src/makeclean/__init__.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from os import PathLike, remove
2+
from os.path import exists, isdir
3+
from shutil import rmtree
4+
5+
import click
6+
7+
8+
__version__ = "0.0.1-dev0"
9+
10+
11+
@click.command()
12+
@click.help_option("--help", "-h")
13+
@click.option("--verbose", "-v", is_flag=True, default=False)
14+
@click.option("--version", "-V", is_flag=True, default=False)
15+
@click.argument("PATH", nargs=-1, type=click.Path())
16+
def main(path, verbose, version):
17+
"""This utility is meant for use in makefiles as the clean target or similar usecases.
18+
It takes an arbitray number of PATH objects and removes them if they exists.
19+
Folders will be remove recursivly."""
20+
if version:
21+
print(f"makeclean.py v{__version__}")
22+
return
23+
clean(path, verbose)
24+
25+
26+
def clean(path: list[str|PathLike], verbose=False):
27+
"""Removes all given Path-Objects, meaning files are deleted and
28+
directorys are removed recurlivly.
29+
30+
Args:
31+
`path` (list[str|PathLike]): List of Paths to delete.
32+
`verbose` (bool, optional): If set to `True`, prints informations to the screen.
33+
"""
34+
for p in path:
35+
if not exists(p):
36+
if verbose:
37+
click.echo(f'{click.style("skip", fg="yellow")}: {p}')
38+
continue
39+
if isdir(p):
40+
if not p.endswith("/"):
41+
p += "/"
42+
if verbose:
43+
click.echo(f'{click.style("dir", fg="bright_cyan")}: {p}')
44+
rmtree(p)
45+
else:
46+
if verbose:
47+
click.echo(f'{click.style("file", fg="blue")}: {p}')
48+
remove(p)

src/makeclean/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import main
2+
3+
4+
if __name__ == "__main__":
5+
main()

0 commit comments

Comments
 (0)