matsoftware / swift-code-metrics Goto Github PK
View Code? Open in Web Editor NEWCode metric analyzer for Swift projects.
License: MIT License
Code metric analyzer for Swift projects.
License: MIT License
This would be helpful to identify where the pain points actually reside within heavily partitioned projects without having to delve into them step-by-step
Changelogs should follow the guidelines defined here: https://keepachangelog.com/en/1.0.0/
GitHub release notes content should be defined inside the CHANGELOG.md
file.
When running on a new installation with the latest numpy (1.20.2) i got a crash
Traceback (most recent call last):
File "/usr/local/bin/swift-code-metrics", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.9/site-packages/swift_code_metrics/scm.py", line 76, in main
from ._graphs_renderer import GraphsRender
File "/usr/local/lib/python3.9/site-packages/swift_code_metrics/_graphs_renderer.py", line 5, in <module>
from ._graphs_presenter import GraphPresenter
File "/usr/local/lib/python3.9/site-packages/swift_code_metrics/_graphs_presenter.py", line 2, in <module>
from ._graph_helpers import Graph
File "/usr/local/lib/python3.9/site-packages/swift_code_metrics/_graph_helpers.py", line 3, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python3.9/site-packages/matplotlib/__init__.py", line 107, in <module>
from . import _api, cbook, docstring, rcsetup
File "/usr/local/lib/python3.9/site-packages/matplotlib/rcsetup.py", line 26, in <module>
from matplotlib.colors import Colormap, is_color_like
File "/usr/local/lib/python3.9/site-packages/matplotlib/colors.py", line 82, in <module>
from matplotlib import _api, cbook, scale
File "/usr/local/lib/python3.9/site-packages/matplotlib/scale.py", line 18, in <module>
from matplotlib.ticker import (
File "/usr/local/lib/python3.9/site-packages/matplotlib/ticker.py", line 179, in <module>
from matplotlib import transforms as mtransforms
File "/usr/local/lib/python3.9/site-packages/matplotlib/transforms.py", line 43, in <module>
from numpy.linalg import inv
ImportError: cannot import name 'inv' from 'numpy.linalg' (unknown location)
It was fixed by installing numpy 1.19.5
iMac:wine-scanner-ios kasper$ pip3 uninstall numpy
Found existing installation: numpy 1.20.2
Uninstalling numpy-1.20.2:
Would remove:
/usr/local/lib/python3.9/site-packages/numpy-1.20.2.dist-info/*
/usr/local/lib/python3.9/site-packages/numpy/.dylibs/libgcc_s.1.dylib
/usr/local/lib/python3.9/site-packages/numpy/.dylibs/libgfortran.3.dylib
/usr/local/lib/python3.9/site-packages/numpy/.dylibs/libopenblas.0.dylib
/usr/local/lib/python3.9/site-packages/numpy/.dylibs/libquadmath.0.dylib
Proceed (y/n)? y
Successfully uninstalled numpy-1.20.2
iMac:wine-scanner-ios kasper$ pip3 install numpy==1.19.5
Collecting numpy==1.19.5
Downloading numpy-1.19.5-cp39-cp39-macosx_10_9_x86_64.whl (15.6 MB)
|████████████████████████████████| 15.6 MB 5.8 MB/s
Installing collected packages: numpy
Successfully installed numpy-1.19.5
The output.json
file should contain a section with:
scm.json
)The library cannot detect when one or more frameworks are included in the same project and therefore they're included in the same folder.
A solution is to provide a json
manifest file to put in the root of the folder to explicitly tell SCM which libraries are included.
~/Deskto: swift-code-metrics --source SwiftNetFrame --artifacts SwiftNetFrameTest --generate-graphs
Traceback (most recent call last):
File "/usr/local/bin/swift-code-metrics", line 10, in
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/scm.py", line 69, in main
if not analyzer.analyze():
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/_analyzer.py", line 21, in analyze
self.__analyze_directory(self.directory, self.exclude_paths, self.tests_default_suffixes)
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/_analyzer.py", line 116, in __analyze_directory
swift_file = SwiftFileParser(file=full_path, base_path=directory, is_test=is_in_test_path).parse()
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/_parser.py", line 99, in parse
framework_name=self.__framework_name(),
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/_parser.py", line 113, in __framework_name
return self.__extracted_framework_name() + suffix
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/_parser.py", line 117, in __extracted_framework_name
first_subpath = self.__extract_first_subpath(subdir)
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/_parser.py", line 126, in __extract_first_subpath
return self.__extract_first_subpath(subdirs[0])
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/_parser.py", line 126, in __extract_first_subpath
return self.__extract_first_subpath(subdirs[0])
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/_parser.py", line 126, in __extract_first_subpath
return self.__extract_first_subpath(subdirs[0])
[Previous line repeated 987 more times]
File "/usr/local/lib/python3.7/site-packages/swift_code_metrics/_parser.py", line 124, in __extract_first_subpath
subdirs = os.path.split(subdir)
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/posixpath.py", line 108, in split
sep = _get_sep(p)
File "/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/posixpath.py", line 42, in _get_sep
if isinstance(path, bytes):
RecursionError: maximum recursion depth exceeded while calling a Python object
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 331, in _error_catcher
yield
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 413, in read
data = self._fp.read(amt)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 447, in read
n = self.readinto(b)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 491, in readinto
n = self.fp.readinto(b)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1049, in recv_into
return self.read(nbytes, buffer)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 908, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 143, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 318, in run
resolver.resolve(requirement_set)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/resolve.py", line 102, in resolve
self._resolve_one(requirement_set, req)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/resolve.py", line 256, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/resolve.py", line 209, in _get_abstract_dist_for
self.require_hashes
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 283, in prepare_linked_requirement
progress_bar=self.progress_bar
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/download.py", line 836, in unpack_url
progress_bar=progress_bar
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/download.py", line 673, in unpack_http_url
progress_bar)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/download.py", line 897, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/download.py", line 617, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/utils/hashes.py", line 48, in check_against_chunks
for chunk in chunks:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/download.py", line 585, in written_chunks
for chunk in chunks:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/utils/ui.py", line 159, in iter
for x in it:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/download.py", line 574, in resp_read
decode_content=False):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 465, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 430, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in exit
self.gen.throw(type, value, traceback)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py", line 336, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
When there's no need of rendering graphs (e.g. when --generate-graphs
is not passed), the matplotlib
module should not be initialized.
I have struggled a bit with installing on the M1 Apple Silicon, but finally managed to get it working.
Here are the steps.
Install a 3.x version of Python with pyenv.
Skip this step if you already have Python 3.x installed or want to install it with another manager
These steps are based on https://laict.medium.com/install-python-on-macos-11-m1-apple-silicon-using-pyenv-12e0729427a9
Install pyenv
brew instal pyenv
Install Python 3.8.6
pyenv install --patch 3.8.6 <<(curl -sSL https://raw.githubusercontent.com/Homebrew/formula-patches/113aa84/python/3.8.3.patch\?full_index\=1)
Set the Python as system default
pyenv global 3.8.6
Install Graphviz and Pygraphviz
Install Graphviz
brew install graphviz
Install Pygraphviz (from pygraphviz/pygraphviz#155 (comment))
pip install --global-option=build_ext --global-option="-I$(brew --prefix graphviz)/include" --global-option="-L$(brew --prefix graphviz)/lib" pygraphviz
Install swift-code-metrics
Install the master branch of swift-code-metrics
pip install --global-option=build_ext --global-option="-I$(brew --prefix graphviz)/include" --global-option="-L$(brew --prefix graphviz)/lib" "git+https://github.com/matsoftware/swift-code-metrics.git#egg=swift-code-metrics"
I'm trying to run the command below but always crash.
swift-code-metrics --version
swift-code-metrics 1.5.1
brew info graphviz
graphviz: stable 2.47.0 (bottled), HEAD
Graph visualization software from AT&T and Bell Labs
https://www.graphviz.org/
/usr/local/Cellar/graphviz/2.47.0 (301 files, 10.5MB) *
Poured from bottle on 2021-03-27 at 12:24:11
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/graphviz.rb
License: EPL-1.0
==> Dependencies
Build: autoconf ✔, automake ✔, bison ✘, pkg-config ✔
Required: gd ✔, gts ✔, libpng ✔, librsvg ✔, libtool ✔, pango ✔
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 79,005 (30 days), 201,535 (90 days), 631,622 (365 days)
install-on-request: 66,252 (30 days), 166,056 (90 days), 507,447 (365 days)
build-error: 0 (30 days)
swift-code-metrics --source . --artifacts metrics --exclude Pods --generate-graphs
NotificationServiceExtension is not linked with the rest of the project.
NotificationServiceExtension is not linked with the rest of the project.
Traceback (most recent call last):
File "/usr/local/bin/swift-code-metrics", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.9/site-packages/swift_code_metrics/scm.py", line 76, in main
from ._graphs_renderer import GraphsRender
File "/usr/local/lib/python3.9/site-packages/swift_code_metrics/_graphs_renderer.py", line 5, in <module>
from ._graphs_presenter import GraphPresenter
File "/usr/local/lib/python3.9/site-packages/swift_code_metrics/_graphs_presenter.py", line 2, in <module>
from ._graph_helpers import Graph
File "/usr/local/lib/python3.9/site-packages/swift_code_metrics/_graph_helpers.py", line 8, in <module>
import pygraphviz as pgv
File "/usr/local/lib/python3.9/site-packages/pygraphviz/__init__.py", line 58, in <module>
from .agraph import AGraph, Node, Edge, Attribute, ItemAttribute, DotError
File "/usr/local/lib/python3.9/site-packages/pygraphviz/agraph.py", line 22, in <module>
from . import graphviz as gv
File "/usr/local/lib/python3.9/site-packages/pygraphviz/graphviz.py", line 28, in <module>
_graphviz = swig_import_helper()
File "/usr/local/lib/python3.9/site-packages/pygraphviz/graphviz.py", line 24, in swig_import_helper
_mod = imp.load_module('_graphviz', fp, pathname, description)
File "/usr/local/Cellar/[email protected]/3.9.2_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/local/Cellar/[email protected]/3.9.2_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: dlopen(/usr/local/lib/python3.9/site-packages/pygraphviz/_graphviz.cpython-39-darwin.so, 2): Symbol not found: _PyIOBase_Type
Referenced from: /usr/local/lib/python3.9/site-packages/pygraphviz/_graphviz.cpython-39-darwin.so
Expected in: flat namespace
in /usr/local/lib/python3.9/site-packages/pygraphviz/_graphviz.cpython-39-darwin.so
I upgraded to the lastest version and now I can't run
Traceback (most recent call last):
File "/usr/local/bin/swift-code-metrics", line 5, in <module>
from swift_code_metrics.scm import main
File "/Library/Python/2.7/site-packages/swift_code_metrics/scm.py", line 5, in <module>
from ._helpers import Log
File "/Library/Python/2.7/site-packages/swift_code_metrics/_helpers.py", line 12
def warn(cls, message: str):
^
SyntaxError: invalid syntax
How to install on Mac...
python3 -m venv .venv
source .venv/bin/activate
brew install graphviz
pip install swift-code-metrics
I would have added this to Wiki -- but it was not turned on ... couldn't access.
The way imports are currently counted prevents @testable
imports from being included in the count. For modules with large numbers of tests this can significantly affect the statistics produced.
Eg:
import MyPackage
is counted as an import.@testable import MyPackage
is not.For example project it works fine, and I receive full report, but the problem starts when I try to use it with my own projects.
I am creating new empty xcode project, with name „TestRaport”, then I run in terminal : swift-code-metrics --source /Desktop/TestRaport --artifacts report --generate-graphs
And I am getting python error:
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/bin/swift-code-metrics", line 11, in <module> sys.exit(main()) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/swift_code_metrics/scm.py", line 67, in main analyzer = Inspector(directory, artifacts, default_tests_paths, exclude) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/swift_code_metrics/_analyzer.py", line 18, in init self._save_report(artifacts) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/swift_code_metrics/_analyzer.py", line 43, in _save_report json.dump(self.report.as_dict, fp, indent=4) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/swift_code_metrics/_analyzer.py", line 218, in as_dict self.non_test_frameworks_key: self.non_test_framework_aggregate.as_dict, File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/swift_code_metrics/_analyzer.py", line 187, in as_dict "poc": ReportingHelpers.decimal_format(self.poc) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/swift_code_metrics/_analyzer.py", line 175, in poc return Metrics.percentage_of_comments(self.noc, self.loc) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/swift_code_metrics/_metrics.py", line 117, in percentage_of_comments return 100 * noc / (noc + loc) ZeroDivisionError: division by zero
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.