Skip to content

Commit

Permalink
Move to hatch (#31)
Browse files Browse the repository at this point in the history
* Move to hatch
* Update CI
  • Loading branch information
tarsil authored May 2, 2024
1 parent 9393bd0 commit 76a1f4f
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 216 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
runs-on: "ubuntu-latest"

steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
- uses: "actions/checkout@v4"
- uses: "actions/setup-python@v5"
with:
python-version: 3.8
- name: "Install dependencies"
run: "scripts/install"
- name: Install build dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: pip install build twine
- name: "Build package & docs"
run: "scripts/build"
run: pip install hatch
- name: "Build package"
run: "hatch run build_with_check"
- name: "Build docs"
run: "hatch run docs:build"
- name: "Publish to PyPI"
run: "scripts/publish"
env:
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@ jobs:
ports:
- 27017:27017
steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
- uses: "actions/checkout@v4"
- uses: "actions/setup-python@v5"
with:
python-version: "${{ matrix.python-version }}"
allow-prereleases: true
- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test-v02
- name: "Install dependencies"
if: steps.cache.outputs.cache-hit != 'true'
run: "scripts/install"
run: "pip install hatch"
- name: "Run linting checks"
run: "scripts/check"
run: "hatch run lint"
- name: "Run typing checks"
run: "hatch run test:check_types"
- name: "Run tests"
env:
DATABASE_URI: "mongodb://root:mongoadmin@localhost:27017"
run: "scripts/test"
run: "hatch run test:test"
24 changes: 2 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
# See https://pre-commit.com for more information.
# See https://pre-commit.com/hooks.html for more hooks.
default_language_version:
python: python3.10
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-toml
- id: check-yaml
args:
- --unsafe
- id: end-of-file-fixer
- id: debug-statements
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args:
- --py3-plus
- --keep-runtime-typing
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args:
- --py3-plus
- --keep-runtime-typing
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.3.0
hooks:
- id: ruff
args: ["--fix", "--line-length=99"]
- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black
args: ["--line-length=99"]
ci:
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
36 changes: 0 additions & 36 deletions Makefile

This file was deleted.

1 change: 0 additions & 1 deletion docker-compose.yml → compose.overrides.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.8'
services:
mongodb:
restart: always
Expand Down
27 changes: 27 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'
services:
mongodb:
restart: always
image: mongo:latest
container_name: mongo
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: mongoadmin
MONGO_INITDB_DATABASE: mongodb
expose:
- 27017
ports:
- 27017:27017

mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ENABLE_ADMIN: 'true'
ME_CONFIG_MONGODB_SERVER: mongodb
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: mongoadmin
ME_CONFIG_BASICAUTH_USERNAME: admin
ME_CONFIG_BASICAUTH_PASSWORD: password
30 changes: 22 additions & 8 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,41 @@ After, clone your fork with the follow command replacing `YOUR-USERNAME` wih you
$ git clone https://github.com/YOUR-USERNAME/mongoz
```

Mongoz also uses [hatch](https://hatch.pypa.io/latest/) for its development, testing and release
cycles.

Please make sure you run:

```shell
pip install hatch
```

### Install the project dependencies

Not necessary because the dependencies are automatically installed by hatch.
But if environments should be pre-initialized it can be done with `hatch env`

```shell
$ cd mongoz
$ scripts/install
$ hatch env create
$ hatch env create test
$ hatch env create docs
```

### Enable pre-commit

The project comes with a pre-commit hook configuration. To enable it, just run inside the clone:

```shell
$ pre-commit
$ hatch run pre-commit install
```

### Run the tests

To run the tests, use:

```shell
$ scripts/test
$ hatch run test:test
```

Because MongoZ uses pytest, any additional arguments will be passed. More info within the
Expand All @@ -74,13 +88,13 @@ Because MongoZ uses pytest, any additional arguments will be passed. More info w
For example, to run a single test_script:

```shell
$ scripts/test tests/test_apiviews.py
$ hatch run test:test tests/test_managers.py
```

To run the linting, use:

```shell
$ scripts/lint
$ hatch run lint
```

### Documentation
Expand All @@ -90,21 +104,21 @@ Improving the documentation is quite easy and it is placed inside the `mongoz/do
To start the docs, run:

```shell
$ scripts/docs
$ hatch run docs:serve
```

## Building MongoZ

To build a package locally, run:

```shell
$ scripts/build
$ hatch run build
```

Alternatively running:

```
$ scripts/install
$ hatch shell
```

It will install the requirements and create a local build in your virtual environment.
Expand Down
71 changes: 49 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,52 @@ Changelog = "https://mongoz.tarsild.io/release-notes/"
Funding = "https://github.com/sponsors/tarsil"
Source = "https://github.com/tarsil/mongoz"

[project.optional-dependencies]
test = [

[tool.hatch.version]
path = "mongoz/__init__.py"

[tool.hatch.envs.default]
dependencies = [
"anyio>=4.0.0,<5",
"mypy==1.9.0",
"ruff>=0.3.0,<5.0.0",
"pre-commit>=3.3.1,<4.0.0",
"devtools>=0.12.2",
"ipython",
"ptpython",
"twine",
]

[tool.hatch.envs.default.scripts]
clean_pyc = "find . -type f -name \"*.pyc\" -delete"
clean_pyi = "find . -type f -name \"*.pyi\" -delete"
clean_pycache = "find . -type d -name \"*__pycache__*\" -delete"
build_with_check = "hatch build; twine check dist/*"
lint = "ruff check --fix --line-length 99 mongoz tests {args}"

[tool.hatch.envs.docs]
dependencies = [
"griffe-typingdoc>=0.2.2,<1.0",
"mkautodoc>=0.2.0,<0.3.0",
"mkdocs>=1.1.2,<2.0.0",
"mkdocs-material>=9.4.4,<10.0.0",
"mdx-include>=1.4.2,<2.0.0",
"mkdocs-markdownextradata-plugin>=0.2.5,<0.3.0",
"mkdocs-meta-descriptions-plugin>=2.3.0",
"mkdocstrings[python]>=0.23.0,<0.30.0",
"pyyaml>=6.0,<7.0.0",
]

[tool.hatch.envs.docs.scripts]
build = "mkdocs build"
serve = "mkdocs serve --dev-addr localhost:8000"

[tool.hatch.envs.test]
dependencies = [
"a2wsgi>1.10.0,<2.0.0",
"autoflake>=2.0.2,<3.0.0",
"black==24.1.1,<25.0",
"esmerald>=3.0.0",
"esmerald>=3.1.3",
"httpx>=0.25.0,<0.30.0",
"isort>=5.12.0,<6.0.0",
"mypy==1.9.0",
Expand All @@ -68,26 +108,13 @@ test = [
"requests>=2.28.2",
"ruff>=0.0.256,<1.0.0",
]
[tool.hatch.envs.test.scripts]
# needs docker services running
test = "pytest {args}"
test_detail = "pytest {args} --disable-pytest-warnings -s -vv"
coverage = "pytest --cov=asyncz --cov=tests --cov-report=term-missing:skip-covered --cov-report=html tests {args}"
check_types = "mypy -p mongoz"

dev = [
"anyio>=4.0.0,<5",
"ipdb>=0.13.13,<1.0.0",
"pdbpp",
"pre-commit>=3.3.1,<4.0.0",
]

doc = [
"mkautodoc>=0.2.0,<0.3.0",
"mkdocs>=1.4.2,<2.0.0",
"mkdocs-material==9.1.5",
"mdx-include>=1.4.1,<2.0.0",
"mkdocs-markdownextradata-plugin>=0.1.7,<0.3.0",
"mkdocstrings>=0.19.0,<0.21.0",
"pyyaml>=5.3.1,<7.0.0",
]

[tool.hatch.version]
path = "mongoz/__init__.py"

[tool.isort]
profile = "black"
Expand Down
15 changes: 0 additions & 15 deletions scripts/build

This file was deleted.

17 changes: 0 additions & 17 deletions scripts/check

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/coverage

This file was deleted.

Loading

0 comments on commit 76a1f4f

Please sign in to comment.