diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7798717..a4b14a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,7 +52,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install poetry - python -m poetry install --no-root --with=dev + python -m poetry install --with=dev - name: Test with pytest by poetry run: | diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9164f6d..a372eec 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Fixed + +- [Reading `pyproject.toml` causes missing `pyproject.toml` error by @or150](https://github.com/hadialqattan/pycln/pull/250) + ## Changed - [Drop Python3.7 by @hadialqattan](https://github.com/hadialqattan/pycln) diff --git a/pycln/__init__.py b/pycln/__init__.py index 1fc405f..4a7fd74 100644 --- a/pycln/__init__.py +++ b/pycln/__init__.py @@ -1,10 +1,9 @@ import io import os import sys -import tokenize +from importlib.metadata import metadata from pathlib import Path -import tomlkit import typer #: Add vendor directory to module search path @@ -20,14 +19,11 @@ sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding=UTF8) # pragma: nocover ISWIN = os.name == "nt" -PYPROJECT_PATH = Path(__file__).parent.parent.joinpath("pyproject.toml") -with tokenize.open(PYPROJECT_PATH) as toml_f: - pycln = tomlkit.parse(toml_f.read())["tool"]["poetry"] - -__name__ = str(pycln["name"]) -__doc__ = str(pycln["description"]) -__version__ = pycln["version"] +pycln = metadata("pycln") +__name__ = str(pycln["Name"]) +__doc__ = str(pycln["Summary"]) +__version__ = str(pycln["Version"]) def version_callback(value: bool): diff --git a/pyproject.toml b/pyproject.toml index fb96218..484b74d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,6 @@ classifiers = [ "Topic :: Utilities"] license = "MIT" readme = "README.md" -include = ["pyproject.toml"] packages = [{ include = "pycln" }, { include = "vendor" }] [tool.poetry.scripts] diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 61aa300..5cec795 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -4,6 +4,7 @@ import sys import tokenize from os import getenv +from pathlib import Path import pytest import requests @@ -11,20 +12,14 @@ from semver import VersionInfo from typer import Exit -from pycln import ( - PYPROJECT_PATH, - VENDOR_PATH, - __doc__, - __name__, - __version__, - version_callback, -) +from pycln import VENDOR_PATH, __doc__, __name__, __version__, version_callback from .utils import sysu # Constants. +PYPROJECT_PATH = Path(__file__).parent.parent.joinpath("pyproject.toml") with tokenize.open(PYPROJECT_PATH) as toml_f: - PYCLN_METADATA = tomlkit.parse(toml_f.read())["tool"]["poetry"] + PYCLN_METADATA = tomlkit.parse(toml_f.read())["tool"]["poetry"] # type: ignore PYCLN_PYPI_JSON_URL = f"https://pypi.org/pypi/{__name__}/json" PYCLN_PYPI_URL = f"https://pypi.org/project/{__name__}/"