diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32ae762 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +.mypy_cache +.ruff_cache +.pypirc + +__pycache__ + +dist + +.env + +venv \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7d31afe --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) +PYTHON := $(ROOT_DIR)venv/bin/python + +install: + python3 -m venv venv + $(PYTHON) -m pip install -r requirements.txt + $(PYTHON) -m pip install -r requirements-dev.txt + +lint: + $(PYTHON) -m ruff check src --fix + +format: + $(PYTHON) -m ruff format src + +check-type: + $(PYTHON) -m mypy main.py src + +check: format lint check-type + +build: check + $(PYTHON) build-deps.py + $(PYTHON) -m hatch -v build -t wheel + +publish: build + $(PYTHON) -m twine upload --repository gitea dist/*.whl \ No newline at end of file diff --git a/build-deps.py b/build-deps.py new file mode 100644 index 0000000..e3a3a4b --- /dev/null +++ b/build-deps.py @@ -0,0 +1,51 @@ +import argparse +import os +import re + +DEPS_REGEX = "dependencies = \[[^\]]*\]" +PYPROJECT_FILENAME = "pyproject.toml" + +if __name__ == "__main__": + """ + build-deps retrieves all mandatory requirements in `requirements.txt` + and copies them in `pyproject.toml` dependencies list. + """ + parser = argparse.ArgumentParser() + parser.add_argument("-d", "--dry-run", action="store_true") + args = parser.parse_args() + + # read and store requirements + requirements: list[str] = [] + with open("requirements.txt", "r") as f: + for d in f.readlines(): + d = d.replace("\n", "") + if "#" in d: + d = d.split("#")[0].strip() + if "gdal" in d.lower(): + print("gdal specific system version") + continue + requirements.append(f'"{d}"') + + # format requirements for pryproject.toml + deps: str = "dependencies = [\n" + for dep in requirements: + deps += f"\t{dep},\n" + deps += "]" + + # get and replace the pyproject.toml content + content: str = "" + with open(PYPROJECT_FILENAME, "r") as f: + content = f.read() + content = re.sub(DEPS_REGEX, deps, content, 1) + + # write the new content in a temp file + with open(f"{PYPROJECT_FILENAME}.tmp", "w") as f: + f.write(content) + + # if not dry run, override the original pyproject.toml + if not args.dry_run: + try: + os.rename(f"{PYPROJECT_FILENAME}.tmp", PYPROJECT_FILENAME) + except Exception as e: + print(f"error occurred while overriding pyproject file: {e}") + os.remove(f"{PYPROJECT_FILENAME}.tmp") diff --git a/main.py b/main.py new file mode 100644 index 0000000..7040273 --- /dev/null +++ b/main.py @@ -0,0 +1,16 @@ +import logging +import sys + +from src import VERSION + + +stdout_handler = logging.StreamHandler(stream=sys.stdout) +logging.basicConfig( + format="[%(levelname)s] - %(asctime)s - %(message)s", + level=logging.INFO, + handlers=(stdout_handler,), +) + +if __name__ == "__main__": + logging.info(f"WhereIs client v{VERSION}") + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8b96326 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,52 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "whereis-client" +dynamic = ["version"] +description = "WhereIs API client library" +dependencies = [ + "requests==2.32.3", +] + +[tool.hatch.version] +path = "src/__init__.py" + +[tool.hatch.build.targets.wheel] +packages = ["src"] + +[tool.hatch.build.targets.sdist] +only-include = ["src"] + +[tool.hatch.build.targets.wheel.sources] +"src" = "whereis-client" + +[tool.ruff] +select = ["E", "F", "I"] +ignore = [] + +exclude = [ + ".git", + ".ruff_cache", + "venv", +] + +line-length = 88 + +target-version = "py310" + +[tool.ruff.mccabe] +max-complexity = 10 + +[tool.mypy] +exclude = [ + "venv", + "dist", + "twine-trusted.py" +] +ignore_missing_imports = true + +[tool.isort] +extend_skip = ["venv"] +profile = "black" diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..b23aff3 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,5 @@ +mypy===1.13.0 +ruff==0.8.3 +twine==6.0.1 +types-requests==2.32.0.20241016 +hatch==1.14.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1786051 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests==2.32.3 +python-dotenv==1.0.1 \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..1cf6267 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1 @@ +VERSION = "0.1.0"