tucan


Nametucan JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://gitlab.com/cerfacs/tucan
SummaryUnformatter Tool to allow parsing and analysis of code base.
upload_time2024-02-01 12:05:43
maintainer
docs_urlNone
authorAntoine Dauptain, Thibault Marzlin, CoopTeam-CERFACS
requires_python>=3.8
license
keywords code fortran python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![tucan](https://images.unsplash.com/photo-1611788542170-38cf842212f4?q=80&w=2940&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D)

TUCAN (Tool to Unformat, Clean, ands Analyse) is a code parser for scientific codebases. It tager languages are:
- Very old FORTRAN
- Recent FORTRAN
- Python (Under development)
- C/C++ (Eazrly development)

## What is does?


### Remove Coding archaisms

First is it a code cleaner. For example, this loop in `tranfit.f' a piece of CHEMKIN package  good'old FORTRAN:

```fortran
(547)      DO 2000 K = 1, KK-1
(548)         DO 2000 J = K+1, KK
(549)            DO 2000 N = 1, NO
(550)               COFD(N,J,K) = COFD(N,K,J)
(551) 2000 CONTINUE
```

Is translated  with the command `tucan clean tranfit.f` as : 
```fortran
(547-547)        do 2000 k  =  1,kk-1
(548-548)           do 2000 j  =  k+1,kk
(549-549)              do 2000 n  =  1,no
(550-550)                 cofd(n,j,k)  =  cofd(n,k,j)
(551-551)              end do ! 2000
(551-551)           end do ! 2000
(551-551)        end do ! 2000
```



The cleaned version simplify the code for further analysis passes, like computing cyclomatic complexity, extracting structures, etc...


### Extracting code structure

On the same file `tucan struct tranfit.f` provides a nested dictionary of the code structure. Here is an exemple from a code in very recent fortran:

```yaml
type htable.h_tuple_t :
    At path ['htable', 'h_tuple_t'], name h_tuple_t, lines 47 -> 52
    6 statements over 6 lines
    Complexity 1
    Refers to 1 callables:
       - class
    Contains no inner structures
    Contains no annotations

type_public_abstract htable.htable_t :
    At path ['htable', 'htable_t'], name htable_t, lines 55 -> 64
    10 statements over 10 lines
    Complexity 1
    Refers to 2 callables:
       - pass
       - t
    Contains no inner structures
    Contains no annotations

function_pure htable.interface_abstract66.htable_hash :
    At path ['htable', 'interface_abstract66', 'htable_hash'], name htable_hash, lines 67 -> 72
    6 statements over 6 lines
    Complexity 1
    Refers to 2 callables:
       - class
       - htable_hash
    Contains no inner structures
    Contains no annotations

interface_abstract htable.interface_abstract66 :
    At path ['htable', 'interface_abstract66'], name interface_abstract66, lines 66 -> 73
    8 statements over 8 lines
    Complexity 1
    Contains no callables
    Contains 1 elements:
    - htable.interface_abstract66.htable_hash
    Contains no annotations
```

This information allows the creation and manipulation of graphs to extract the structure of the code


### Interpreting IFDEFS 

An other nasty example is the use of ìfdefs in C or FORTRAN:

```
#ifdef FRONT
        WRITE(*,*) " FRONT is enabled " ! partial front subroutine
        SUBROUTINE dummy_front(a,b,c)
        WRITE(*,*) " FRONT 1"     ! partial front subroutine
#else                
        SUBROUTINE dummy_front(a,d,e)
        WRITE(*,*) " FRONT 2"       ! partial front subroutine
#endif
        END SUBROUTINE

        SUBROUTINE dummy_back(a,b,c)
#ifdef BACK
        WRITE(*,*) " FRONT is enabled " ! partial front subroutine
        WRITE(*,*) " BACK 1"    ! partial back subroutine
        END SUBROUTINE  
#else
        WRITE(*,*) " BACK 2"    ! partial back subroutine
        END SUBROUTINE  
#endif
```

Depending on the pre-definition of variables FRONT and BACK, this code snippet can be read in four ways possible.
Here are usages:

`tucan ifdef-clean templates_ifdef.f` yields:

```fortran
        SUBROUTINE dummy_front(a,d,e)
        WRITE(*,*) " FRONT 2"       ! partial front subroutine
        END SUBROUTINE

        SUBROUTINE dummy_back(a,b,c)


        WRITE(*,*) " BACK 2"    ! partial back subroutine
        END SUBROUTINE
```


`tucan ifdef-clean templates_ifdef.f -v FRONT` yields:

```fortran
        WRITE(*,*) " FRONT is enabled " ! partial front subroutine
        SUBROUTINE dummy_front(a,b,c)
        WRITE(*,*) " FRONT 1"     ! partial front subroutine


        END SUBROUTINE

        SUBROUTINE dummy_back(a,b,c)


        WRITE(*,*) " BACK 2"    ! partial back subroutine
        END SUBROUTINE
```

`tucan ifdef-clean templates_ifdef.f -v FRONT,BACK` yields:

```fortran
         WRITE(*,*) " FRONT is enabled " ! partial front subroutine
        SUBROUTINE dummy_front(a,b,c)
        WRITE(*,*) " FRONT 1"     ! partial front subroutine


        END SUBROUTINE

        SUBROUTINE dummy_back(a,b,c)
        WRITE(*,*) " BACK is enabled " ! partial front subroutine
        WRITE(*,*) " BACK 1"    ! partial back subroutine
        END SUBROUTINE
```

## More about tucan

`Tucan` is used by  `anubis`, our open-source  tool to explore the git repository of a code, and `marauder's map`  our open-source tool to show codes structures by in-depth vizualisation of callgraphs and code circular-packing .


            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/cerfacs/tucan",
    "name": "tucan",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "code,fortran,python",
    "author": "Antoine Dauptain, Thibault Marzlin, CoopTeam-CERFACS",
    "author_email": "coop@cerfacs.fr",
    "download_url": "https://files.pythonhosted.org/packages/9d/4b/d9e48958684c1efefc43a22326b09500208fdcf0e04836bb1ad874789d5d/tucan-0.1.0.tar.gz",
    "platform": null,
    "description": "![tucan](https://images.unsplash.com/photo-1611788542170-38cf842212f4?q=80&w=2940&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D)\n\nTUCAN (Tool to Unformat, Clean, ands Analyse) is a code parser for scientific codebases. It tager languages are:\n- Very old FORTRAN\n- Recent FORTRAN\n- Python (Under development)\n- C/C++ (Eazrly development)\n\n## What is does?\n\n\n### Remove Coding archaisms\n\nFirst is it a code cleaner. For example, this loop in `tranfit.f' a piece of CHEMKIN package  good'old FORTRAN:\n\n```fortran\n(547)      DO 2000 K = 1, KK-1\n(548)         DO 2000 J = K+1, KK\n(549)            DO 2000 N = 1, NO\n(550)               COFD(N,J,K) = COFD(N,K,J)\n(551) 2000 CONTINUE\n```\n\nIs translated  with the command `tucan clean tranfit.f` as : \n```fortran\n(547-547)        do 2000 k  =  1,kk-1\n(548-548)           do 2000 j  =  k+1,kk\n(549-549)              do 2000 n  =  1,no\n(550-550)                 cofd(n,j,k)  =  cofd(n,k,j)\n(551-551)              end do ! 2000\n(551-551)           end do ! 2000\n(551-551)        end do ! 2000\n```\n\n\n\nThe cleaned version simplify the code for further analysis passes, like computing cyclomatic complexity, extracting structures, etc...\n\n\n### Extracting code structure\n\nOn the same file `tucan struct tranfit.f` provides a nested dictionary of the code structure. Here is an exemple from a code in very recent fortran:\n\n```yaml\ntype htable.h_tuple_t :\n    At path ['htable', 'h_tuple_t'], name h_tuple_t, lines 47 -> 52\n    6 statements over 6 lines\n    Complexity 1\n    Refers to 1 callables:\n       - class\n    Contains no inner structures\n    Contains no annotations\n\ntype_public_abstract htable.htable_t :\n    At path ['htable', 'htable_t'], name htable_t, lines 55 -> 64\n    10 statements over 10 lines\n    Complexity 1\n    Refers to 2 callables:\n       - pass\n       - t\n    Contains no inner structures\n    Contains no annotations\n\nfunction_pure htable.interface_abstract66.htable_hash :\n    At path ['htable', 'interface_abstract66', 'htable_hash'], name htable_hash, lines 67 -> 72\n    6 statements over 6 lines\n    Complexity 1\n    Refers to 2 callables:\n       - class\n       - htable_hash\n    Contains no inner structures\n    Contains no annotations\n\ninterface_abstract htable.interface_abstract66 :\n    At path ['htable', 'interface_abstract66'], name interface_abstract66, lines 66 -> 73\n    8 statements over 8 lines\n    Complexity 1\n    Contains no callables\n    Contains 1 elements:\n    - htable.interface_abstract66.htable_hash\n    Contains no annotations\n```\n\nThis information allows the creation and manipulation of graphs to extract the structure of the code\n\n\n### Interpreting IFDEFS \n\nAn other nasty example is the use of \u00ecfdefs in C or FORTRAN:\n\n```\n#ifdef FRONT\n        WRITE(*,*) \" FRONT is enabled \" ! partial front subroutine\n        SUBROUTINE dummy_front(a,b,c)\n        WRITE(*,*) \" FRONT 1\"     ! partial front subroutine\n#else                \n        SUBROUTINE dummy_front(a,d,e)\n        WRITE(*,*) \" FRONT 2\"       ! partial front subroutine\n#endif\n        END SUBROUTINE\n\n        SUBROUTINE dummy_back(a,b,c)\n#ifdef BACK\n        WRITE(*,*) \" FRONT is enabled \" ! partial front subroutine\n        WRITE(*,*) \" BACK 1\"    ! partial back subroutine\n        END SUBROUTINE  \n#else\n        WRITE(*,*) \" BACK 2\"    ! partial back subroutine\n        END SUBROUTINE  \n#endif\n```\n\nDepending on the pre-definition of variables FRONT and BACK, this code snippet can be read in four ways possible.\nHere are usages:\n\n`tucan ifdef-clean templates_ifdef.f` yields:\n\n```fortran\n        SUBROUTINE dummy_front(a,d,e)\n        WRITE(*,*) \" FRONT 2\"       ! partial front subroutine\n        END SUBROUTINE\n\n        SUBROUTINE dummy_back(a,b,c)\n\n\n        WRITE(*,*) \" BACK 2\"    ! partial back subroutine\n        END SUBROUTINE\n```\n\n\n`tucan ifdef-clean templates_ifdef.f -v FRONT` yields:\n\n```fortran\n        WRITE(*,*) \" FRONT is enabled \" ! partial front subroutine\n        SUBROUTINE dummy_front(a,b,c)\n        WRITE(*,*) \" FRONT 1\"     ! partial front subroutine\n\n\n        END SUBROUTINE\n\n        SUBROUTINE dummy_back(a,b,c)\n\n\n        WRITE(*,*) \" BACK 2\"    ! partial back subroutine\n        END SUBROUTINE\n```\n\n`tucan ifdef-clean templates_ifdef.f -v FRONT,BACK` yields:\n\n```fortran\n         WRITE(*,*) \" FRONT is enabled \" ! partial front subroutine\n        SUBROUTINE dummy_front(a,b,c)\n        WRITE(*,*) \" FRONT 1\"     ! partial front subroutine\n\n\n        END SUBROUTINE\n\n        SUBROUTINE dummy_back(a,b,c)\n        WRITE(*,*) \" BACK is enabled \" ! partial front subroutine\n        WRITE(*,*) \" BACK 1\"    ! partial back subroutine\n        END SUBROUTINE\n```\n\n## More about tucan\n\n`Tucan` is used by  `anubis`, our open-source  tool to explore the git repository of a code, and `marauder's map`  our open-source tool to show codes structures by in-depth vizualisation of callgraphs and code circular-packing .\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Unformatter Tool to allow parsing and analysis of code base.",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://gitlab.com/cerfacs/tucan/-/issues",
        "Documentation": "https://tucan.readthedocs.io/en/latest/",
        "Homepage": "https://gitlab.com/cerfacs/tucan"
    },
    "split_keywords": [
        "code",
        "fortran",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61475f8f2a00c4e06d8001bbe86d3ebeedaae68897dcffcf109ed6857e3e8ff6",
                "md5": "1a5c423fe38a9b8bc5c948b91b6bf2ef",
                "sha256": "79680bd4722066e7bd95aec8b365d5510743c7908918cc47cc4b8be3aa8cf425"
            },
            "downloads": -1,
            "filename": "tucan-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1a5c423fe38a9b8bc5c948b91b6bf2ef",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 34269,
            "upload_time": "2024-02-01T12:05:41",
            "upload_time_iso_8601": "2024-02-01T12:05:41.128962Z",
            "url": "https://files.pythonhosted.org/packages/61/47/5f8f2a00c4e06d8001bbe86d3ebeedaae68897dcffcf109ed6857e3e8ff6/tucan-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d4bd9e48958684c1efefc43a22326b09500208fdcf0e04836bb1ad874789d5d",
                "md5": "752d62fde0c6109ffa9b03e459b64ee7",
                "sha256": "05079d38254a53e86e617d71ba8c11dd69f22d3e1ed8832771501cb3b09c15b5"
            },
            "downloads": -1,
            "filename": "tucan-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "752d62fde0c6109ffa9b03e459b64ee7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 82016,
            "upload_time": "2024-02-01T12:05:43",
            "upload_time_iso_8601": "2024-02-01T12:05:43.828748Z",
            "url": "https://files.pythonhosted.org/packages/9d/4b/d9e48958684c1efefc43a22326b09500208fdcf0e04836bb1ad874789d5d/tucan-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-01 12:05:43",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "cerfacs",
    "gitlab_project": "tucan",
    "lcname": "tucan"
}
        
Elapsed time: 0.19291s