diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c004648 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12"] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install -e ".[dev]" + + - name: Lint with ruff + run: ruff check molgenis_auth/ tests/ + + - name: Run tests with coverage + run: pytest --cov=molgenis_auth --cov-report=xml tests/ + + - name: Upload coverage to Codecov + if: matrix.python-version == '3.12' + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage.xml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..61a628a --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,44 @@ +name: docs + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: write + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Configure Git Credentials + run: | + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV + + - uses: actions/cache@v4 + with: + key: mkdocs-material-${{ env.cache_id }} + path: .cache + restore-keys: | + mkdocs-material- + + - name: Install dependencies + run: pip install mkdocs-material mkdocstrings[python] -e . + + - name: Build docs + run: mkdocs build + + - name: Deploy to GitHub Pages + if: github.event_name != 'pull_request' + run: mkdocs gh-deploy --force diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f08020b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release + +on: + push: + tags: + - "v*" + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + run: pip install -e ".[dev]" + + - name: Run tests + run: pytest tests/ + + - name: Build package + run: pip install build && python -m build + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true + files: dist/* diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..e8468af --- /dev/null +++ b/docs/index.md @@ -0,0 +1,33 @@ +# molgenis-python-auth + +A lightweight Python client for performing **OAuth 2.0 Device Authorization Flow** +with the **Molgenis Authentication Server**. + +## Installation + +```bash +pip install git+https://github.com/molgenis/molgenis-python-auth.git +``` + +## Quick start + +```python +from molgenis_auth import MolgenisAuthClient + +client = MolgenisAuthClient( + auth_server="https://auth.molgenis.org", + client_id="YOUR_CLIENT_ID", + scopes="openid offline_access", +) + +tokens = client.device_flow_auth() +``` + +## CLI usage + +```bash +molgenis-auth \ + --auth-server https://auth.molgenis.org \ + --client-id YOUR_CLIENT_ID \ + --scopes "openid offline_access" +``` diff --git a/docs/reference.md b/docs/reference.md new file mode 100644 index 0000000..c2bd9c9 --- /dev/null +++ b/docs/reference.md @@ -0,0 +1,3 @@ +# API Reference + +::: molgenis_auth.client diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..e31db9e --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,36 @@ +site_name: molgenis-python-auth +site_url: https://molgenis.github.io/molgenis-python-auth/ +repo_name: molgenis-python-auth +repo_url: https://github.com/molgenis/molgenis-python-auth + +theme: + name: material + palette: + - media: "(prefers-color-scheme: light)" + scheme: default + primary: indigo + accent: indigo + toggle: + icon: material/brightness-7 + name: Switch to dark mode + - media: "(prefers-color-scheme: dark)" + scheme: slate + primary: indigo + accent: indigo + toggle: + icon: material/brightness-4 + name: Switch to light mode + +nav: + - Home: index.md + - Reference: reference.md + +plugins: + - search + - mkdocstrings: + handlers: + python: + options: + show_source: false + show_root_heading: true + members_order: source diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..18aac5f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,63 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "molgenis-auth" +version = "0.1.0" +description = "OAuth Device Flow client for Molgenis authentication" +readme = "README.md" +requires-python = ">=3.10" +license = "GPL-3.0-or-later" +keywords = [] +authors = [ + { name = "Tim Cadman", email = "t.j.cadman@umcg.nl" }, +] +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: Implementation :: CPython", +] +dependencies = [ + "requests", +] + +[project.optional-dependencies] +dev = [ + "pytest>=7.0.0", + "pytest-cov>=4.0.0", + "ruff>=0.4.0", +] + +[project.urls] +Documentation = "https://github.com/molgenis/molgenis-python-auth#readme" +Issues = "https://github.com/molgenis/molgenis-python-auth/issues" +Source = "https://github.com/molgenis/molgenis-python-auth" + +[project.scripts] +molgenis-auth = "molgenis_auth.cli:main" + +[tool.hatch.build.targets.wheel] +packages = ["molgenis_auth"] + +[tool.pytest.ini_options] +testpaths = ["tests"] + +[tool.coverage.run] +source_pkgs = ["molgenis_auth", "tests"] +branch = true +parallel = true + +[tool.coverage.paths] +molgenis_auth = ["molgenis_auth", "*/molgenis-python-auth/molgenis_auth"] +tests = ["tests", "*/molgenis-python-auth/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] diff --git a/setup.py b/setup.py deleted file mode 100644 index 78f7499..0000000 --- a/setup.py +++ /dev/null @@ -1,19 +0,0 @@ -from setuptools import setup, find_packages - -setup( - name="molgenis_auth", - version="0.1.0", - description="OAuth Device Flow client for Molgenis authentication", - author="Your Name", - author_email="you@example.com", - packages=find_packages(), - install_requires=[ - "requests", - ], - python_requires=">=3.8", - entry_points={ - "console_scripts": [ - "molgenis-auth = molgenis_auth.cli:main", - ], - }, -) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_import.py b/tests/test_import.py new file mode 100644 index 0000000..356145f --- /dev/null +++ b/tests/test_import.py @@ -0,0 +1,4 @@ +def test_import(): + from molgenis_auth import MolgenisAuthClient + + assert MolgenisAuthClient is not None