diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4a447df --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +--- +name: CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + + permissions: + pull-requests: write + + steps: + - uses: actions/checkout@v4 + - uses: eifinger/setup-rye@v3 + id: setup-rye + with: + enable-cache: true + cache-prefix: ${{ matrix.python-version }} + - name: pin python-version ${{ matrix.python-version }} + if: steps.setup-rye.outputs.cache-hit != 'true' + run: rye pin ${{ matrix.python-version }} + - name: install dependencies + if: steps.setup-rye.outputs.cache-hit != 'true' + run: | + rye sync --no-lock + - name: run ruff + uses: chartboost/ruff-action@v1 + - name: run tests + run: | + echo '```' > pytest.log + rye test | tee -a pytest.log + echo '```' >> pytest.log + - name: PR comment pytest output + uses: thollander/actions-comment-pull-request@v2 + with: + filePath: pytest.log + if: github.event_name == 'pull_request' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index cbabb66..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,49 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Test - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - workflow_dispatch: - -permissions: - contents: read - -jobs: - test: - name: Test and lint the application - runs-on: ubuntu-latest - - permissions: - pull-requests: write - - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v5 - with: - python-version: "3.10" - cache: 'pip' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Lint with Ruff - run: | - pip install ruff - ruff check --output-format=github . - - name: Test with pytest-cov - run: | - pip install pytest-cov - echo '```' > pytest.log - pytest --cov | tee -a pytest.log - echo '```' >> pytest.log - - name: PR comment pytest output - uses: thollander/actions-comment-pull-request@v2 - with: - filePath: pytest.log - if: github.event_name == 'pull_request' diff --git a/.gitignore b/.gitignore index b1b7370..38fb294 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,13 @@ -# python dev objects +# python generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# venv .venv -__pycache__ -# local testing objects -*.json -cookies.txt +# testing files .coverage -.envrc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bf50f5a..63f0e38 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,10 +10,15 @@ repos: - id: check-merge-conflict - id: check-json - id: no-commit-to-branch -- repo: https://github.com/psf/black - rev: 22.10.0 +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.4.4 hooks: - - id: black + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.10.0 hooks: diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..871f80a --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.12.3 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..682ac2a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,39 @@ +[project] +name = "tyora" +version = "0.1.0" +description = "CLI to interact with the mooc.fi instance of CSES" +license = "MIT" +authors = [ + { name = "Edwin Hermans", email = "edwin@madtech.cx" } +] +dependencies = [ + "html2text>=2024.2.26", + "htmlement>=2.0.0", + "requests>=2.32.1", +] +readme = "README.md" +requires-python = ">= 3.12" + +[project.scripts] +"tyora" = "tyora:main" + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.rye] +managed = true +dev-dependencies = [ + "pytest>=8.2.1", + "requests-mock>=1.12.1", + "pytest-cov>=5.0.0", +] + +[tool.hatch.metadata] +allow-direct-references = true + +[tool.hatch.build.targets.wheel] +packages = ["src/tyora"] + +[tool.pytest.ini_options] +addopts = "--cov" diff --git a/requirements-dev.lock b/requirements-dev.lock new file mode 100644 index 0000000..eb596ec --- /dev/null +++ b/requirements-dev.lock @@ -0,0 +1,38 @@ +# generated by rye +# use `rye lock` or `rye sync` to update this lockfile +# +# last locked with the following flags: +# pre: false +# features: [] +# all-features: false +# with-sources: false +# generate-hashes: false + +-e file:. +certifi==2024.2.2 + # via requests +charset-normalizer==3.3.2 + # via requests +coverage==7.5.1 + # via pytest-cov +html2text==2024.2.26 + # via tyora +htmlement==2.0.0 + # via tyora +idna==3.7 + # via requests +iniconfig==2.0.0 + # via pytest +packaging==24.0 + # via pytest +pluggy==1.5.0 + # via pytest +pytest==8.2.1 + # via pytest-cov +pytest-cov==5.0.0 +requests==2.32.1 + # via requests-mock + # via tyora +requests-mock==1.12.1 +urllib3==2.2.1 + # via requests diff --git a/requirements.lock b/requirements.lock new file mode 100644 index 0000000..3925fe1 --- /dev/null +++ b/requirements.lock @@ -0,0 +1,25 @@ +# generated by rye +# use `rye lock` or `rye sync` to update this lockfile +# +# last locked with the following flags: +# pre: false +# features: [] +# all-features: false +# with-sources: false +# generate-hashes: false + +-e file:. +certifi==2024.2.2 + # via requests +charset-normalizer==3.3.2 + # via requests +html2text==2024.2.26 + # via tyora +htmlement==2.0.0 + # via tyora +idna==3.7 + # via requests +requests==2.32.1 + # via tyora +urllib3==2.2.1 + # via requests diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 13dbb67..0000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -html2text==2024.2.26 -htmlement==2.0.0 -pytest==8.2.0 -pytest-cov==5.0.0 -requests==2.31.0 -requests-mock==1.12.1 diff --git a/tyora.py b/src/tyora/__init__.py similarity index 100% rename from tyora.py rename to src/tyora/__init__.py