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

#47 Remove deprecated code #167

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Version 1.8.1, 2024-07-xx
`#157 <https://github.com/roskakori/pygount/issues/157>`_).
* Development: Change default branch to main (issue
`#160 <https://github.com/roskakori/pygount/issues/160>`_).
* Removed deprecated code: (contributed by Marco Gambone and Niels Vanden Bussche, issue
`#47 <https://github.com/roskakori/pygount/issues/47>`_).

Version 1.8.0, 2024-05-13

Expand Down
3 changes: 1 addition & 2 deletions pygount/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# All rights reserved. Distributed under the BSD License.
from importlib.metadata import version

from .analysis import DuplicatePool, SourceAnalysis, SourceScanner, SourceState, encoding_for, source_analysis
from .analysis import DuplicatePool, SourceAnalysis, SourceScanner, SourceState, encoding_for
from .common import Error, OptionError
from .summary import LanguageSummary, ProjectSummary

Expand All @@ -23,5 +23,4 @@
"SourceAnalysis",
"SourceScanner",
"SourceState",
"source_analysis",
]
46 changes: 1 addition & 45 deletions pygount/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import pygount.common
import pygount.lexers
import pygount.xmldialect
from pygount.common import deprecated, mapped_repr
from pygount.common import mapped_repr
from pygount.git_storage import GitStorage, git_remote_url_and_revision_if_any

# Attempt to import chardet.
Expand Down Expand Up @@ -432,26 +432,6 @@ def source_count(self) -> int:
"""number of source lines of code (the sum of code_count and string_count)"""
return self.code_count + self.string_count

@property
def code(self) -> int:
# TODO #47: Remove deprecated property.
return self._code

@property
def documentation(self) -> int:
# TODO #47: Remove deprecated property.
return self._documentation

@property
def empty(self) -> int:
# TODO #47: Remove deprecated property.
return self._empty

@property
def string(self) -> int:
# TODO #47: Remove deprecated property.
return self._string

@property
def state(self) -> SourceState:
"""
Expand Down Expand Up @@ -873,11 +853,6 @@ def encoding_for(
return result


@deprecated(f"use {SourceAnalysis.__name__}.{SourceAnalysis.from_state.__name__}")
def pseudo_source_analysis(source_path, group, state, state_info=None):
return SourceAnalysis.from_state(source_path, group, state, state_info)


#: BOMs to indicate that a file is a text file even if it contains zero bytes.
_TEXT_BOMS = (codecs.BOM_UTF16_BE, codecs.BOM_UTF16_LE, codecs.BOM_UTF32_BE, codecs.BOM_UTF32_LE, codecs.BOM_UTF8)

Expand Down Expand Up @@ -917,25 +892,6 @@ def guess_lexer(source_path: str, text: str) -> pygments.lexer.Lexer:
return result


@deprecated(f"use {SourceAnalysis.__name__}.{SourceAnalysis.from_file.__name__}")
def source_analysis(
source_path,
group,
encoding="automatic",
fallback_encoding="cp1252",
generated_regexes: Optional[List[Pattern]] = None,
duplicate_pool: Optional[DuplicatePool] = None,
):
actual_generated_regexes = (
generated_regexes
if generated_regexes is not None
else pygount.common.regexes_from(DEFAULT_GENERATED_PATTERNS_TEXT)
)
return SourceAnalysis.from_file(
source_path, group, encoding, fallback_encoding, actual_generated_regexes, duplicate_pool
)


def base_language(language: str) -> str:
base_language_match = _BASE_LANGUAGE_REGEX.match(language)
return language if base_language_match is None else base_language_match.group("base_language")
22 changes: 0 additions & 22 deletions tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,6 @@ def test_can_guess_lexer_for_cmakelists():
assert lexer.name == "CMake"


def test_can_use_deprecated_counts():
source_analysis = analysis.SourceAnalysis("some.py", "Python", "some", 1, 2, 3, 4, analysis.SourceState.analyzed)
assert source_analysis.code == source_analysis.code_count
assert source_analysis.documentation == source_analysis.documentation_count
assert source_analysis.empty == source_analysis.empty_count
assert source_analysis.string == source_analysis.string_count


class EncodingTest(TempFolderTest):
_ENCODING_TO_BOM_MAP = {encoding: bom for bom, encoding in _BOM_TO_ENCODING_MAP.items()}
_TEST_CODE = "x = '\u00fd \u20ac'"
Expand Down Expand Up @@ -484,20 +476,6 @@ def test_has_no_duplicate_in_pygount_source():
assert duplicate_path is None, f"{source_path} must not be duplicate of {duplicate_path}"


def test_can_match_deprecated_functions():
source_path = __file__
group = "some"
assert str(analysis.source_analysis(source_path, group)) == str(
analysis.SourceAnalysis.from_file(source_path, group)
)

missing_path = "missing.py"
reason = "missing"
assert str(analysis.pseudo_source_analysis(missing_path, group, analysis.SourceState.error, reason)) == str(
analysis.SourceAnalysis.from_state(missing_path, group, analysis.SourceState.error, reason)
)


def test_can_compute_base_language():
assert base_language("JavaScript") == "JavaScript"
assert base_language("JavaScript+Lasso") == "JavaScript"
Expand Down
Loading