Coverage for src/configuraptor/helpers.py: 100%

1"""

2 Contains stand-alone helper functions.

3"""

4

5 import os

6 import typing

7

8 import black.files

9

10

11 def camel_to_snake(s: str) -> str:

12 """

13 Convert CamelCase to snake_case.

14

15 Source:

16 https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case

17 """

18 return "".join([f"_{c.lower()}" if c.isupper() else c for c in s]).lstrip("_")

19

20

21 def find_pyproject_toml() -> typing.Optional[str]:

22 """

23 Find the project's config toml, looks up until it finds the project root (black's logic).

24 """

25 return black.files.find_pyproject_toml((os.getcwd(),))