Skip to content

Commit

Permalink
Split code in mltiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
inean committed Aug 11, 2024
1 parent d210407 commit 3502a11
Show file tree
Hide file tree
Showing 19 changed files with 927 additions and 758 deletions.
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ repos:
language: system
types: ["dockerfile"]
entry: hadolint

- repo: local
hooks:
- id: update-version
name: Update Version
entry: scripts/versioning.py
language: python
pass_filenames: false
stages: [commit]
files: ^pyproject\.toml$
additional_dependencies: [toml]
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -r requirements.lock
COPY src .

# Run the application:
ENTRYPOINT ["cloudflare-companion"]
ENTRYPOINT ["cloudflare_companion.py"]

# Use CMD to pass arguments to the application
CMD ["version"]
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ dev-dependencies = [
"pytest>=8.3.2",
"pytest-asyncio>=0.23.8",
"pytest-cov>=5.0.0",
"toml>=0.10.2",
]
managed = true
virtual = true

[tool.hatch.version]
path = "src/__about__.py"

[tool.pytest.ini_options]
pythonpath = [
"src",
Expand Down
63 changes: 63 additions & 0 deletions scripts/versioning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3

import argparse
import os
import sys

import toml

TOML_FILE = "pyproject.toml"
DATA_FILE = "src/__about__.py"


def update_version(toml_file=None, data_file=None):
# Get the current working directory
current_dir = os.getcwd()

# Compute the paths relative to the current working directory
toml_file = os.path.join(current_dir, toml_file or TOML_FILE)
data_file = os.path.join(current_dir, data_file or DATA_FILE)

# Ensure the files exist
if not os.path.exists(toml_file):
sys.stderr.write(f"Source file '{toml_file}' not found\n")
sys.exit(1)
if not os.path.exists(data_file):
sys.stderr.write(f"Destination File {data_file} not found\n")
sys.exit(1)

# Read the version from pyproject.toml
with open(toml_file, "r") as f:
pyproject_data = toml.load(f)
# Read the current contents of __about__.py
with open(data_file, "r") as f:
lines = f.readlines()

# Update the version in __about__.py
with open(data_file, "w") as f:
version = pyproject_data["project"]["version"]
for line in lines:
line = f'__version__ = "{version}"\n' if line.startswith("__version__") else line
f.write(line)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Update version in destination file from source file.",
)
parser.add_argument(
"--source",
type=str,
default=TOML_FILE,
help=f"PyProject file to read version from ({TOML_FILE})",
)
parser.add_argument(
"--target",
type=str,
default=DATA_FILE,
help=f"Python Destination file to update version in ({DATA_FILE})",
)
args = parser.parse_args()

update_version(toml_file=args.source, data_file=args.target)
update_version()
1 change: 1 addition & 0 deletions src/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
Loading

0 comments on commit 3502a11

Please sign in to comment.