0

I read through the documentation (https://pypi.org/project/pygount/1.2.0/), but I am still confused. When running pygount in my root directory, how to I skip all folders that start with "_X" (recursive, so skip any nested folders that start with that, too).

This runs, but I don't know if it is doing what I think it is: pygount --suffix=py --format=summary --folders-to-skip='**/_X*'

a11
  • 3,122
  • 4
  • 27
  • 66
  • If you think you have a solution, then consider running it in a small, controlled test environment, rather than on root. If it works there and excludes the directories you want excluded, it probably works on root as well. – Silvio Mayolo Feb 28 '23 at 20:20

1 Answers1

1

TL;DR: Use --folders-to-skip with a list of patterns for folder-names, not paths.

Example

We can't reproduce, because your question is missing an example folder structure. First let's create it with two simple Linux shell-commands (e.g. zsh, bash).

Next, we can test different arguments for the parameter --folders-to-skip.

Create the sample directory structure

Create directories (2 levels deep):

$ mkdir -p pygount/src{1..3}/{A..C}                                                                                     

Then create the files, one in each directory:

$ touch pygount/src{1..3}/{A..C}/code.py

Now we have following structure:

$ tree pygount                                                                                                          
pygount
├── src1
│   ├── A
│   │   └── code.py
│   ├── B
│   │   └── code.py
│   └── C
│       └── code.py
├── src2
│   ├── A
│   │   └── code.py
│   ├── B
│   │   └── code.py
│   └── C
│       └── code.py
└── src3
    ├── A
    │   └── code.py
    ├── B
    │   └── code.py
    └── C
        └── code.py

12 directories, 9 files

Using pygount, without skipping

The simple way, without skipping:

$ pygount --suffix=py pygount                                                                                           0       __empty__       pygount pygount/src1/A/code.py
0       __empty__       pygount pygount/src1/B/code.py
0       __empty__       pygount pygount/src1/C/code.py
0       __empty__       pygount pygount/src2/A/code.py
0       __empty__       pygount pygount/src2/B/code.py
0       __empty__       pygount pygount/src2/C/code.py
0       __empty__       pygount pygount/src3/A/code.py
0       __empty__       pygount pygount/src3/B/code.py
0       __empty__       pygount pygount/src3/C/code.py

Issue: Just provide a single folder-name as pattern

PyGount doesn't work with paths for the parameter, like you may know from other Linux commands like ls:

$ ls **/C                                                                                                               pygount/src1/C:
code.py

pygount/src2/C:
code.py

pygount/src3/C:
code.py

See how a path given with --folders-to-skip='**/C' doesn't get matched:

$ pygount --suffix=py --folders-to-skip='**/C' pygount                                                                  0       __empty__       pygount pygount/src1/A/code.py
0       __empty__       pygount pygount/src1/B/code.py
0       __empty__       pygount pygount/src1/C/code.py
0       __empty__       pygount pygount/src2/A/code.py
0       __empty__       pygount pygount/src2/B/code.py
0       __empty__       pygount pygount/src2/C/code.py
0       __empty__       pygount pygount/src3/A/code.py
0       __empty__       pygount pygount/src3/B/code.py
0       __empty__       pygount pygount/src3/C/code.py

Using pygount with skipped folder-names

Instead the folders to skip are expected as single folder-names given as list. See the description for related parameter --names-to-skip in the docs:

To specify alternative patterns, use --folders-to-skip and --names-to-skip. Both take a comma separated list of patterns, see below on the pattern syntax. To for example also prevent folders starting with two underscores (_) from being analyzed, specify --folders-to-skip=[...],__*.

Now skipping inner folders named C:

$ pygount --suffix=py --folders-to-skip='C' pygount                                                                     0       __empty__       pygount pygount/src1/A/code.py
0       __empty__       pygount pygount/src1/B/code.py
0       __empty__       pygount pygount/src2/A/code.py
0       __empty__       pygount pygount/src2/B/code.py
0       __empty__       pygount pygount/src3/A/code.py
0       __empty__       pygount pygount/src3/B/code.py

It skipped every folder, that has a name like C, even recursively. So it yields the same effect like path **/C.

Concept of globs

For the different concept of filename and path patterns (globbing) on Unix-like systems like glob, extended glob or globstar (**) see also:

hc_dev
  • 8,389
  • 1
  • 26
  • 38