diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..e23fb5a8 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,23 @@ +{ + "recommendations": [ + // + //-- Used for IDE, Workbench, Tools -------------------------------------------- + // + "editorconfig.editorconfig", + "VisualStudioExptTeam.vscodeintellicode", + // + //-- Used for linters, formatters ---------------------------------------------- + // + "ms-python.python", + "ms-python.vscode-pylance", + "charliermarsh.ruff", + "njpwerner.autodocstring", + "njqdev.vscode-python-typehint", + // "ms-python.mypy-type-checker", + // + //-- Used for: Git, Code Quality ----------------------------------------------- + // + "vivaxy.vscode-conventional-commits", + "codezombiech.gitignore" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 181da6b2..df5c95a5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,17 +2,55 @@ "version": "0.2.0", "configurations": [ { - "name": "Python: Debug File", - "type": "python", + "name": "python: with Args", + "type": "debugpy", "request": "launch", "program": "${file}", - "console": "integratedTerminal" + "args": "${input:arguments}", + "cwd": "${input:debug_working_dir}", + "justMyCode": true, + "autoReload": { + "enable": true + } }, { - "name": "Python: Module", - "type": "python", + "name": "python: Within Libs", + "type": "debugpy", "request": "launch", - "module": "petl" + "program": "${file}", + "args": "${input:last_arguments}", + "cwd": "${input:debug_working_dir}", + "justMyCode": false, + "autoReload": { + "enable": true + } } + ], + "inputs": [ + { + // Usage: "args": "${input:arguments}", + "id": "arguments", + "type": "promptString", + "description": "Which arguments to pass to the command?" + }, + { + // Usage: "cwd": "${input:debug_working_dir}" + "id": "debug_working_dir", + "type": "pickString", + "description": "Debug the python program in which of these folders?", + "options": [ + "${fileDirname}", + "${fileWorkspaceFolder}", + "${fileWorkspaceFolder}/petl", + "${fileWorkspaceFolder}/petl/tests", + "${fileWorkspaceFolder}/examples", + "${relativeFileDirname}", + "${userHome}", + "${cwd}", + "${selectedText}", + "" + ], + "default": "${fileDirname}" + }, ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 071c936a..1fdb1135 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,73 +1,121 @@ { - // SETTINGS OF EDITOR FOR ALL FILES - "editor.formatOnSave": false, // for reducing git changes for now + //-- Editor settings for all files ------------------------------------------------- + // + "editor.formatOnSave": false, // Using this for reducing git changes between commits "editor.formatOnPaste": true, "editor.tabSize": 4, "editor.wordWrapColumn": 83, - "editor.renderWhitespace": "trailing", + "editor.renderWhitespace": "boundary", "files.eol": "\n", "files.encoding": "utf8", + // + //-- Editor settings for search/view files ----------------------------------------- + // "files.exclude": { + // python "**/.tox": true, + "**/.nox": true, "**/.eggs": true, "**/*.egg-info": true, "**/__pycache__": true, + "**/__pypackages__": true, "**/.pylint.d": true, "**/.cache": true, "**/.mypy_cache": true, "**/.pytest_cache": true, + "**/.ruff_cache": true, + "**/.ipynb_checkpoints": true, "**/*.pyc": true, "**/*.egg": true, + "**/*.pyenv": true, + "**/*.pytype": true, "**/.vscode-server": true, }, "files.watcherExclude": { + // git "**/.git/objects/**": true, "**/.git/subtree-cache/**": true, - "**/.tox/*/**": true, - "**/.eggs/*/**": true, - "**/*.egg-info/*/**": true, - "**/__pycache__/*/**": true, - "**/.cache/*/**": true, - "**/.mypy_cache/*/**": true, - "**/.pytest_cache/*/**": true, - "**/logs/*/**": true, + // python + "**/.tox": true, + "**/.nox": true, + "**/.eggs": true, + "**/*.egg-info": true, + "**/__pycache__": true, + "**/__pypackages__": true, + "**/.cache": true, + "**/.mypy_cache": true, + "**/.pytest_cache": true, + "**/.ruff_cache": true, + "**/.ipynb_checkpoints": true, "**/*.pyc": true, "**/*.egg": true, + "**/*.venv": true, + "**/*.pyenv": true, + "**/*.pytype": true, + "**/_build": true, + "**/build": true, + "**/dist": true, + "**/site-packages": true, + // others + "**/logs": true, "**/*.log": true, - "**/.vscode-server/*/**": true, + "**/.vscode-server": true, "**/example.*": true, }, "search.exclude": { + // git "**/.git/objects/**": true, "**/.git/subtree-cache/**": true, - "**/.tox/*/**": true, - "**/.eggs/*/**": true, - "**/*.egg-info/*/**": true, - "**/__pycache__/*/**": true, - "**/.cache/*/**": true, - "**/.mypy_cache/*/**": true, - "**/.pytest_cache/*/**": true, - "**/logs/*/**": true, + // python + "**/.tox": true, + "**/.nox": true, + "**/.eggs": true, + "**/*.egg-info": true, + "**/__pycache__": true, + "**/__pypackages__": true, + "**/.cache": true, + "**/.mypy_cache": true, + "**/.pytest_cache": true, + "**/.ruff_cache": true, + "**/.ipynb_checkpoints": true, "**/*.pyc": true, "**/*.egg": true, + "**/*.venv": true, + "**/*.pyenv": true, + "**/*.pytype": true, + "**/_build": true, + "**/build": true, + "**/dist": true, + "**/site-packages": true, + // others "**/*.log": true, - "**/.vscode-server/*/**": true, + "**/logs": true, + "**/.vscode-server": true, "**/example.*": true, }, + // + //-- Python language settings ------------------------------------------------------ + // "[python]": { - // SETTINGS OF FOR PYTHON + // Editor settings for python files "editor.tabSize": 4, "editor.wordWrapColumn": 83, "files.eol": "\n", "files.encoding": "utf8", - // "editor.trimAutoWhitespace": true, // disabled for now - // "files.trimFinalNewlines": true, // for reducing git changes due to whitespaces - // "files.trimTrailingWhitespace": true, - // SETTINGS EXCLUSIVE TO PYTHON + "editor.defaultFormatter": "charliermarsh.ruff", + // "editor.defaultFormatter": "ms-python.black-formatter", + //-- Settings for keeping source code compatibility + "editor.codeActionsOnSave": { + "source.fixAll": "explicit", + "source.organizeImports": "explicit" + }, "editor.insertSpaces": true, "files.insertFinalNewline": true, + //-- Settings to reduce git changes due to whitespaces up source code (disabled for now) + // "editor.trimAutoWhitespace": true, + // "files.trimFinalNewlines": true, + // "files.trimTrailingWhitespace": true, }, - "python.formatting.provider": "black", "python.autoComplete.extraPaths": [ "${workspaceFolder}/petl/", "${workspaceFolder}/petl/io/", @@ -76,12 +124,15 @@ "${workspaceFolder}/petl/test/", "${workspaceFolder}/petl/test/io", ], - "python.linting.enabled": true, - "python.linting.maxNumberOfProblems": 12, - "python.linting.ignorePatterns": [ + // + //-- Python analysis/tools settings ------------------------------------------------ + // + "python.analysis.logLevel": "Warning", + "pylint.ignorePatterns": [ ".vscode/*.py", ".git", ".tox", + ".nox", ".venv", ".eggs", ".egg-info", @@ -91,17 +142,15 @@ "__pycache__", "_build", "*.pyc", + ".vscode", ".vscode-server", ], - "python.linting.pylintEnabled": true, - "python.linting.pylintArgs": [ + "pylint.args": [ "--max-line-length=83", "--reports=y", "--disable=import-error,invalid-name,bad-continuation,import-outside-toplevel,missing-module-docstring,missing-function-docstring,trailing-whitespace,line-too-long,bad-whitespace" ], - "python.analysis.logLevel": "Warning", - "python.linting.flake8Enabled": true, - "python.linting.flake8Args": [ + "flake8.args": [ "--max-line-length", "83", "--max-complexity", @@ -111,8 +160,7 @@ "--exclude", ".git,.tox,.venv,.eggs,.egg-info,.cache,.mypy_cache,.pytest_cache,.vscode,__pycache__,_build,*.pyc,.vscode-server" ], - "python.linting.mypyEnabled": false, - "python.linting.mypyArgs": [ + "mypy-type-checker.args": [ "--allow-untyped-defs", "--allow-untyped-calls", "--allow-untyped-globals", @@ -129,5 +177,9 @@ "${workspaceFolder}/petl/util/", "${workspaceFolder}/petl/test/", "${workspaceFolder}/petl/test/io" + ], + "bandit.args": [ + "--configfile", + "${workspaceFolder}/pyproject.toml" ] } \ No newline at end of file diff --git a/examples/notes/issue_219.py b/examples/notes/issue_219.py index 25a91f63..48b94f4a 100644 --- a/examples/notes/issue_219.py +++ b/examples/notes/issue_219.py @@ -25,7 +25,7 @@ # -%memit print tbl_dummy_data.nrows() +print tbl_dummy_data.nrows() # @@ -43,17 +43,17 @@ # -%memit -r1 tbl_dummy_data.progress(10000).todb(psql_connection, 'issue_219') +tbl_dummy_data.progress(10000).todb(psql_connection, 'issue_219') # # memory usage using default cursor -%memit print etl.fromdb(psql_connection, 'select * from issue_219 order by foo').look(2) +print etl.fromdb(psql_connection, 'select * from issue_219 order by foo').look(2) # # memory usage using server-side cursor -%memit print etl.fromdb(lambda: psql_connection.cursor(name='server-side'), 'select * from issue_219 order by foo').look(2) +print etl.fromdb(lambda: psql_connection.cursor(name='server-side'), 'select * from issue_219 order by foo').look(2) # @@ -72,15 +72,15 @@ # -%memit -r1 tbl_dummy_data.progress(10000).todb(mysql_connection, 'issue_219') +tbl_dummy_data.progress(10000).todb(mysql_connection, 'issue_219') # # memory usage with default cursor -%memit print etl.fromdb(mysql_connection, 'select * from issue_219 order by foo').look(2) +print etl.fromdb(mysql_connection, 'select * from issue_219 order by foo').look(2) # # memory usage with server-side cursor -%memit print etl.fromdb(lambda: mysql_connection.cursor(MySQLdb.cursors.SSCursor), 'select * from issue_219 order by foo').look(2) +print etl.fromdb(lambda: mysql_connection.cursor(MySQLdb.cursors.SSCursor), 'select * from issue_219 order by foo').look(2) diff --git a/pyproject.toml b/pyproject.toml index 257f1f9d..d1622bb8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,8 @@ [build-system] requires = ["setuptools", "setuptools-scm", "wheel"] + +[tool.bandit] +exclude_dirs = ["bin", "docs"] + +[tool.bandit.assert_used] +skips = ["*/*_test.py", "*/test_*.py"] diff --git a/requirements-linting.txt b/requirements-linting.txt new file mode 100644 index 00000000..538f5889 --- /dev/null +++ b/requirements-linting.txt @@ -0,0 +1,17 @@ +## Used as main formatter/linter: + +ruff >= 0.3 + +# Used in Github: + +pylint >= 3.0.0 +flake8 >= 7.0.0 +black >= 24.0.0 +bandit[toml,sarif] >= 1.7.0 + +## Suggestions: + +# pre-commit + +#? Obs: Should work with python >= 3.8 +