Skip to content

Commit

Permalink
pyproject
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Mar 31, 2024
1 parent 57b44eb commit 66c9f47
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pip_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install uv environment
uses: andgineer/uv-venv@v1
- name: Install build dependencies
run: uv pip install build "setuptools>=46.4.0" --python=${{ env.PRIMARY_PYTHON_VERSION }}
run: uv pip install build --python=${{ env.PRIMARY_PYTHON_VERSION }}

- name: Build package
run: python -m build
Expand Down
27 changes: 14 additions & 13 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
Copyright (c) 2024 Andrey Sorokin <andrey@sorokin.engineer>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the Software), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!make
VERSION := $(shell cat src/audiobook_tags/version.py | cut -d= -f2 | sed 's/\"//g; s/ //')
VERSION := $(shell grep '__version__' src/audiobook_tags/__about__.py | cut -d '"' -f2)
export VERSION

.HELP: version ## Show the current version
Expand Down
35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[build-system]
requires = [ "hatchling",]
build-backend = "hatchling.build"

[project]
name = "audiobook-tags"
dynamic = [ "version",]
description = "Fix mp3 tags to use in iTunes/iPhone audiobooks."
keywords = [ "mp3", "tags", "audiobook", "itunes", "iphone",]
classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent",]
readme = "README.md"
requires-python = ">=3.8"
dependencies = [ "eyed3",]
[[project.authors]]
name = "Andrey Sorokin"
email = "andrey@sorokin.engineer"

[project.license]
file = "LICENSE.txt"

[project.urls]
Homepage = "https://andgineer.github.io/audiobook-tags/"
Documentation = "https://andgineer.github.io/audiobook-tags/"

[tool.setuptools]
packages = "find:"

[tool.setuptools.package-dir]
"" = "src"

[tool.setuptools.manifest]
include = [ "README.md", "LICENSE.txt",]

[tool.hatch.version]
path = "src/audiobook_tags/__about__.py"
6 changes: 4 additions & 2 deletions requirements.dev.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-r requirements.in

# test
pytest
pytest-cov
Expand All @@ -10,5 +12,5 @@ pre-commit

# build
-e .
pip-tools

hatchling
toml
26 changes: 10 additions & 16 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
-e .
astroid==3.0.1
# via pylint
build==1.0.3
# via pip-tools
certifi==2023.7.22
# via requests
cfgv==3.4.0
# via pre-commit
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via pip-tools
coverage==5.5
# via
# coveralls
Expand All @@ -33,6 +29,7 @@ filelock==3.13.1
# via virtualenv
filetype==1.2.0
# via eyed3
hatchling==1.22.4
identify==2.5.31
# via pre-commit
idna==3.4
Expand All @@ -50,22 +47,21 @@ nodeenv==1.8.0
# via pre-commit
packaging==23.1
# via
# build
# deprecation
# hatchling
# pytest
pip==24.0
# via pip-tools
pip-tools==7.3.0
pathspec==0.12.1
# via hatchling
platformdirs==3.11.0
# via
# pylint
# virtualenv
pluggy==1.3.0
# via pytest
# via
# hatchling
# pytest
pre-commit==3.5.0
pylint==3.0.2
pyproject-hooks==1.0.0
# via build
pytest==7.4.3
# via pytest-cov
pytest-cov==4.1.0
Expand All @@ -74,18 +70,16 @@ pyyaml==6.0.1
requests==2.31.0
# via coveralls
setuptools==69.2.0
# via
# nodeenv
# pip-tools
# via nodeenv
toml==0.10.2
# via coverage
tomlkit==0.12.3
# via pylint
trove-classifiers==2024.3.25
# via hatchling
typing-extensions==4.8.0
# via mypy
urllib3==2.1.0
# via requests
virtualenv==20.24.6
# via pre-commit
wheel==0.41.3
# via pip-tools
2 changes: 2 additions & 0 deletions scripts/compile_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ echo "Req‘s compilation time: $((REQS_TIME - $START_TIME)) seconds"
echo "Req‘s dev compilation time: $((END_TIME - REQS_TIME)) seconds"
echo "Total execution time: $((END_TIME - $START_TIME)) seconds"

# do not pin dependencies in the package
scripts/include_pyproject_requirements.py requirements.in
71 changes: 71 additions & 0 deletions scripts/include_pyproject_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
"""Include requirements.txt in pyproject.toml project.dependencies array.
Author: Andrey Sorokin
email: andrey@sorokin.engineer
url: https://github.com/andgineer
License: MIT
"""

import argparse

import toml

PROJECT_METADATA_FILE_NAME = "pyproject.toml"
REQUIREMENTS_FILE_NAME = "requirements.txt"


def main(requirements_file_name: str, section_path: str) -> None:
"""Include requirements.txt in pyproject.toml project.dependencies array."""
with open(requirements_file_name, "r", encoding="utf8") as f:
requirements = [
line.strip()
for line in f
if line.strip() and not line.lstrip().startswith("#")
]
print(
f"From {requirements_file_name} read requirements:"
f"\n{requirements[:10]}...\n...{len(requirements)} total"
)

with open(PROJECT_METADATA_FILE_NAME, "r", encoding="utf8") as f:
pyproject_data = toml.load(f)

section_keys = section_path.split(".")
target_section = pyproject_data
for key in section_keys:
target_section = target_section[key]

print(
f"To section `{section_path}` array `dependencies`"
f" of `{PROJECT_METADATA_FILE_NAME}`, project `{pyproject_data['project']['name']}`.\n"
)
target_section["dependencies"] = requirements

with open(PROJECT_METADATA_FILE_NAME, "w", encoding="utf8") as f:
toml.dump(pyproject_data, f)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
description="""Include dependencies from `requirements_file` into array `dependencies`
of pyproject.toml's section specified in `section_path`.
By default includes requirements.txt into `dependencies` array of section `project`.""",
)
parser.add_argument(
"requirements_file",
nargs="?",
default=REQUIREMENTS_FILE_NAME,
help="Input file with dependencies",
)
parser.add_argument(
"section_path",
nargs="?",
default="project",
help="Path to the section in pyproject.toml (e.g., tool.hatch.envs.test)",
)

args = parser.parse_args()
main(requirements_file_name=args.requirements_file, section_path=args.section_path)
2 changes: 1 addition & 1 deletion scripts/verup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# verup.sh release / feature / branch / ss
# (ss - to create snapshot version)

VERSION_FILES=("src/audiobook_tags/version.py")
VERSION_FILES=("src/audiobook_tags/__about__.py")

set -u # fail on unset variables
set -e # if any command fails, stop execution
Expand Down
5 changes: 0 additions & 5 deletions setup.cfg

This file was deleted.

36 changes: 0 additions & 36 deletions setup.py

This file was deleted.

1 change: 1 addition & 0 deletions src/audiobook_tags/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.2.8"
4 changes: 4 additions & 0 deletions src/audiobook_tags/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Audiobooks from mp3 with broken tags.
The file is mandatory for build system to find the package.
"""
1 change: 0 additions & 1 deletion src/audiobook_tags/version.py

This file was deleted.

0 comments on commit 66c9f47

Please sign in to comment.