Skip to content

Make htmlreport installable single package#6335

Merged
firewave merged 31 commits intocppcheck-opensource:mainfrom
vpetrigo:feature/installable_htmlreport
May 7, 2024
Merged

Make htmlreport installable single package#6335
firewave merged 31 commits intocppcheck-opensource:mainfrom
vpetrigo:feature/installable_htmlreport

Conversation

@vpetrigo
Copy link
Copy Markdown
Contributor

Hello!

I would like to propose a set of changes to make cppcheck-htmlreport installable. That would allow to easliy install that module via pip, pipx, etc.

For example, with pipx you can install cppcheck-htmlreport executable as follow:

pipx install "git+https://github.com/vpetrigo/cppcheck@feature/installable_htmlreport#subdirectory=htmlreport"

That also allows populating Pygments into user's environment automatically. No need to switch to the htmlreport and execute pip install . or something.

After that the user is able to use cppcheck-htmlreport without installation of DEB/RPM packages. Moreover, on Windows it allows usage of this utility withot necessity to execute it like that, because shebans are not supported there:

python <path/to/script>/cppcheck-htmlreport

That changes can be used for publishing the package to the PyPI if needed.

Let me know if you would like me to update/change something in this PR.

Thank you!

@firewave
Copy link
Copy Markdown
Collaborator

Thanks for your contribution.

It is has been quite a while since I did a Python package so I am not sure how well I can comment on that. So just some generic observations.

Would this work as intended? We rarely touch this but this would decouple the script from the binary. So usually the versions would be in sync but now you have be running different versions and that might lead to issues in the future. We definitely do not intend to have some sort of backwards compatibility being maintained in the script. And on a non-rolling distro without something brew/universe/AUR the cppcheck version is usually lacking way behind whereas the version in PyPi would be the latest. I am not sure we actually want to publish that.

Please make sure you properly rename cppcheck-htmlreport in git so we do not lose the history. Currently it looks like you just renamed it in the filesystem and git doesn't report it as moved/renamed. (I know that it sometimes just doesn't work - git is weird).

We also need to make sure that it will still work for existing users/installations so we possibly need some kind of compatibility layer/link. That might get in the way of renaming the file though.

You also removed the executable flag from test_htmlreport.py. No idea if that was intentional.

@vpetrigo vpetrigo force-pushed the feature/installable_htmlreport branch from 98c1b17 to ea9713d Compare April 23, 2024 21:38
@vpetrigo
Copy link
Copy Markdown
Contributor Author

@firewave, thank you for the prompt reply!

You also removed the executable flag from test_htmlreport.py. No idea if that was intentional.

That was Windows removing this flag for some reason. Should be fixed now.

Please make sure you properly rename cppcheck-htmlreport in git so we do not lose the history. Currently it looks like you just renamed it in the filesystem and git doesn't report it as moved/renamed. (I know that it sometimes just doesn't work - git is weird).

Should be fixed, thank you for pointing out!

Would this work as intended? We rarely touch this but this would decouple the script from the binary.

With those changes I can install the cppcheck-htmlreport with pip/pipx and it is available as an executable:

cppcheck\htmlreport $ pip install .

Processing d:\projects\python\cppcheck\htmlreport
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: Pygments in d:\projects\python\cppcheck\venv\lib\site-packages (from cppcheck-htmlreport==0.0.0) (2.17.2)
Building wheels for collected packages: cppcheck-htmlreport
  Building wheel for cppcheck-htmlreport (pyproject.toml) ... done
  Created wheel for cppcheck-htmlreport: filename=cppcheck_htmlreport-0.0.0-py3-none-any.whl size=11757 sha256=b167955971dbe4e7031402012fe2c9dcd5c06d83c0189daa4fe5dccd963c5b02
  Stored in directory: C:\Users\vladi\AppData\Local\Temp\pip-ephem-wheel-cache-nq44u7vz\wheels\42\5c\77\bd3ae971d3662d84cd1ec450ecf4d5bb4dca8e679d08ee5b6c
Successfully built cppcheck-htmlreport
Installing collected packages: cppcheck-htmlreport
Successfully installed cppcheck-htmlreport-0.0.0
# ===========================================================================
cppcheck\htmlreport $ gcm cppcheck-htmlreport

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     cppcheck-htmlreport.exe                            0.0.0.0    D:\Projects\python\cppcheck\venv\Scripts\cppcheck-htmlreport.exe

# ===========================================================================

cppcheck\htmlreport $ cppcheck-htmlreport --help   
Usage: cppcheck-htmlreport [options]

Options:
  -h, --help            show this help message and exit
  --title=TITLE         The title of the project.
  --file=FILE           The cppcheck xml output file to read defects from. You can combine results from several xml reports i.e. "--file file1.xml --file file2.xml ..". Default is reading from stdin.   
  --report-dir=REPORT_DIR
                        The directory where the HTML report content is written.
  --source-dir=SOURCE_DIR
                        Base directory where source code files can be found.
  --add-author-information=ADD_AUTHOR_INFORMATION
                        Blame information to include. Adds specified author information. Specify as comma-separated list of either "name", "email", "date" or "n","e","d". Default: "n,e,d"
  --source-encoding=SOURCE_ENCODING
                        Encoding of source code.
  --blame-options=BLAME_OPTIONS
                        [-w, -M] blame options which you can use to get author and author mail  -w --> not including white spaces and returns original author of the line  -M --> not including moving    
                        of lines and returns original author of the line

I am not sure what you mean by

this would decouple the script from the binary

cppcheck-htmlreport is not part of Windows install package for example. On Fedora/CentOS it is also distibuted as a separate package. 🤔

One of the options I see to preserve backward compatibility:

htmlreport/
    └── cppcheck_htmlreport/
        ├── cppcheck_htmlreport.py -> cppcheck-htmlreport
        └── ....
    └── cppcheck-htmlreport # original file

Would you tell if that makes sense for you?

@firewave
Copy link
Copy Markdown
Collaborator

cppcheck-htmlreport is not part of Windows install package for example.

That seems like an oversight. Please file a ticket about that.

On Fedora/CentOS it is also distibuted as a separate package.

But those should have a fixed dependency on the cppcheck package with the same version so they are tightly coupled. Having a quick look at the Fedora package confirms that - https://fedora.pkgs.org/39/fedora-x86_64/cppcheck-htmlreport-2.12.1-1.fc39.x86_64.rpm.html.

So if you pull it from PyPi you might get the latest script but have an outdated binary. Although many distros now discourage pulling from PyPi and ask you to install the python-* packages from their repo instead.
Since there is already a regular package in distros installing it form PyPi as well would cause a conflict. So this would mainly be something for local installs.

We should also add a test to the CI to make sure that it works and doesn't break in the future. That should be possible by using a virtualenv and would go into scriptcheck.yml.

@vpetrigo
Copy link
Copy Markdown
Contributor Author

So if you pull it from PyPi you might get the latest script but have an outdated binary.

PyPI provides package's version support. If you release cppcheck-htmlreport it can have the same version as the main cppcheck binary. So, if an user installs a package from PyPI they is able to provide a constrain, e.g. cppcheck-htmlreport==2.14. Frankly speaking, I do not see an issue here, especially since setup.py provides a way to get version from a version control.

It may be benefitial to provide a way to install report generation tool only. For example, we may have a device that runs analysis processes and publish XML reports as artifacts. A QA engineer may want to create a report from that artifacts, so it seems reasonable that they may want to install only HTML generation tool instead of full-featured CppCheck environment they will not use.

We should also add a test to the CI to make sure that it works and doesn't break in the future. That should be possible by using a virtualenv and would go into scriptcheck.yml.

Sure, will update that.

@vpetrigo vpetrigo force-pushed the feature/installable_htmlreport branch from 10b6f2d to 8feaad5 Compare April 24, 2024 00:03
@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Apr 24, 2024

Thanks @vpetrigo and @firewave

We rarely touch this but this would decouple the script from the binary.

that is a very good observation that I did not think about directly. So as far as I see we can make pretty drastic changes to cppcheck binary without affecting the compatibility with cppcheck-htmlreport. We can rename every command line flag for instance. But changing the xml file format would break compatibility with cppcheck-htmlreport.

@firewave
Copy link
Copy Markdown
Collaborator

But changing the xml file format would break compatibility with cppcheck-htmlreport.

Yeah - I totally blanked on it just depending on the XML output and not the CLI. I have actually never used it (or at least not for many, many, many years) but only adjusted tests for it.

@vpetrigo
Copy link
Copy Markdown
Contributor Author

So as far as I see we can make pretty drastic changes to cppcheck binary without affecting the compatibility with cppcheck-htmlreport.

Current changes take the version from the Git. So, if a user installs cppcheck-htmlreport something like that (my fork does not have version tags assigned, so the version is somewhat related to dev):

$ pip install "git+https://github.com/vpetrigo/cppcheck@feature/installable_htmlreport#subdirectory=htmlreport"
$ pip list
Package             Version
------------------- ---------------------
cppcheck-htmlreport 0.1.dev28213+ga111c84
pip                 24.0
Pygments            2.17.2

And it provides an understanding that the current cppcheck-htmlreport script was installed from a repo with cppcheck of that version. If something goes wrong, a user can resinstall it using a newer version for example.

Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.. I know nothing about python packaging though.

@vpetrigo
Copy link
Copy Markdown
Contributor Author

If it is required, let me know if you want to change cppcheck-htmlreport script versioning for distribution at some point. I will be glad to help.

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Apr 26, 2024

@firewave do you think I can merge?

@firewave
Copy link
Copy Markdown
Collaborator

Will take a proper look this weekend.

Comment thread .gitignore Outdated
**/*.egg-info/

# cppcheck-htmlreport auto files
htmlreport/cppcheck_htmlreport/run.py
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be fixates on the root i.e. start with a slash?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that should be updated!

Comment thread htmlreport/setup.py Outdated
"cppcheck-htmlreport",
],
install_requires=['Pygments']
author="Henrik Nilsson",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danmar Erm...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.. could we change author to "Cppcheck team" perhaps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated that.

Comment thread htmlreport/setup.py
},
test_suite="tests",
install_requires=["Pygments"],
setup_requires=["setuptools>=60", "setuptools-scm>=7.0"],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need those specific versions? Please add a small comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will add a comment. That is the requirement of the stable version of the setuptool-scm package that allows getting package version from a source control.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment was added.

Comment thread htmlreport/tox.ini Outdated
@@ -1,12 +1,15 @@
[tox]
envlist=py26,py27,py32,pypy
envlist = py26,py27,py32,pypy,pip
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we no longer need the py26 stuff. Also Python 2.7 needs to be officially deprecated (I filed https://trac.cppcheck.net/ticket/12682 about that).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can remove that. I have not found any usage of tox though in the CI scripts you have. Would you confirm if it is still in use?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have do not even have an idea what tox is...

If this is unused we should just remove it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep the file please make sure it was moved within git. Currently it shows up as deleted/added.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW Python 2.7 is deprecated now and the leftovers will be removed after the next release.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be moved. At least commit history show it that way:
image

Not sure why it shows up as removed and created under the "File changed" tab.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have encountered this before. It seems to be a bug or at least some quirk within git/GitHub - and a bad one. Fortunately it only occurred with unimportant files so far.

Copy link
Copy Markdown
Collaborator

@firewave firewave May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a known GitHub issue: https://github.com/orgs/community/discussions/43177

And it explains why we have only seen it with "unimportant( i.e. small files). It was kind of my assumption that it happens if there were "too many" changes in a moved file.

@vpetrigo vpetrigo requested a review from firewave May 5, 2024 12:35
@firewave
Copy link
Copy Markdown
Collaborator

firewave commented May 6, 2024

Sorry for being so pedantic about things (I wouldn't call it thorough) but we have so much cruft in our codebase so it makes sense to to take of that while at it.

Also often external submissions are one-shots and we should get those as proper as possible because applying them otherwise there are further pieces to pick up later on. Possibly by somebody else...and possibly not for years...

@vpetrigo vpetrigo force-pushed the feature/installable_htmlreport branch from 80f9c06 to 4a3cdb2 Compare May 6, 2024 13:16
htmlreport/test_htmlreport.py
test/tools/htmlreport/test_htmlreport.py
cd htmlreport
./check.sh
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be moved to test/tools/htmlreport

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be updated.

Comment thread test/tools/htmlreport/tox.ini Outdated
[testenv:pip]
setenv = PIP_PACKAGE_TEST=1

[testenv:py26]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be removed as we no longer specify it above.

But I really think we can just drop the whole file as it is about automated testing and we never used in the repo. If somebody external depends on it they will raise this issue and we can then re-add it and also implement it in our CI.

It was added in 97119b8 and the referenced page in that commit doesn't even exist anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tox.ini removed from the repository.

Comment thread test/tools/htmlreport/check.sh Outdated
PYTHON=python
fi

PROJECT_ROOT_DIR=$(git rev-parse --show-toplevel)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if you are running this from a source package without a repo.

In other scripts we use DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" to get the script dir. And then traverse back from that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now.

ERRORLIST_XML="$REPORT_DIR/errorlist.xml"
UNMATCHEDSUPPR_XML="$REPORT_DIR/unmatchedSuppr.xml"

$PYTHON cppcheck-htmlreport --file ../gui/test/data/xmlfiles/xmlreport_v2.xml --title "xml2 test" --report-dir "$REPORT_DIR" --source-dir ../test/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ew. Glad we moved that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be also removed from the script?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - that is totally fine.

I was just commenting how that is a good thing that we got rid of the relative paths.

Switch from git project root to POSIX project root getter
@firewave firewave self-requested a review May 7, 2024 12:04
Copy link
Copy Markdown
Collaborator

@firewave firewave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. If CI passes we can merge this.

vpetrigo added 4 commits May 7, 2024 14:34
Update test cases where Python expects cppcheck-htmlreport script to be in the same directory
Update test cases where Python expects cppcheck-htmlreport script to be in the same directory
@vpetrigo vpetrigo requested a review from danmar May 7, 2024 16:18
@firewave firewave merged commit f562ff2 into cppcheck-opensource:main May 7, 2024
@firewave
Copy link
Copy Markdown
Collaborator

firewave commented May 7, 2024

Thanks a lot for your contribution. And especially your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants