Skip to content
Snippets Groups Projects
example.ipynb 2.33 KiB
Newer Older
Xuefeng Ding's avatar
Xuefeng Ding committed
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import myproj.simulation as ms\n",
Xuefeng Ding's avatar
Xuefeng Ding committed
    "import numpy as np\n",
Xuefeng Ding's avatar
Xuefeng Ding committed
    "\n",
    "print(ms.add(1, 2))\n",
Xuefeng Ding's avatar
Xuefeng Ding committed
    "print(ms.complex(1, 2))\n",
    "print(np.array([1, 2, 3]))"
Xuefeng Ding's avatar
Xuefeng Ding committed
   ]
Xuefeng Ding's avatar
Xuefeng Ding committed
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pylint\n",
    "\n",
    "pylint.run_pylint([\"myproj/simulation\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from astroid.interpreter._import import util\n",
    "\n",
    "print(util.is_namespace(\"myproj\"))"
   ]
Xuefeng Ding's avatar
Xuefeng Ding committed
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from io import StringIO\n",
    "\n",
    "import pylint.lint\n",
    "from pylint.reporters import JSONReporter\n",
    "\n",
Xuefeng Ding's avatar
Xuefeng Ding committed
    "root = \"/datafs/users/dingxf/neutrino-physics-tutorial/scikit-build-cpp-python\"\n",
Xuefeng Ding's avatar
Xuefeng Ding committed
    "\n",
    "# Define the Pylint options\n",
    "pylint_options = [\n",
    "    \"--reports=n\",\n",
    "    \"--output-format=json\",\n",
    "    \"--extension-pkg-allow-list=simulation._csrc._hello\",\n",
    "    \"--prefer-stubs=true\",\n",
    "    \"--clear-cache-post-run=y\",\n",
Xuefeng Ding's avatar
Xuefeng Ding committed
    "    f\"{root}/python/myproj/simulation/core.py\",  # The file you want to lint\n",
Xuefeng Ding's avatar
Xuefeng Ding committed
    "]\n",
    "\n",
    "# Create a StringIO buffer to capture Pylint output\n",
    "pylint_output = StringIO()\n",
    "reporter = JSONReporter(output=pylint_output)\n",
    "\n",
    "# Run Pylint\n",
    "pylint.lint.Run(pylint_options, reporter=reporter, exit=True)\n",
    "\n",
    "# Get the output\n",
    "output = pylint_output.getvalue()\n",
    "\n",
    "# Parse and display the results\n",
    "results = json.loads(output)\n",
    "print(json.dumps(results, indent=2))"
   ]
Xuefeng Ding's avatar
Xuefeng Ding committed
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "dingxf",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}