Skip to content

Commit

Permalink
Merge pull request #153 from datastax/poetry
Browse files Browse the repository at this point in the history
Use poetry to manage the project
  • Loading branch information
erichare authored Jan 2, 2024
2 parents 6a83a1e + 83f8400 commit ab857b4
Show file tree
Hide file tree
Showing 12 changed files with 1,187 additions and 118 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mypy
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install poetry
poetry install
- name: Black linting
run: |
black --check .
poetry run black --check .
- name: Ruff Linting AstraPy
run: |
ruff astrapy
poetry run ruff astrapy
- name: Ruff Linting Tests
run: |
ruff tests
poetry run ruff tests
- name: Run MyPy AstraPy
run: |
mypy astrapy
poetry run mypy astrapy
- name: Run MyPy Tests
run: |
mypy tests
poetry run mypy tests
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install poetry
poetry install
- name: Run pytest
run: |
pytest
poetry run pytest
22 changes: 14 additions & 8 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,15 @@ You can use the Ops client to work with the Astra DevOps API. Check the [devops

## For Developers

You should additionally `pip install -r requirements-dev.txt` in a development
environment (note that the `pip install -e .` is covered by the regular
requirements file already).
Install poetry
```bash
pip install poetry
```

Install the project dependencies
```bash
poetry install
```

### Style, linter, typing

Expand All @@ -366,14 +372,14 @@ Moreover, **type annotations** are used everywhere.
To ensure the code complies, you should get no errors
(_Success: no issues found..._) when running the following in the root dir:

```
black --check astrapy && ruff astrapy && mypy astrapy
```bash
poetry run black --check astrapy && poetry run ruff astrapy && poetry run mypy astrapy
```

Likewise, for the tests:

```
black --check tests && ruff tests && mypy tests
```bash
poetry run black --check tests && poetry run ruff tests && poetry run mypy tests
```

### Testing
Expand All @@ -392,7 +398,7 @@ export ASTRA_DB_OPS_APPLICATION_TOKEN="..." # Ops-only, falls back to the other
then you can run:

```bash
pytest
poetry run pytest
```

To remove the noise from the logs (on by default), run `pytest -o log_cli=0`.
Expand Down
36 changes: 35 additions & 1 deletion astrapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,38 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "0.6.3"

import importlib.metadata
import toml
import os

from typing import Any


def get_version() -> Any:
try:
# Poetry will create a __version__ attribute in the package's __init__.py file
return importlib.metadata.version(__package__)

# If the package is not installed, we can still get the version from the pyproject.toml file
except importlib.metadata.PackageNotFoundError:
# Get the path to the pyproject.toml file
dir_path = os.path.dirname(os.path.realpath(__file__))
pyproject_path = os.path.join(dir_path, "..", "pyproject.toml")

# Read the pyproject.toml file and get the version from the poetry section
try:
with open(pyproject_path, encoding="utf-8") as pyproject:
# Load the pyproject.toml file as a dictionary
file_contents = pyproject.read()
pyproject_data = toml.loads(file_contents)

# Return the version from the poetry section
return pyproject_data["tool"]["poetry"]["version"]

# If the pyproject.toml file does not exist or the version is not found, return unknown
except (FileNotFoundError, KeyError):
return "unknown"


__version__ = get_version()
16 changes: 0 additions & 16 deletions mypy.ini

This file was deleted.

1,055 changes: 1,055 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[tool.poetry]
name = "astrapy"
version = "0.6.3"
description = "AstraPy is a Pythonic SDK for DataStax Astra"
authors = [
"Kirsten Hunter <kirsten.hunter@datastax.com>"
]
license = "Apache-2.0"
readme = "README.md"
packages = [
{ include = "astrapy" }
]
keywords = ["DataStax", "Astra"]
homepage = "https://github.com/datastax/astrapy"
repository = "https://github.com/datastax/astrapy"
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[tool.poetry.dependencies]
python = "^3.8.0"
cassio = "~0.1.3"
toml = "^0.10.2"
httpx = { version="~0.25.1", extras=["http2"] }

[tool.poetry.group.dev.dependencies]
black = "~23.11.0"
faker = "~20.0.0"
mypy = "~1.7.0"
pre-commit = "~3.5.0"
pytest-asyncio = "~0.23.2"
pytest-cov = "~4.1.0"
pytest-testdox = "~3.1.0"
pytest = "~7.4.3"
python-dotenv = "~1.0.0"
ruff = "~0.1.5"
types-toml = "^0.10.8.7"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
follow_imports = "normal"
ignore_missing_imports = true
no_implicit_reexport = true
show_error_codes = true
show_error_context = true
strict_equality = true
strict_optional = true
warn_redundant_casts = true
warn_return_any = true
warn_unused_ignores = true

[tool.pytest.ini_options]
filterwarnings = "ignore::DeprecationWarning"
addopts = "-v --cov=astrapy --testdox --cov-report term-missing"
asyncio_mode = "auto"
log_cli = 1
log_cli_level = "INFO"
6 changes: 0 additions & 6 deletions pytest.ini

This file was deleted.

10 changes: 0 additions & 10 deletions requirements-dev.txt

This file was deleted.

3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

3 changes: 0 additions & 3 deletions setup.cfg

This file was deleted.

60 changes: 0 additions & 60 deletions setup.py

This file was deleted.

0 comments on commit ab857b4

Please sign in to comment.