Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of hatch #6

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Lint and Tests
on:
push:
branches:
- "**"

jobs:
python-lint:
runs-on: ubuntu-20.04
steps:
- name: Checkout github repo (+ download lfs dependencies)
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Check code format (Ruff)
run: ruff format --check src tests
- name: Check Typing (mypy)
run: |
mypy --install-types --non-interactive

python-test:
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 9
matrix:
os: [windows-latest, ubuntu-20.04]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps:
- name: Checkout github repo (+ download lfs dependencies)
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Test with pytest
run: |
pytest --cov tests --cov-report xml
43 changes: 0 additions & 43 deletions .github/workflows/python-package.yml

This file was deleted.

18 changes: 8 additions & 10 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will upload a Python Package using Hatch when a release is created
# This workflow will upload a Python Package when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
Expand All @@ -21,23 +21,21 @@ jobs:
environment: PyPi

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install hatch

python -m pip install build
- name: Build Python 🐍 packages
run: hatch build

run: python -m build
- name: Publish distribution 📦 to PyPI
# Upload packages only on a tagged commit
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
password: ${{ secrets.PYPI_API_TOKEN }}
75 changes: 20 additions & 55 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,71 @@
# Development

This projet uses [Hach](https://hatch.pypa.io/latest/) to manage the development environment.

## Project setup

➢ To install the [development environment](https://hatch.pypa.io/latest/environment/), run:
➢ To install your development environment inside a [virtual environment](https://docs.python.org/3/library/venv.html), run:

```shell
hatch env create
python -m venv venv
source venv/bin/activate
```

> See [hatch env create](https://hatch.pypa.io/latest/cli/reference/#hatch-env-create) documentation

This command will create a virtual environment and install the development dependencies.

> NOTE: `hatch` creates a virtual environment in the `~/.local/share/hatch/env/virtual/antares-study-version` directory.

➢ To activate the virtual environment, run:

➢ To install the project dependencies, then run:
```shell
hatch shell
python -m pip install --upgrade pip
pip install -r requirements.txt
```

> See [hatch shell](https://hatch.pypa.io/latest/cli/reference/#hatch-shell) documentation

This command will spawn a new shell with the virtual environment activated. Use Ctrl+D to exit the shell.

> NOTE: this command will display the full path to the virtual environment.
> You can use it to configure PyCharm or Visual Studio Code to use this virtual environment.
or `requirements-dev.txt` if you want to run the tests or check the lint.

## Development tasks

➢ To format and lint the source code with [ruff](https://docs.astral.sh/ruff/), run:

```shell
hatch fmt
ruff check src/ tests/ --fix && ruff format src/ tests/
```

> See [hatch fmt](https://hatch.pypa.io/latest/cli/reference/#hatch-fmt) documentation

➢ To run the tests on the current Python version, run:
➢ To run the tests, run:

```shell
hatch run test
pytest
```

> See [hatch run](https://hatch.pypa.io/latest/cli/reference/#hatch-run) documentation

➢ To run the tests on Python 3.12, for example, run:

```shell
hatch run all.py3.12:test
```
at the root of the projet.

➢ To generate the test coverage report, run:

```shell
hatch run cov
pytest --cov --cov-report xml
```
at the root of the project.

This command will run the unit tests and generate a coverage report in the `htmlcov` directory.
This command will run the unit tests and generate a coverage report inside the `coverage.xml` file at the root of the project.

➢ To check the typing with [mypy](http://mypy-lang.org/), run:

```shell
hatch run types:check
```

➢ To check the typing on unit tests, run:

```shell
hatch run types:check-tests
mypy --install-types --non-interactive
```

## Generating the documentation

To prepare the documentation environment, run:
First you need to install mkdocs dependencies, so run:

```shell
hatch env create docs
pip install -r requirements-doc.txt
```

➢ To generate the documentation with [mkdocs](https://www.mkdocs.org/), run:

```shell
hatch run docs:build
mkdocs build -f mkdocs.yml
```

This command will generate the documentation in the `site` directory.
This command will delete the existing documentation folder and regenerate it inside the directory `site`.

➢ To serve the documentation locally, run:

```shell
hatch run docs:serve
mkdocs serve -f mkdocs.yml
```

This command will start a local web server to serve the documentation
Expand All @@ -113,11 +86,3 @@ This command will create a `dist` directory with the built package.
```shell
hatch publish
```

➢ To clean the project, run:

```shell
hatch clean
```

This command will remove the `dist` directory.
92 changes: 5 additions & 87 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"


[project]
name = "antares-study-version"
dynamic = ["version"]
Expand All @@ -28,89 +23,25 @@ classifiers = [

dependencies = ["click", "pandas"]

[project.scripts]
antares-study-version = "antares.study.version.cli:cli"


[project.urls]
Documentation = "https://github.com/AntaresSimulatorTeam/antares-study-version#readme"
Issues = "https://github.com/AntaresSimulatorTeam/antares-study-version/issues"
Source = "https://github.com/AntaresSimulatorTeam/antares-study-version"


[project.scripts]
antares-study-version = "antares.study.version.cli:cli"


[tool.hatch.version]
path = "src/antares/study/version/__about__.py"
attr = "__version__"


[tool.hatch.build.targets.wheel]
packages = ["src/antares"]


[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest<8",
"pydantic<2",
"pytest-freezer<0.5",
]


[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test-cov = "coverage run -m pytest {args:tests}"
cov-report = [
"- coverage combine",
"coverage report --show-missing",
"coverage html",
]
cov = [
"test-cov",
"cov-report",
]


[[tool.hatch.envs.all.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]


[tool.hatch.envs.types]
dependencies = [
"pytest<8",
"pydantic<2",
"pytest-freezer<0.5",
"mypy>=1.0.0",
]


[tool.hatch.envs.types.scripts]
check = "mypy --namespace-packages --package antares.study.version --install-types --non-interactive"
check-tests = "mypy --install-types --non-interactive {args:tests}"


[tool.hatch.envs.docs]
detached = true
dependencies = ["mkdocs"]


[tool.hatch.envs.docs.scripts]
build = "mkdocs build -f mkdocs.yml {args}"
serve = "mkdocs serve -f mkdocs.yml {args}"
gh-deploy = "mkdocs gh-deploy -f mkdocs.yml {args}"


[tool.mypy]
mypy_path = 'src, tests'

files = ["src/", "tests/"]
ignore_missing_imports = true

[tool.coverage.run]
source_pkgs = ["antares.study.version", "tests"]
branch = true
parallel = true
omit = []


[tool.coverage.paths]
antares_study_config = ["src/antares/study/version", "*/antares-study-version/src/antares/study/version"]
tests = ["tests", "*/antares-study-version/tests"]
Expand All @@ -123,19 +54,6 @@ exclude_lines = [
"if TYPE_CHECKING:",
]


[tool.black]
target-version = ["py38"]
line-length = 120


[tool.isort]
profile = "black"
line_length = 120
src_paths = ["src", "tests"]
skip_gitignore = true


[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
Expand Down
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
pythonpath = src
testpaths = tests
log_cli = true
junit_family=xunit2
7 changes: 7 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-r requirements.txt
mypy~=1.10.1
ruff~=0.5.2
pytest~=8.2.2
pytest-cov~=5.0.0
freezegun~=1.5.1
pandas-stubs~=2.0.3
Loading
Loading