Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.alpha 13 #358

Merged
merged 70 commits into from
Oct 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
a8d546d
back to develop a 13
cleder Jun 19, 2024
7df753e
Merge branch 'main' into develop
cleder Jun 19, 2024
24a4852
fix ruff errors for base classes
cleder Jun 20, 2024
419b46d
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jun 24, 2024
2210254
Merge pull request #332 from cleder/pre-commit-ci-update-config
cleder Jun 24, 2024
89f3eaa
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 1, 2024
429cf45
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 1, 2024
87e505b
Merge pull request #333 from cleder/pre-commit-ci-update-config
cleder Jul 2, 2024
fe5eda3
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 8, 2024
48d4f76
Merge pull request #334 from cleder/pre-commit-ci-update-config
cleder Jul 9, 2024
221ba14
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 15, 2024
6e90a52
Merge pull request #335 from cleder/pre-commit-ci-update-config
cleder Jul 16, 2024
2aad8b1
document the helper functions
cleder Jun 20, 2024
5b7ee34
better docstrings and ruff fixes
cleder Jul 18, 2024
7fee7b0
better docstrings and ruff fixes
cleder Jul 18, 2024
401c8e9
better docstrings and ruff fixes
cleder Jul 18, 2024
c3c6f8e
better docstrings and ruff fixes
cleder Jul 18, 2024
4541ea0
better docstrings and ruff fixes
cleder Jul 18, 2024
d592b0d
better docstrings and ruff fixes
cleder Jul 18, 2024
7983fdb
better docstrings and ruff fixes
cleder Jul 18, 2024
9d71aaf
better docstrings and ruff fixes
cleder Jul 18, 2024
765d36e
better docstrings and ruff fixes
cleder Jul 18, 2024
a81a586
Apply suggestions from code review
cleder Jul 18, 2024
0e30b63
Update fastkml/features.py
cleder Jul 18, 2024
9e954cf
Merge pull request #336 from cleder/264-test-documentation-with-docte…
cleder Jul 18, 2024
36a7f6d
make __eq__ generic
cleder Jul 18, 2024
0ac5e91
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 22, 2024
931b155
Merge pull request #337 from cleder/pre-commit-ci-update-config
cleder Jul 26, 2024
1dc645d
add basic parse class method to KML #284
cleder Jul 26, 2024
6d04f79
add basic parse class method to KML #284
cleder Jul 26, 2024
251fd83
add basic parse class method to KML #284
cleder Jul 26, 2024
2f69fd9
Update fastkml/kml.py
cleder Jul 26, 2024
8eb9680
ruff format
cleder Jul 26, 2024
75347fe
Merge pull request #338 from cleder/284-add-from_file-or-load-method-…
cleder Jul 26, 2024
f5b76d6
override name_spaces in parse whith obsvered namespace
cleder Jul 26, 2024
518fe3a
Refactor default namespace handling in XMLObject from _default_ns to …
cleder Jul 26, 2024
49aa9c7
fix repr
cleder Jul 27, 2024
c39ce76
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 29, 2024
e91ec55
Refactor geometry.py to include outer_boundary_is and inner_boundary_…
cleder Jul 30, 2024
1cab81a
Merge pull request #339 from cleder/pre-commit-ci-update-config
cleder Aug 1, 2024
dff28d1
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 5, 2024
577d18c
Merge pull request #340 from cleder/pre-commit-ci-update-config
cleder Aug 6, 2024
a01e1f1
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 12, 2024
6979396
Merge pull request #341 from cleder/pre-commit-ci-update-config
cleder Aug 12, 2024
19f3415
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 19, 2024
807c939
Merge pull request #342 from cleder/pre-commit-ci-update-config
cleder Aug 20, 2024
8830734
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 26, 2024
3f65d45
Merge pull request #344 from cleder/pre-commit-ci-update-config
cleder Aug 27, 2024
2fbbfc3
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Sep 2, 2024
58d0de4
Merge pull request #347 from cleder/pre-commit-ci-update-config
cleder Sep 3, 2024
5c9ad59
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Sep 9, 2024
839a433
Merge pull request #348 from cleder/pre-commit-ci-update-config
cleder Sep 10, 2024
48faf51
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Sep 16, 2024
c588bdd
Merge pull request #349 from cleder/pre-commit-ci-update-config
cleder Sep 16, 2024
513a9ac
#351 Add Test for the __repr__ method
cleder Sep 22, 2024
01b6144
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Sep 23, 2024
23782a2
Merge pull request #353 from cleder/pre-commit-ci-update-config
cleder Sep 23, 2024
d04e56b
Refactor contributing documentation and add setup instructions
cleder Sep 25, 2024
744cd50
improve type annotations for tests
cleder Sep 25, 2024
9e8b3b7
run mypy for tests in CI
cleder Sep 25, 2024
456f5cc
add pytest as dependency to typechecking
cleder Sep 25, 2024
27fb7a4
add python 3.14-dev to CI
cleder Sep 25, 2024
031c3b3
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Sep 30, 2024
2480842
Merge pull request #354 from cleder/pre-commit-ci-update-config
cleder Sep 30, 2024
181e2fe
add typos
cleder Oct 1, 2024
9dc9f74
Add test case for #355
cleder Oct 2, 2024
3f760bb
Fix inner boundaries for polygon #355
cleder Oct 2, 2024
118c064
Apply suggestions from code review
cleder Oct 2, 2024
fd61d0b
fix tests
cleder Oct 2, 2024
3ecc272
Merge pull request #356 from cleder/355-interior-rings-not-working-pr…
cleder Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix ruff errors for base classes
cleder committed Jun 20, 2024
commit 24a4852a449d8922aecc78f4a1973dd1f382c3a7
190 changes: 172 additions & 18 deletions fastkml/base.py
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@

logger = logging.getLogger(__name__)

__all__ = ["_XMLObject"]


class _XMLObject:
"""XML Baseclass."""
@@ -46,7 +48,19 @@ def __init__(
name_spaces: Optional[Dict[str, str]] = None,
**kwargs: Any,
) -> None:
"""Initialize the XML Object."""
"""
Initialize the XML Object.

Parameters
----------
ns : Optional[str], default=None
The namespace of the XML object.
name_spaces : Optional[Dict[str, str]], default=None
The dictionary of namespace prefixes and URIs.
**kwargs : Any
Additional keyword arguments.

"""
self.ns: str = self._default_ns if ns is None else ns
name_spaces = name_spaces or {}
self.name_spaces = {**config.NAME_SPACES, **name_spaces}
@@ -55,7 +69,15 @@ def __init__(
self.__kwarg_keys = tuple(kwargs.keys())

def __repr__(self) -> str:
"""Create a string (c)representation for _XMLObject."""
"""
Create a string (c)representation for _XMLObject.

Returns
-------
str
The string representation of the object.

"""
return (
f"{self.__class__.__module__}.{self.__class__.__name__}("
f"ns={self.ns!r}, "
@@ -65,21 +87,59 @@ def __repr__(self) -> str:
)

def __str__(self) -> str:
"""
Return the string representation of the object.

Returns
-------
str
The string representation of the object.

"""
return self.to_string()

def __eq__(self, other: object) -> bool:
"""
Compare two _XMLObject instances for equality.

Parameters
----------
other : object
The object to compare with.

Returns
-------
bool
True if the objects are equal, False otherwise.

"""
if type(self) is not type(other):
return False
assert isinstance(other, type(self))
assert isinstance(other, type(self)) # noqa: S101
return self.ns == other.ns and self.name_spaces == other.name_spaces

def etree_element(
self,
precision: Optional[int] = None,
verbosity: Verbosity = Verbosity.normal,
) -> Element:
"""Return the KML Object as an Element."""
element: Element = config.etree.Element( # type: ignore[attr-defined]
"""
Return the KML Object as an Element.

Parameters
----------
precision : Optional[int], default=None
The precision of the KML object.
verbosity : Verbosity, default=Verbosity.normal
The verbosity level.

Returns
-------
Element
The KML object as an Element.

"""
element: Element = config.etree.Element(
f"{self.ns}{self.get_tag_name()}",
)
for item in registry.get(self.__class__):
@@ -100,15 +160,32 @@ def to_string(
precision: Optional[int] = None,
verbosity: Verbosity = Verbosity.normal,
) -> str:
"""Return the KML Object as serialized xml."""
"""
Return the KML Object as serialized xml.

Parameters
----------
prettyprint : bool, default=True
Whether to pretty print the XML.
precision : Optional[int], default=None
The precision of the KML object.
verbosity : Verbosity, default=Verbosity.normal
The verbosity level.

Returns
-------
str
The KML object as serialized XML.

"""
element = self.etree_element(
precision=precision,
verbosity=verbosity,
)
try:
return cast(
str,
config.etree.tostring( # type: ignore[attr-defined]
config.etree.tostring(
element,
encoding="UTF-8",
pretty_print=prettyprint,
@@ -119,7 +196,7 @@ def to_string(
except TypeError:
return cast(
str,
config.etree.tostring( # type: ignore[attr-defined]
config.etree.tostring(
element,
encoding="UTF-8",
).decode(
@@ -128,6 +205,15 @@ def to_string(
)

def _get_splat(self) -> Dict[str, Any]:
"""
Get the keyword arguments as a dictionary.

Returns
-------
Dict[str, Any]
The keyword arguments as a dictionary.

"""
return {
key: getattr(self, key)
for key in self.__kwarg_keys
@@ -136,11 +222,33 @@ def _get_splat(self) -> Dict[str, Any]:

@classmethod
def get_tag_name(cls) -> str:
"""Return the tag name."""
"""
Return the tag name.

Returns
-------
str
The tag name.

"""
return cls.__name__

@classmethod
def _get_ns(cls, ns: Optional[str]) -> str:
"""
Get the namespace.

Parameters
----------
ns : Optional[str]
The namespace.

Returns
-------
str
The namespace.

"""
return cls._default_ns if ns is None else ns

@classmethod
@@ -152,7 +260,26 @@ def _get_kwargs(
element: Element,
strict: bool,
) -> Dict[str, Any]:
"""Returns a dictionary of kwargs for the class constructor."""
"""
Get the keyword arguments for the class constructor.

Parameters
----------
ns : str
The namespace.
name_spaces : Optional[Dict[str, str]], default=None
The dictionary of namespace prefixes and URIs.
element : Element
The XML element.
strict : bool
Whether to enforce strict parsing.

Returns
-------
Dict[str, Any]
The keyword arguments for the class constructor.

"""
name_spaces = name_spaces or {}
name_spaces = {**config.NAME_SPACES, **name_spaces}
kwargs: Dict[str, Any] = {"ns": ns, "name_spaces": name_spaces}
@@ -183,7 +310,26 @@ def class_from_element(
element: Element,
strict: bool,
) -> Self:
"""Creates an XML object from an etree element."""
"""
Create an XML object from an etree element.

Parameters
----------
ns : str
The namespace.
name_spaces : Optional[Dict[str, str]], default=None
The dictionary of namespace prefixes and URIs.
element : Element
The XML element.
strict : bool
Whether to enforce strict parsing.

Returns
-------
Self
The XML object.

"""
kwargs = cls._get_kwargs(
ns=ns,
name_spaces=name_spaces,
@@ -204,15 +350,23 @@ def class_from_string(
strict: bool = True,
) -> Self:
"""
Creates a geometry object from a string.
Create an XML object from a string.

Args:
----
string: String representation of the geometry object
Parameters
----------
string : str
The string representation of the XML object.
ns : Optional[str], default=None
The namespace of the XML object.
name_spaces : Optional[Dict[str, str]], default=None
The dictionary of namespace prefixes and URIs.
strict : bool, default=True
Whether to enforce strict parsing.

Returns:
Returns
-------
Geometry object
Self
The XML object.

"""
ns = cls._get_ns(ns)
@@ -222,6 +376,6 @@ def class_from_string(
strict=strict,
element=cast(
Element,
config.etree.fromstring(string), # type: ignore[attr-defined]
config.etree.fromstring(string),
),
)
1 change: 1 addition & 0 deletions fastkml/config.py
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
"DEFAULT_NAME_SPACES",
"GXNS",
"KMLNS",
"etree",
"register_namespaces",
"set_default_namespaces",
"set_etree_implementation",
2 changes: 1 addition & 1 deletion fastkml/geometry.py
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ def handle_invalid_geometry_error(
element: Element,
strict: bool,
) -> None:
error_in_xml = config.etree.tostring( # type: ignore[attr-defined]
error_in_xml = config.etree.tostring(
element,
encoding="UTF-8",
).decode(
6 changes: 3 additions & 3 deletions fastkml/gx.py
Original file line number Diff line number Diff line change
@@ -147,13 +147,13 @@ def etree_elements(
) -> Iterator[Element]:
name_spaces = name_spaces or {}
name_spaces = {**config.NAME_SPACES, **name_spaces}
element: Element = config.etree.Element( # type: ignore[attr-defined]
element: Element = config.etree.Element(
f"{name_spaces.get('kml', '')}when",
)
if self.when:
element.text = self.when.isoformat()
yield element
element = config.etree.Element( # type: ignore[attr-defined]
element = config.etree.Element(
f"{name_spaces.get('gx', '')}coord",
)
if self.coord:
@@ -163,7 +163,7 @@ def etree_elements(
],
)
yield element
element = config.etree.Element( # type: ignore[attr-defined]
element = config.etree.Element(
f"{name_spaces.get('gx', '')}angles",
)
if self.angle:
Loading

Unchanged files with check annotations Beta

on:

Check warning on line 1 in .github/workflows/codesee-arch-diagram.yml

GitHub Actions / static-tests (3.12)

1:1 [document-start] missing document start "---"

Check warning on line 1 in .github/workflows/codesee-arch-diagram.yml

GitHub Actions / static-tests (3.12)

1:1 [truthy] truthy value should be one of [false, true]
push:
branches:
- main
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

Check warning on line 12 in .github/workflows/codeql.yml

GitHub Actions / static-tests (3.12)

12:1 [document-start] missing document start "---"
on:

Check warning on line 14 in .github/workflows/codeql.yml

GitHub Actions / static-tests (3.12)

14:1 [truthy] truthy value should be one of [false, true]
push:
branches: ["develop", "main"]
pull_request:
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs

Check warning on line 54 in .github/workflows/codeql.yml

GitHub Actions / static-tests (3.12)

54:101 [line-length] line too long (225 > 100 characters)
# queries: security-extended,security-and-quality
uses: github/codeql-action/autobuild@v3
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

Check warning on line 64 in .github/workflows/codeql.yml

GitHub Actions / static-tests (3.12)

64:101 [line-length] line too long (118 > 100 characters)
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

Check warning on line 67 in .github/workflows/codeql.yml

GitHub Actions / static-tests (3.12)

67:101 [line-length] line too long (119 > 100 characters)
# - run: |
# echo "Run, Build Application using script"
on: [pull_request, issue_comment]

Check warning on line 1 in .github/workflows/pr_agent.yml

GitHub Actions / static-tests (3.12)

1:1 [document-start] missing document start "---"

Check warning on line 1 in .github/workflows/pr_agent.yml

GitHub Actions / static-tests (3.12)

1:1 [truthy] truthy value should be one of [false, true]
jobs:
pr_agent_job:
runs-on: ubuntu-latest
# run tests and lint with a variety of Python versions
---
name: Tests
on: [push, pull_request]

Check warning on line 5 in .github/workflows/run-all-tests.yml

GitHub Actions / static-tests (3.12)

5:1 [truthy] truthy value should be one of [false, true]
jobs:
cpython: