Package: archan
ArchanAnalysis of your architecture strength based on DSM data.A Python module that analyzes your architecture strength
based onDesign Structure Matrix (DSM)data.Archan is a Python module that analyzes the strength of your
project architecture according to some criteria described in"The Protection of Information in Computer Systems", written by
Jerome H. Saltzer and Michael D. Schroeder.FeaturesUsable directly on the command-line.Support for plugins. See for example theProvider pluginindependenpy.
You can also take a look atdjango-meerkat, a Django app using Archan.Configurable through command-line or configuration file (YAML format).Read DSM data on standard input.InstallationWithpip:pipinstallarchanWithpipx:python3.8-mpipinstall--userpipx
pipxinstallarchanUsageArchan defines three main classes: Analyzer, Provider and Checker.
A provider is an object that will produce data and return it in the form of
a DSM (Design Structure Matrix). The checker is an object that
will analyze this DSM according to some criteria, and return a status code
saying if the criteria are verified or not. An analyzer is just a combination
of providers and checkers to run a analysis test suite.On the command-lineExamples:$archan-husage: archan [-c FILE] [-h] [-i FILE] [-l] [--no-color] [--no-config] [-v]Analysis of your architecture strength based on DSM dataoptional arguments:-c FILE, --config FILE  Configuration file to use.-h, --help              Show this help message and exit.-i FILE, --input FILE   Input file containing CSV data.-l, --list-plugins      Show the available plugins. Default: false.--no-color              Do not use colors. Default: false.--no-config             Do not load configuration from file. Default: false.-v, --version           Show the current version of the program and exit.# See a list of all supported Archan pluginsarchan--list-plugins# Archan can locate the configuration file automatically (See the Configuration section)archan# or a specific configuration can be specifiedarchan--configmy_config.yml# Archan can load DSM data in CSV format such as the output from dependenpy (install separately)dependenpypytest--format=csv--outputpytest_dsm.csv# Read CSV data from file (No configuration)archan--no-config--inputpytest_dsm.csv# or read CSV data from STDINdependenpypytest--format=csv|archan--no-configConfigurationArchan applies the following methods to find the configuration file folder:read the contents of the file.configconfigin the current directory
to get the path to the configuration directory,useconfigfolder in the current directory if it exists,use the current directory.It then searches for a configuration file named:archan.ymlarchan.yaml.archan.yml.archan.yamlFormat of the configuration file is as follow:analyzers:[list of strings and/or dict]-identifier:[optional string]name:[string]description:[string]providers:[string or list]-provider.Name:[as string or dict]provider_arguments:as key value pairscheckers:[string or list]-checker.Name:[as string or dict]checker_arguments:as key value pairsIt means you can write:analyzers:# a first analyzer with one provider and several checker-name:My first analyzerdescription:Optional descriptionproviders:just.UseThisProvidercheckers:-and.ThisChecker-and.ThisOtherChecker:which:hassome:arguments# a second analyzer with several providers and one checker-name:My second analyzerproviders:-use.ThisProvidercheckers:and.ThisChecker# a third analyzer, using its name directly-some.AnalyzerEvery checker support anignoreargument, set to True or False (default).
If set to True, the check will not make the test suit fail.You can reuse the same providers and checkers in different analyzers, they
will be instantiated as different objects and won't interfere between each other.As an example, seeArchan's own configuration file.To get the list of available plugins in your current environment,
runarchan --list-pluginsorarchan -l.Writing a pluginPlugin discoveryYou can write three types of plugins: analyzers, providers and checkers.
Your plugin does not need to be in an installable package. All it needs to
be summoned is to be available in your current Python path. However, if you want
it to be automatically discovered by Archan, you will have to make it installable,
through pip or simplypython setup.py installcommand or equivalent.If you decide to write a Python package for your plugin, I recommend you
to name itarchan-your-pluginfor consistency. If you plan to make it live
along other code in an already existing package, just leave the name as it is.To make your plugin discoverable by Archan, use thearchanentry point
in yoursetup.py:fromsetuptoolsimportsetupsetup(...,'entry_points':{'archan':['mypackage.MyPlugin = mypackage.mymodule:MyPlugin',]}If you build your package with Poetry, use this instead:[tool.poetry.plugins.archan]"mypackage.MyPlugin"="mkdocstrings.plugin:MkdocstringsPlugin"The name of the entry point should by convention be composed of the name of
your package in lower case, a dot, and the name of the Python class, though
you can name it whatever you want. Remember that this name will be the one
used in the configuration file.Also a good thing is to make the plugin importable thanks to its name only:importmypackage.MyPluginBut again, this is just a convention.Plugin classYou can write three types of plugins: analyzers, providers and checkers.
For each of them, you have to inherit from its corresponding class:fromarchanimportAnalyzer,Provider,CheckerclassMyAnalyzer(Analyzer):...classMyProvider(Provider):...classMyChecker(Checker):...A provider or checker plugin must have the following class attributes:identifier: the identifier of the plugin. It must be the same name as in
your entry points, so that displaying its help tells how to summon it.name: the verbose name of the plugin.description: a description to explain what it does.(optional) arguments: a tuple/list of Argument instances. This one is only
used to display some help for the plugin. An argument is composed of a name,
a type, a description and a default value.fromarchanimportProvider,ArgumentclassMyProvider(Provider):identifier='mypackage.MyProvider'name='This is my Provider'description="""Don't hesitate to use multi-line strings as the lines will be de-indented,concatenated again and wrapped to match the console width.Blank lines will be kept though, so the above line will not be removed."""arguments=(Argument('my_arg',int,'This argument is useful.',42),# don't forget the ending comma if you have just one   ^   argument)Additionally, a checker plugin should have thehintclass attribute (string).
The hint describe what you should do if the check fails.For now, the analyzers plugins just have theprovidersandcheckersclass attributes.Plugin methodsA provider must implement theget_dsm(self, **kwargs)method. This method
must return an instance ofDSM. A DSM is composed of a two-dimensions
array, the matrix, a list of strings, the keys or names for each line/column
of the matrix, and optionally the categories for each key (a list of same size).fromarchanimportDSM,ProviderclassMyProvider(Provider):name='mypackage.MyProvider'defget_dsm(self,my_arg=42,**kwargs):# this is where you compute your stuffmatrix_data=[...]entities=[...]categories=[...]orNone# and return a DSM instancereturnDSM(matrix_data,entities,categories)A checker must implement thecheck(self, dsm, **kwargs)method.fromarchanimportDSM,CheckerclassMyChecker(Checker):name='mypackage.MyChecker'defcheck(self,dsm,**kwargs):# this is where you check your stuff# with dsm.data, dsm.entities, dsm.categories, dsm.size (rows, columns)...# and return True, False, or a constant from Checker: PASSED or FAILED# with an optional messagereturnChecker.FAILED,'too much issues in module XXX'Logging messagesEach plugin instance has aloggerattribute available. Use it to log
messages withself.logger.debug,info,warning,errororcritical.Available pluginsHere is the list of plugins available in other packages.See other plugins published to PyPi by searching for"archan-"Providersdependenpy.InternalDependencies: Provide matrix data about internal
dependencies in a set of packages. Install it withpip install dependenpy.