diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d963497..57bc455 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,18 +17,27 @@ jobs: - '3.12' steps: - - name: Clone Repository + - name: Clone repository uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} + - name: Use Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: Install Tox - run: | - python -m pip install --upgrade pip - pip install tox tox-gh-actions + - name: Configure uv + uses: astral-sh/setup-uv@v2 + with: + enable-cache: true - - name: Invoke Tox - run: tox + - name: Sync dependencies + run: uv sync --all-extras --dev + + - name: Check styling + run: uv run flake8 --ignore=E123,E231,W291,W293 fimfarchive tests + + - name: Check types + run: uv run mypy + + - name: Run tests + run: uv run pytest diff --git a/.gitignore b/.gitignore index 578f98c..a355102 100644 --- a/.gitignore +++ b/.gitignore @@ -16,8 +16,11 @@ Thumbs.db # Python cache. __pycache__/ +# Lock files. +uv.lock + # Virtual environment. -venv/ +.venv/ # Vim settings. .vim/ diff --git a/README.md b/README.md index fd4e309..690d0f1 100644 --- a/README.md +++ b/README.md @@ -65,24 +65,22 @@ Start by creating a clone of the Fimfarchive repository. git clone https://github.com/JockeTF/fimfarchive.git ``` -Enter the cloned repository and create a virtual environment called `venv` -within it. Make sure to activate the virtual environment before proceeding to -install the development dependencies. +Enter the cloned repository and install the development dependencies. ```bash -python3 -m pip install -r requirements.txt +uv sync ``` Optionally also install `lz4` to lower the memory footprint of open archives. ```bash -python3 -m pip install lz4 +uv sync --extra lz4 ``` All done! Run the test suite to make sure everything works as expected. ```bash -pytest +uv run pytest ``` [virtual environment]: https://docs.python.org/3/tutorial/venv.html @@ -91,11 +89,11 @@ pytest # Running Fimfarchive has a command line interface which is invoked as a Python module. -It can't do much except prepare new Fimfarchie releases. For archive browsing +It can't do much except prepare new Fimfarchive releases. For archive browsing you will need to use third-party tools, or make your own. ``` -$ python3 -m fimfarchive +$ uv run python -m fimfarchive Usage: COMMAND [PARAMETERS] Fimfarchive, ensuring that history is preseved. @@ -109,7 +107,7 @@ The command line interface features multiple subcommands, each with its own brief help text. The subcommand is specified as the second program argument. ``` -$ python3 -m fimfarchive update --help +$ uv run python -m fimfarchive update --help usage: [-h] [--alpha] --archive PATH [--refetch] Updates stories for Fimfarchive. diff --git a/fimfarchive/writers.py b/fimfarchive/writers.py index d1b53e3..17236d5 100644 --- a/fimfarchive/writers.py +++ b/fimfarchive/writers.py @@ -5,7 +5,7 @@ Writers for Fimfarchive. # # Fimfarchive, preserves stories from Fimfiction. -# Copyright (C) 2019 Joakim Soderlund +# Copyright (C) 2024 Joakim Soderlund # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -38,7 +38,7 @@ from fimfarchive.stories import Story __all__ = ( 'Writer', 'DirectoryWriter', - 'FimfarchiveWriter' + 'FimfarchiveWriter', ) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..fe6ed57 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,50 @@ +[project] +name = "fimfarchive" +version = "0.1.0" +description = "Preserves stories from Fimfiction" +readme = "README.md" +requires-python = "~=3.8" +dependencies = [ + "arrow~=1.3", + "bbcode~=1.1", + "blinker~=1.8", + "importlib-resources~=6.4", + "jinja2~=3.1", + "jmespath~=1.0", + "jsonapi-client", + "requests~=2.32", + "tqdm~=4.66", +] + +[project.optional-dependencies] +lz4 = ["lz4~=4.3"] + +[tool.uv] +compile-bytecode = true +dev-dependencies = [ + "flake8~=5.0", + "mypy~=1.11", + "pytest~=8.3", + "requests-mock~=1.12", + "types-jmespath~=1.0", + "types-requests~=2.32", + "types-tqdm~=4.66", +] + +[tool.uv.sources.jsonapi-client] +git = "https://github.com/JockeTF/jsonapi-client.git" + +[tool.mypy] +files = ["fimfarchive", "tests"] +ignore_missing_imports = true + +[tool.pyright] +venvPath = "." +venv = ".venv" + +[tool.pytest.ini_options] +testpaths = ["tests"] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index cce4fb0..0000000 --- a/requirements.txt +++ /dev/null @@ -1,16 +0,0 @@ -arrow -bbcode -blinker -flake8 -importlib_resources -jinja2 -jmespath -jsonapi-client@git+https://github.com/JockeTF/jsonapi-client.git -mypy -pytest -requests -requests-mock -tqdm -types-jmespath -types-requests -types-tqdm diff --git a/setup.py b/setup.py deleted file mode 100755 index e508244..0000000 --- a/setup.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python3 -""" -Setuptools for Fimfarchive. -""" - - -# -# Fimfarchive, preserves stories from Fimfiction -# Copyright (C) 2015 Joakim Soderlund -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - - -import os -from typing import Iterable, List, Tuple - -from setuptools import setup - -from fimfarchive import __author__, __license__, __version__ - - -PACKAGE = 'fimfarchive' -GITHUB = 'https://github.com/JockeTF/fimfarchive' - - -def to_name(path: str) -> str: - """ - Converts path to a package name. - """ - return path.replace(os.path.sep, '.') - - -def iter_package_paths() -> Iterable[str]: - """ - Yields all package paths to install. - """ - for dirpath, dirnames, filenames in os.walk(PACKAGE): - if '__init__.py' in filenames: - yield dirpath - - -def iter_package_names() -> Iterable[str]: - """ - Yields all package names to install. - """ - for dirpath in iter_package_paths(): - yield to_name(dirpath) - - -def iter_package_data() -> Iterable[Tuple[str, List[str]]]: - """ - Yields all package data to install. - """ - for dirpath in iter_package_paths(): - filenames = [ - filename for filename in os.listdir(dirpath) - if os.path.isfile(os.path.join(dirpath, filename)) - and not filename.endswith('.py') - ] - - if filenames: - yield to_name(dirpath), filenames - - -setup( - name="fimfarchive", - version=__version__, - license=__license__, - author=__author__, - author_email='fimfarchive@gmail.com', - url='http://www.fimfarchive.net/', - download_url=f'{GITHUB}/archive/{__version__}.tar.gz', - packages=list(iter_package_names()), - package_data=dict(iter_package_data()), - install_requires=( - 'arrow', - 'bbcode', - 'blinker', - 'importlib_resources', - 'jinja2', - 'jmespath', - 'jsonapi-client', - 'requests', - 'tqdm', - ), -) diff --git a/tox.ini b/tox.ini deleted file mode 100644 index cb6119e..0000000 --- a/tox.ini +++ /dev/null @@ -1,29 +0,0 @@ -[tox] -envlist = - py38 - py39 - py310 - py311 - py312 - -[gh-actions] -python = - 3.8: py38 - 3.9: py39 - 3.10: py310 - 3.11: py311 - 3.12: py312 - -[testenv] -deps = -rrequirements.txt -commands = - py.test - flake8 fimfarchive tests - mypy --ignore-missing-imports fimfarchive tests - -[pytest] -addopts = - tests - -[flake8] -exclude = fimfarchive/__init__.py