From ea8b09c8397577a911673f90541ba74a32ae35e7 Mon Sep 17 00:00:00 2001 From: takunomi-build-bot Date: Mon, 7 Jul 2025 00:41:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Repository=20layout=20updated=20?= =?UTF-8?q?to=20latest=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit was automatically generated by [a script](https://gitfub.space/Jmaa/repo-manager) --- .gitea/workflows/python-package.yml | 35 +++++++--- .gitea/workflows/python-ruff.yml | 6 +- .gitea/workflows/python-test.yml | 6 +- .gitea/workflows/python-version-check.yml | 6 +- CONVENTIONS.md | 36 ++++++++++ LICENSE | 2 +- README.md | 35 ++++++++-- ruff.toml | 81 ++++++++++++++++++++++- setup.py | 27 ++++++-- 9 files changed, 207 insertions(+), 27 deletions(-) create mode 100644 CONVENTIONS.md mode change 120000 => 100644 ruff.toml diff --git a/.gitea/workflows/python-package.yml b/.gitea/workflows/python-package.yml index 09275ea..69f3d9e 100644 --- a/.gitea/workflows/python-package.yml +++ b/.gitea/workflows/python-package.yml @@ -1,16 +1,33 @@ +# WARNING! +# THIS IS AN AUTOGENERATED FILE! +# MANUAL CHANGES CAN AND WILL BE OVERWRITTEN! + name: Package Python on: push: tags: - 'v[0-9]+.[0-9]+.[0-9]+' - paths-ignore: ["README.md", ".gitignore", "LICENSE", "ruff.toml"] + paths-ignore: ['README.md', '.gitignore', 'LICENSE', 'CONVENTIONS.md', 'ruff.toml'] jobs: - Package: - uses: jmaa/workflows/.gitea/workflows/python-package.yaml@v6.21 - with: - REGISTRY_DOMAIN: gitfub.space - REGISTRY_ORGANIZATION: jmaa - secrets: - PIPY_REPO_USER: ${{ secrets.PIPY_REPO_USER }} - PIPY_REPO_PASS: ${{ secrets.PIPY_REPO_PASS }} + Package-Python-And-Publish: + runs-on: ubuntu-latest + container: + image: node:21-bookworm + steps: + - name: Setting up Python ${{ env.PYTHON_VERSION }} for ${{runner.arch}} ${{runner.os}} + run: | + apt-get update + apt-get install -y python3 python3-pip + - name: Check out repository code + if: success() + uses: actions/checkout@v3 + - name: Installing Python Dependencies + if: success() + run: python3 -m pip install --upgrade pip setuptools wheel build twine pytest --break-system-packages + - name: Build + if: success() + run: python3 -m build + - name: Publish + if: success() + run: python3 -m twine upload --repository-url "https://gitfub.space/api/packages/jmaa/pypi" -u ${{ secrets.PIPY_REPO_USER }} -p ${{ secrets.PIPY_REPO_PASS }} dist/* diff --git a/.gitea/workflows/python-ruff.yml b/.gitea/workflows/python-ruff.yml index b1be7a3..29803ca 100644 --- a/.gitea/workflows/python-ruff.yml +++ b/.gitea/workflows/python-ruff.yml @@ -1,7 +1,11 @@ +# WARNING! +# THIS IS AN AUTOGENERATED FILE! +# MANUAL CHANGES CAN AND WILL BE OVERWRITTEN! + name: Python Ruff Code Quality on: push: - paths-ignore: ["README.md", ".gitignore", "LICENSE"] + paths-ignore: ['README.md', '.gitignore', 'LICENSE', 'CONVENTIONS.md', 'ruff.toml'] jobs: ruff: diff --git a/.gitea/workflows/python-test.yml b/.gitea/workflows/python-test.yml index 58ffc6c..98d5dbe 100644 --- a/.gitea/workflows/python-test.yml +++ b/.gitea/workflows/python-test.yml @@ -1,8 +1,12 @@ +# WARNING! +# THIS IS AN AUTOGENERATED FILE! +# MANUAL CHANGES CAN AND WILL BE OVERWRITTEN! + name: Run Python tests (through Pytest) on: push: - paths-ignore: ["README.md", ".gitignore", "LICENSE", "ruff.toml"] + paths-ignore: ['README.md', '.gitignore', 'LICENSE', 'CONVENTIONS.md', 'ruff.toml'] jobs: Test: diff --git a/.gitea/workflows/python-version-check.yml b/.gitea/workflows/python-version-check.yml index 71d0ef0..5cc987d 100644 --- a/.gitea/workflows/python-version-check.yml +++ b/.gitea/workflows/python-version-check.yml @@ -1,8 +1,12 @@ +# WARNING! +# THIS IS AN AUTOGENERATED FILE! +# MANUAL CHANGES CAN AND WILL BE OVERWRITTEN! + name: Verify Python project can be installed, loaded and have version checked on: push: - paths-ignore: ["README.md", ".gitignore", "LICENSE", "ruff.toml"] + paths-ignore: ['README.md', '.gitignore', 'LICENSE', 'CONVENTIONS.md', 'ruff.toml'] jobs: Test: diff --git a/CONVENTIONS.md b/CONVENTIONS.md new file mode 100644 index 0000000..9bdf447 --- /dev/null +++ b/CONVENTIONS.md @@ -0,0 +1,36 @@ + + + + +# Conventions + +When contributing code to this project, you MUST follow the requirements +specified here. + +## Code Conventions + +When contributing code to this project, you MUST follow these principles: + +- Code should be easy to read and understand. +- Keep the code as simple as possible. Avoid unnecessary complexity. +- Use meaningful names for variables, functions, etc. Names should reveal intent. +- Functions should be small and do one thing well. They should not exceed a few lines. +- Function names should describe the action being performed. +- Only use comments when necessary, as they can become outdated. Instead, strive to make the code self-explanatory. +- When comments are used, they should add useful information that is not readily apparent from the code itself. +- Properly handle errors and exceptions to ensure the software's robustness. +- Use exceptions rather than error codes for handling errors. +- Consider security implications of the code. Implement security best practices to protect against vulnerabilities and attacks. +- Documentation should document semantics, not syntax. +- Prefer importing modules, not individual items from modules. +- Do not use f-strings in logging statements. +- Loop variables and walrus-expression-variables should be deleted when + unneeded to keep scope clean, and to avoid accidental use. + +## Testing + +When contributing test to this project, you MUST follow these principles: + +- Do not use any testing libraries other than `pytest`. +- Mocking is the root of all evil. Writing your own stubs is much more + preferable. diff --git a/LICENSE b/LICENSE index 7d3bf4b..c523464 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,3 @@ -Copyright (c) 2022-2024 Jon Michael Aanes +Copyright (c) 2022-2025 Jon Michael Aanes All rights reserved. diff --git a/README.md b/README.md index 356c493..05f268b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ - - - - + + + # Socials-util @@ -14,7 +13,9 @@ Used by one-page-internet. ## Dependencies -All requirements can be installed easily using: +This project requires [Python](https://www.python.org/) 3.8 or newer. + +All required libraries can be installed easily using: ```bash pip install -r requirements.txt @@ -25,10 +26,32 @@ Full list of requirements: - [aenum](https://pypi.org/project/aenum/) +## Contributing + +Feel free to submit pull requests. Please follow the [Code Conventions](CONVENTIONS.md) when doing so. + + +### Testing + +Testing requires the [pytest](https://docs.pytest.org/en/stable/) library. + +Run tests with the following command: + +```sh +pytest test +``` + +Test coverage can be run using the [`pytest-cov`](https://pypi.org/project/pytest-cov/) extension: + +```sh +pytest --cov=socials_util test +``` + + ## License ``` -Copyright (c) 2022-2024 Jon Michael Aanes +Copyright (c) 2022-2025 Jon Michael Aanes All rights reserved. ``` diff --git a/ruff.toml b/ruff.toml deleted file mode 120000 index 0f9835d..0000000 --- a/ruff.toml +++ /dev/null @@ -1 +0,0 @@ -/home/jmaa/.config/ruff/pyproject.toml \ No newline at end of file diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..c397e12 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,80 @@ +#[tool.ruff] +lint.select = [ 'ALL' ] +lint.ignore = [ + 'ANN', # Type annotations (lots of work.) + 'FBT', # Boolean trap is bullshit. + 'C90', 'PLR0911', 'PLR0915', 'PLR0913', # Code complexity measures are bullshit. + 'Q003', 'D205', # Format conflict + + 'TCH', # Microoptimization at the cost of readability + 'TID252', # I like relative imports + + 'D407', 'D413', # Weird documentation stuff + + 'D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D106', 'D107', 'D300', 'D401', # Missing docstrings (lots of work) + 'TD002', 'TD003', 'TD004', 'FIX', # Who cares about TODO standards? + "E501", 'PLR0912', 'PTH123', 'F405', 'E402', 'PLW0603', + + 'SIM102', + + 'TRY002', 'TRY003', +] + +# Autofix +lint.fixable = [ + 'SIM', 'C', 'Q', + 'UP035', 'UP004', 'UP032', 'UP006', 'UP007', 'I001', + 'F401', 'COM812', 'B011', 'PLR1722', 'PLR0402', 'S101', +] +lint.unfixable = ['SIM102', 'SIM114'] + +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", +] + +# Same as Black. +line-length = 88 + +# Allow unused variables when underscore-prefixed. +lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +# Assume Python 3.10. +target-version = "py310" + +[lint.flake8-quotes] +inline-quotes = "single" +multiline-quotes = "double" +docstring-quotes = "double" + +[format] +quote-style = "single" +indent-style = "space" +docstring-code-format = true + +[lint.per-file-ignores] +"test/*" = [ + "S101", # Test Asserts + "T201", # Debug prints + "PLR2004", # magic-value-comparison + 'SLF001', # Allow access to private members +] diff --git a/setup.py b/setup.py index 1f5ba7f..d4cb5db 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,9 @@ -# WARNING -# -# THIS IS AN AUTOGENERATED FILE. -# -# MANUAL CHANGES CAN AND WILL BE OVERWRITTEN. +# WARNING! +# THIS IS AN AUTOGENERATED FILE! +# MANUAL CHANGES CAN AND WILL BE OVERWRITTEN! import re +from pathlib import Path from setuptools import setup @@ -23,13 +22,27 @@ Python library for parsing and processing URLs of Social Media Sites.""".strip() def parse_version_file(text: str) -> str: - match = re.match(r'^__version__\s*=\s*(["\'])([\d\.]+)\1$', text) + text = re.sub('^#.*', '', text, flags=re.MULTILINE) + match = re.match(r'^\s*__version__\s*=\s*(["\'])([\d\.]+)\1$', text) if match is None: msg = 'Malformed _version.py file!' raise Exception(msg) return match.group(2) +def find_python_packages() -> list[str]: + """ + Find all python packages. (Directories containing __init__.py files.) + """ + root_path = Path(PACKAGE_NAME) + packages: set[str] = set([PACKAGE_NAME]) + + # Search recursively + for init_file in root_path.rglob('__init__.py'): + packages.add(str(init_file.parent).replace('/', '.')) + + return sorted(packages) + with open(PACKAGE_NAME + '/_version.py') as f: version = parse_version_file(f.read()) @@ -53,7 +66,7 @@ setup( author='Jon Michael Aanes', author_email='jonjmaa@gmail.com', url='https://gitfub.space/Jmaa/' + PACKAGE_NAME, - packages=[PACKAGE_NAME], + packages=find_python_packages(), install_requires=REQUIREMENTS_MAIN, extras_require={ 'test': REQUIREMENTS_TEST,