diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 0000000000000000000000000000000000000000..3ed43b27963b7fe5f79f8aad916e087c747af914 --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,11 @@ +# Changes here will be overwritten by Copier +_commit: v0.1.5 +_src_path: https://gitlab.softwareheritage.org/swh/devel/swh-py-template.git +description: Software Heritage data model +distribution_name: swh-model +have_cli: true +have_workers: false +package_root: swh/model +project_name: swh.model +python_minimal_version: '3.7' +readme_format: rst diff --git a/.gitignore b/.gitignore index 68708728197a5774d0b68cdd676cd092103aa1fe..035b13951e98580e45e6b453c2bb6fa9aef9a59f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,12 @@ -*~ -build -/.coverage -/.coverage.* -dist *.egg-info/ +*.pyc +.coverage .eggs/ .hypothesis -*.pyc -__pycache__ -.pytest_cache -*.sw? +.mypy_cache .tox -version.txt -.mypy_cache/ +__pycache__ +build/ +dist/ +docs/README.rst +docs/README.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 33a226de603535a6347f7fd1c5a5ec7f4a7e8765..44882702188264afb4d255160c59b98cc4f25d85 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,23 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: check-json - id: check-yaml + - repo: https://github.com/python/black + rev: 23.1.0 + hooks: + - id: black + + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + - repo: https://github.com/pycqa/flake8 - rev: 5.0.4 + rev: 6.0.0 hooks: - id: flake8 additional_dependencies: [flake8-bugbear==22.9.23] @@ -29,12 +39,3 @@ repos: language: system types: [python] - - repo: https://github.com/PyCQA/isort - rev: 5.11.5 - hooks: - - id: isort - - - repo: https://github.com/python/black - rev: 22.10.0 - hooks: - - id: black diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index caa4b690c5fefc3b25112d1e63359adb6f8d48ef..0000000000000000000000000000000000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,6 +0,0 @@ -include README.md -include Makefile -include requirements*.txt -include version.txt -recursive-include swh/model/tests/data *.tgz -recursive-include swh py.typed diff --git a/docs/Makefile b/docs/Makefile index b97c7532e5b946df72b8641f22f6e3e2ba84602c..bf867de5518beb4ff5cf68f23733e3e04f98f2b0 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,2 +1,2 @@ -include ../../swh-docs/Makefile.sphinx +include swh-docs/Makefile.sphinx -include Makefile.local diff --git a/mypy.ini b/mypy.ini index d411c51089c58ee654ae210c90af17e8bb388e1a..2f09ec1206332b62139f5d945e5fabbe1c165d2b 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,6 +1,13 @@ [mypy] namespace_packages = True warn_unused_ignores = True +explicit_package_bases = True +# ^ Needed for mypy to detect py.typed from swh packages installed +# in editable mode # 3rd party libraries without stubs (yet) +[mypy-pkg_resources.*] +ignore_missing_imports = True +# [mypy-add_your_lib_here.*] +# ignore_missing_imports = True diff --git a/pyproject.toml b/pyproject.toml index 69b8f4dd830abf638e624eeea85dbc580c862538..8dfbe9f211a0ddb2dd7dbe1fd9aa33c947984e59 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,52 @@ +[project] +name = "swh.model" +authors = [ + {name="Software Heritage developers", email="swh-devel@inria.fr"}, +] + +description = "Software Heritage data model" +readme = {file = "README.rst", content-type = "text/x-rst"} +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: OS Independent", + "Development Status :: 5 - Production/Stable", +] +dynamic = ["version", "dependencies", "optional-dependencies"] + +[tool.setuptools.packages.find] +include = ["swh.*"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} + +[tool.setuptools.dynamic.optional-dependencies] +cli = {file = "requirements-cli.txt"} +testing = {file = ["requirements-cli.txt", "requirements-test.txt"]} +testing_minimal = {file = "requirements-test.txt"} + +[project.entry-points.console_scripts] +"swh.identify" = "swh.model.cli:identify" + +[project.entry-points."swh.cli.subcommands"] +"swh.model" = "swh.model.cli" + +[project.urls] +"Homepage" = "https://gitlab.softwareheritage.org/swh/devel/swh-model" +"Bug Reports" = "https://gitlab.softwareheritage.org/swh/devel/swh-model/-/issues" +"Funding" = "https://www.softwareheritage.org/donate" +"Documentation" = "https://docs.softwareheritage.org/devel/swh-model/" +"Source" = "https://gitlab.softwareheritage.org/swh/devel/swh-model.git" + +[build-system] +requires = ["setuptools", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +fallback_version = "0.0.1" + [tool.black] target-version = ['py37'] diff --git a/setup.py b/setup.py deleted file mode 100755 index 8698ecc1975a5ffe4091d738cb9407c2bc443bf5..0000000000000000000000000000000000000000 --- a/setup.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (C) 2015-2020 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU General Public License version 3, or any later version -# See top-level LICENSE file for more information - -from io import open -from os import path - -from setuptools import find_packages, setup - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, "README.rst"), encoding="utf-8") as f: - long_description = f.read() - - -def parse_requirements(name=None): - if name: - reqf = "requirements-%s.txt" % name - else: - reqf = "requirements.txt" - - requirements = [] - if not path.exists(reqf): - return requirements - - with open(reqf) as f: - for line in f.readlines(): - line = line.strip() - if not line or line.startswith("#"): - continue - requirements.append(line) - return requirements - - -setup( - name="swh.model", - description="Software Heritage data model", - long_description=long_description, - long_description_content_type="text/x-rst", - python_requires=">=3.7", - author="Software Heritage developers", - author_email="swh-devel@inria.fr", - url="https://forge.softwareheritage.org/diffusion/DMOD/", - packages=find_packages(), - setup_requires=["setuptools-scm"], - use_scm_version=True, - install_requires=parse_requirements() + parse_requirements("swh"), - extras_require={ - "cli": parse_requirements("cli"), - "testing-minimal": parse_requirements("test"), - "testing": parse_requirements("test") + parse_requirements("cli"), - }, - include_package_data=True, - entry_points=""" - [console_scripts] - swh-identify=swh.model.cli:identify - [swh.cli.subcommands] - identify=swh.model.cli - """, - classifiers=[ - "Programming Language :: Python :: 3", - "Intended Audience :: Developers", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Operating System :: OS Independent", - "Development Status :: 5 - Production/Stable", - ], - project_urls={ - "Bug Reports": "https://forge.softwareheritage.org/maniphest", - "Funding": "https://www.softwareheritage.org/donate", - "Source": "https://forge.softwareheritage.org/source/swh-model", - "Documentation": "https://docs.softwareheritage.org/devel/swh-model/", - }, -) diff --git a/swh/__init__.py b/swh/__init__.py deleted file mode 100644 index b36383a61027f0875a3cb103edc8f2a4528a3289..0000000000000000000000000000000000000000 --- a/swh/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from pkgutil import extend_path - -__path__ = extend_path(__path__, __name__) diff --git a/swh/model/collections.py b/swh/model/collections.py index d7150fa9c2477d2297c175bee37d67da2a5f8408..6de27eed61be03a9ce42858d3002e61243f3a5fc 100644 --- a/swh/model/collections.py +++ b/swh/model/collections.py @@ -61,5 +61,5 @@ class ImmutableDict(Mapping, Generic[KT, VT]): """Returns a copy of this ImmutableDict without the given key, as well as the value associated to the key.""" new_items = copy.deepcopy(self._data) - popped_value = new_items.pop(popped_key, None) # type: ignore + popped_value = new_items.pop(popped_key, None) return (popped_value, ImmutableDict(new_items)) diff --git a/tox.ini b/tox.ini index 15d0702f8e538a5c4f57fd2a94a2505859507f17..3728a15ae4ef7bcee2d26f9621ebeeb68f62f5bc 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,10 @@ [tox] -minversion=4 -envlist=black,flake8,mypy,py3-{minimal,full-cover} +minversion = 4 +envlist = + black + flake8 + mypy + py3-{minimal,full-cover} [testenv] extras = @@ -14,6 +18,8 @@ commands = full: {envsitepackagesdir}/swh/model \ minimal: {envsitepackagesdir}/swh/model/tests/test_cli.py -m 'not requires_optional_deps' \ {posargs} +# --rootdir and --import-mode must NOT be used here due to the (hack-ish) way of +# executing tests (using tox-in-tox); see below [testenv:py3{,7,8,9,10,11,12,13},pypy3{,5,6,7,8,9,10,11,12,13}] skip_install = true @@ -51,32 +57,14 @@ commands = # breaking doc build [testenv:sphinx] allowlist_externals = make -usedevelop = true extras = testing deps = - # fetch and install swh-docs in develop mode - -e git+https://gitlab.softwareheritage.org/swh/devel/swh-docs.git\#egg=swh.docs + # fetch and install swh-docs + git+https://gitlab.softwareheritage.org/swh/devel/swh-docs.git\#egg=swh.docs setenv = SWH_PACKAGE_DOC_TOX_BUILD = 1 # turn warnings into errors SPHINXOPTS = -W commands = - make -I ../.tox/sphinx/src/swh-docs/swh/ -C docs - -# build documentation only inside swh-environment using local state -# of swh-docs package -[testenv:sphinx-dev] -allowlist_externals = make -usedevelop = true -extras = - testing -deps = - # install swh-docs in develop mode - -e ../swh-docs -setenv = - SWH_PACKAGE_DOC_TOX_BUILD = 1 - # turn warnings into errors - SPHINXOPTS = -W -commands = - make -I ../.tox/sphinx-dev/src/swh-docs/swh/ -C docs + make -I {env_dir}/share/ -C docs