Skip to content

Commit

Permalink
[ENH] package with pyproject.tom and lint (#46)
Browse files Browse the repository at this point in the history
* package with pyproject.toml, add isort / codespell, apply linting via pre-commit

* update pre-commit

* run tests

* rm breakpoints

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update test_rs2redcap_redcap2rs.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Yibei Chen <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 21, 2024
1 parent 05362e8 commit 239efcc
Show file tree
Hide file tree
Showing 30 changed files with 411 additions and 3,317 deletions.
11 changes: 11 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[flake8]
doctests = True
exclude =
**/__init__.py
**/tests/*
*build/
docs/sphinxext/
docs/tools/
reproschema/_version.py
max-line-length=79
extend-ignore = B001, B006, B016, E501, E722, F821
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Python package

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine pyyaml
pip install setuptools twine pyyaml build
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py bdist_wheel
python -m build
twine upload dist/*
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# autogenerated by hacthling
reproschema/_version.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,43 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

# Sorts Python imports alphabetically and by section with `isort`.
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: [--profile, black, --settings-path, pyproject.toml]

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black

# Checks for spelling errors
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: [--toml, pyproject.toml]
additional_dependencies: [tomli]

# Format TOML files
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.13.0
hooks:
- id: pretty-format-toml
args: [--autofix, --indent, '4']

# Check that Python code complies with PEP8 guidelines
# flake8 uses pydocstyle to check docstrings: https://flake8.pycqa.org/en/latest/
# flake8-docstrings: https://pypi.org/project/flake8-docstrings/
# flake8-use-fstring forces to use fstrings: https://pypi.org/project/flake8-use-fstring/
# flake8-functions checks functions quality: https://pypi.org/project/flake8-functions/
# flake8-bugbear detects some common bugs: https://github.com/PyCQA/flake8-bugbear
- repo: https://github.com/pyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
args: [--config, .flake8, --verbose, reproschema]
additional_dependencies: [flake8-bugbear]
3 changes: 3 additions & 0 deletions codespell_ignore_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
datas
Varios
deamon
84 changes: 84 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling", "hatch-vcs"]

[project]
authors = [{name = "Repronim developers", email = "[email protected]"}]
dependencies = [
"click",
"etelemetry",
"pyshacl",
"PyLD",
"requests",
"requests_cache",
"pyyaml",
"beautifulsoup4",
"lxml",
"pydantic >= 2.0"
]
description = "Reproschema Python library"
# Version from setuptools_scm
dynamic = ["version"]
license = {text = "Apache License, 2.0"}
maintainers = [{name = "Repronim developers", email = "[email protected]"}]
name = "reproschema-py"
readme = "README.md"
requires-python = ">=3.8"

[project.optional-dependencies]
all = ["reproschema-py[doc]", "reproschema-py[test]"]
dev = ["reproschema-py[doc]", "reproschema-py[test]", "black", "pre-commit"]
doc = [
"packaging",
"sphinx >= 2.1.2",
"sphinx_rtd_theme",
"sphinxcontrib-apidoc ~= 0.3.0",
"sphinxcontrib-napoleon",
"sphinxcontrib-versioning"
]
docs = ["reproschema-py[doc]"]
# For running unit and docstring tests
test = [
"pytest >= 4.4.0",
"pytest-cov",
"pytest-env",
"pytest-xdist",
"pytest-rerunfailures",
"codecov"
]
tests = ["reproschema-py[test]"]

[project.scripts]
reproschema = "reproschema.cli:main"

[project.urls]
Homepage = "https://github.com/ReproNim/reproschema-py"

[tool.black]
line-length = 79

[tool.codespell]
ignore-words = "codespell_ignore_words.txt"
skip = "./.git"

[tool.hatch.build.hooks.vcs]
version-file = "reproschema/_version.py"

[tool.hatch.build.targets.wheel]
packages = ["reproschema"]

[tool.hatch.version]
source = "vcs"

[tool.isort]
combine_as_imports = true
line_length = 79
profile = "black"
skip_gitignore = true

[tool.pytest.ini_options]
addopts = "-ra --strict-config --strict-markers --doctest-modules --showlocals -v"
doctest_optionflags = "NORMALIZE_WHITESPACE ELLIPSIS"
junit_family = "xunit2"
minversion = "6.0"
xfail_strict = true
16 changes: 6 additions & 10 deletions reproschema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logging
import os

from ._version import get_versions

__version__ = get_versions()["version"]
del get_versions
from reproschema._version import __version__

#
# Basic logger configuration
Expand Down Expand Up @@ -40,12 +37,11 @@ def set_logger_level(lgr, level):
try:
import etelemetry

etelemetry.check_available_version("repronim/reproschema-py", __version__, lgr=lgr)
etelemetry.check_available_version(
"repronim/reproschema-py", __version__, lgr=lgr
)
except Exception as exc:
lgr.warning(
"Failed to check for a more recent version available with etelemetry: %s", exc
"Failed to check for a more recent version available with etelemetry: %s",
exc,
)

from . import _version

__version__ = _version.get_versions()["version"]
Loading

0 comments on commit 239efcc

Please sign in to comment.