Skip to content

Commit

Permalink
switch to hatch like in asyncz
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed May 1, 2024
1 parent d236534 commit b8ae039
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 368 deletions.
11 changes: 0 additions & 11 deletions .flake8

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
- 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
run: pip install hatch
- name: "Build package"
run: "scripts/build"
run: "hatch build"
- name: "Build docs"
run: "hatch run docs:build"
- name: "Publish to PyPI"
run: "scripts/release"
env:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ jobs:
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test-v02
- name: "Install dependencies"
if: steps.cache.outputs.cache-hit != 'true'
run: "scripts/install"
- name: "Run linting"
run: "scripts/lint"
run: "pip install hatch"
- name: "Run linting checks"
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"
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# 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.4.0
Expand All @@ -26,11 +24,6 @@ repos:
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
10 changes: 0 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ services:
POSTGRES_DB: "esmerald"
expose:
- "5432"
volumes:
- "esmerald:/var/lib/postgresql/data"
command: >-
--jit=false
ports:
Expand All @@ -33,8 +31,6 @@ services:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: mongoadmin
MONGO_INITDB_DATABASE: mongodb
volumes:
- "mongo_esmerald_db_data:/data/db"
expose:
- 27017
ports:
Expand All @@ -52,9 +48,3 @@ services:
ME_CONFIG_MONGODB_ADMINPASSWORD: mongoadmin
ME_CONFIG_BASICAUTH_USERNAME: admin
ME_CONFIG_BASICAUTH_PASSWORD: password

volumes:
esmerald:
external: true
mongo_esmerald_db_data:
external: true
93 changes: 30 additions & 63 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,109 +47,76 @@ $ git clone https://github.com/YOUR-USERNAME/esmerald

### Install the project dependencies

=== "Linux, macOS"
```shell
$ cd esmerald
$ scripts/install
```

=== "Windows"
```powershell
$ cd esmerald
$ scripts\install.ps1
```
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 esmerald
$ 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
$ pre-commit install
```

### Run the tests

To run the tests, use:

=== "Linux, macOS"

```shell
$ scripts/test
```

=== "Windows"

```powershell
$ scripts\test.ps1
```
```shell
$ hatch run test:test
```

Because Esmerald uses pytest, any additional arguments will be passed. More info within the
[pytest documentation](https://docs.pytest.org/en/latest/how-to/usage.html)

For example, to run a single test_script:

=== "Linux, macOS"
```shell
$ scripts/test tests/test_apiviews.py
```

=== "Windows"
```powershell
$ scripts\test tests\test_apiviews.py
```
```shell
$ hatch run test:test tests/test_apiviews.py
```

To run the linting, use:

=== "Linux, macOS"
```shell
$ scripts/lint
```

=== "Windows"
```powershell
$ scripts\lint.ps1
```
```shell
$ hatch run lint
```

### Documentation

Improving the documentation is quite easy and it is placed inside the `esmerald/docs` folder.

To start the docs, run:

=== "Linux, macOS"
```shell
$ scripts/docs
```

=== "Windows"
```powershell
$ scripts\docs.ps1
```
```shell
$ hatch run docs:serve
```

## Building Esmerald

To build a package locally, run:

=== "Linux, macOS"
```shell
$ scripts/build
```

=== "Windows"
```shell
$ scripts\build
```
```shell
$ hatch build
```


Alternatively running:

=== "Linux, macOS"
```
$ scripts/install
```
=== "Windows"
```
$ scripts\install.ps1
```

```shell
$ hatch shell
```

It will install the requirements and create a local build in your virtual environment.

Expand Down
91 changes: 59 additions & 32 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,63 @@ Source = "https://github.com/dymmond/esmerald"

[project.optional-dependencies]
test = [
"httpx>=0.25.0,<0.30.0",
]

dev = [
"a2wsgi>=1.10.0,<2",
# includes watchfiles
"uvicorn[standard]>=0.24.0",
]


templates = ["mako>=1.2.4,<2.0.0"]
jwt = ["passlib==1.7.4", "python-jose>=3.3.0,<4"]
encoders = ["ujson>=5.7.0,<6", "orjson>=3.0,<4.0"]
schedulers = ["asyncz>=0.4.0"]

[tool.hatch.envs.default]
dependencies = [
"ruff",
"pre-commit>=2.17.0,<3.0.0",
"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 esmerald tests docs_src {args}"


[tool.hatch.envs.docs]
dependencies = [
"griffe-typingdoc>=0.2.2",
"mike>=2.0.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 = [
"pytest>=7.1.3,<9.0.0",
"pytest-cov>=4.1.0,<6.0.0",
"pytest-asyncio>=0.20.0",
"mypy==1.9.0",
"flake8>=5.0.4",
"aiofiles>=0.8.0,<24",
"a2wsgi>=1.9.0,<2",
"asyncz>=0.6.0",
"anyio[trio]>=3.6.2,<5.0.0",
"asyncio[trio]>=3.4.3,<4.0.0",
"httpx>=0.25.0,<0.30.0",
"brotli>=1.0.9,<2.0.0",
"flask>=1.1.2,<4.0.0",
Expand All @@ -120,40 +167,19 @@ test = [
# types
"types-ujson==5.9.0.0",
"types-orjson==3.6.2",
]
"ipython",
"ptpython",
"uvicorn",

dev = [
"a2wsgi>=1.10.0,<2",
"autoflake>=1.4.0",
"black==24.4.0",
"ipdb",
"isort>=5.0.6,<6.0.0",
"flake8>=3.8.3,<8.0.0",
"uvicorn[standard]>=0.24.0",
"pre-commit>=3.0.4,<4.0.0",
"ruff>=0.3.0,<1.0.0",
"watchfiles>=0.16.1,<0.22.0",
]
[tool.hatch.envs.test.scripts]

# needs docker services running
test = "ESMERALD_SETTINGS_MODULE='tests.settings.TestSettings' pytest {args}"
coverage = "ESMERALD_SETTINGS_MODULE='tests.settings.TestSettings' pytest --cov=asyncz --cov=tests --cov-report=term-missing:skip-covered --cov-report=html tests {args}"
check_types = "mypy -p lilya"

doc = [
"griffe-typingdoc>=0.2.2",
"mike>=2.0.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",
]

templates = ["mako>=1.2.4,<2.0.0"]
jwt = ["passlib==1.7.4", "python-jose>=3.3.0,<4"]
encoders = ["ujson>=5.7.0,<6"]
schedulers = ["asyncz>=0.4.0"]
ptpython = ["ptpython>=3.0.23,<4.0.0"]
ipython = ["ipython>=8.10.0,<9.0.0"]

[tool.hatch.version]
path = "esmerald/__init__.py"
Expand Down Expand Up @@ -226,6 +252,7 @@ ignore_errors = true

[[tool.mypy.overrides]]
module = [
"multipart.*",
"sqlalchemy.*",
"sqlalchemy_utils.*",
"slugify.*",
Expand Down
14 changes: 0 additions & 14 deletions scripts/build

This file was deleted.

Loading

0 comments on commit b8ae039

Please sign in to comment.