init repository
This commit is contained in:
parent
202924df8a
commit
3f4557e547
0
.env.example
Normal file
0
.env.example
Normal file
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
.mypy_cache
|
||||
.ruff_cache
|
||||
.pypirc
|
||||
|
||||
__pycache__
|
||||
|
||||
dist
|
||||
|
||||
.env
|
||||
|
||||
venv
|
||||
25
Makefile
Normal file
25
Makefile
Normal file
@ -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
|
||||
51
build-deps.py
Normal file
51
build-deps.py
Normal file
@ -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")
|
||||
16
main.py
Normal file
16
main.py
Normal file
@ -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}")
|
||||
|
||||
52
pyproject.toml
Normal file
52
pyproject.toml
Normal file
@ -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"
|
||||
5
requirements-dev.txt
Normal file
5
requirements-dev.txt
Normal file
@ -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
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
requests==2.32.3
|
||||
python-dotenv==1.0.1
|
||||
1
src/__init__.py
Normal file
1
src/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
VERSION = "0.1.0"
|
||||
Loading…
x
Reference in New Issue
Block a user