Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python: ["3.10", "3.11", "3.12", "3.13"]
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repository
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Why a new PyPi package? Well, the not-so-great PyPi doesn't allow to have forked

# PyCG - Practical Python Call Graphs

[![Tests](https://github.com/deeplime-io/PyCG/actions/workflows/test.yaml/badge.svg)](https://github.com/vitsalis/PyCG/actions/workflows/test.yaml)
[![Tests](https://github.com/deeplime-io/PyCG/actions/workflows/test.yaml/badge.svg)](https://github.com/deeplime-io/PyCG/actions/workflows/test.yaml)

PyCG generates call graphs for Python code using static analysis.
It efficiently supports
Expand All @@ -33,7 +33,7 @@ In _43rd International Conference on Software Engineering, ICSE '21_,

# Installation

PyCG is implemented in Python3 and requires Python version 3.4 or higher.
PyCG is implemented in Python3 and requires Python 3.10–3.14.
It also has no dependencies. Simply:
```
pip install onecode-pycg
Expand Down
5 changes: 3 additions & 2 deletions pycg/processing/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ def __init__(

def _get_fun_defaults(self, node):
defaults = {}
start = len(node.args.args) - len(node.args.defaults)
pos_args = node.args.posonlyargs + node.args.args
start = len(pos_args) - len(node.args.defaults)
for cnt, d in enumerate(node.args.defaults, start=start):
if not d:
continue

self.visit(d)
defaults[node.args.args[cnt].arg] = self.decode_node(d)
defaults[pos_args[cnt].arg] = self.decode_node(d)

start = len(node.args.kwonlyargs) - len(node.args.kw_defaults)
for cnt, d in enumerate(node.args.kw_defaults, start=start):
Expand Down
69 changes: 69 additions & 0 deletions pycg/tests/preprocessor_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# Copyright (c) 2020 Vitalis Salis.
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import ast
import os
import tempfile

from base import TestBase

from pycg.machinery.classes import ClassManager
from pycg.machinery.definitions import DefinitionManager
from pycg.machinery.imports import ImportManager
from pycg.machinery.modules import ModuleManager
from pycg.machinery.scopes import ScopeManager
from pycg.processing.preprocessor import PreProcessor


class PreprocessorTest(TestBase):
def _make_preprocessor(self, code):
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
f.write(code)
fname = f.name

im = ImportManager()
sm = ScopeManager()
dm = DefinitionManager()
cm = ClassManager()
mm = ModuleManager()
pp = PreProcessor(fname, "mod", im, sm, dm, cm, mm, modules_analyzed=set())
return pp, fname

def test_get_fun_defaults_posonlyargs(self):
code = "def eye(n_rows, n_cols=None, /): pass\n"
pp, fname = self._make_preprocessor(code)
try:
node = ast.parse(code).body[0]
defaults = pp._get_fun_defaults(node)
self.assertIn("n_cols", defaults)
self.assertEqual(defaults["n_cols"], [None])
finally:
os.unlink(fname)

def test_get_fun_defaults_positional_or_keyword(self):
code = "def f(a, b=1): pass\n"
pp, fname = self._make_preprocessor(code)
try:
node = ast.parse(code).body[0]
defaults = pp._get_fun_defaults(node)
self.assertIn("b", defaults)
self.assertEqual(defaults["b"], [1])
finally:
os.unlink(fname)
55 changes: 21 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
[project]
name = "onecode-pycg"
version = "1.2.0"

version = "1.2.1"
description = "PyCG - Practical Python Call Graphs"
readme = "README.md"
requires-python = ">=3.4"

licence = { file = "LICENCE" }
requires-python = ">=3.10,<3.15"
license = { file = "LICENCE" }
authors = [{ name = "Vitalis Salis", email = "vitsalis@gmail.com" }]


maintainers = [{ name = "DeepLime", email = "contact@deeplime.io" }]
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]

[project.scripts]
pycg = "pycg.__main__:main"

[project.optional-dependencies]
dev = ["flake8>=6.0.0", "isort>=5.12.0", "black>=22.12.0", "mock"]
dev = ["ruff>=0.8.0", "mock"]

[project.urls]
"Homepage" = "https://github.com/vitsalis/PyCG"
"Bug Tracker" = "https://github.com/vitsalis/PyCG/issues"
Homepage = "https://github.com/deeplime-io/PyCG"
"Bug Tracker" = "https://github.com/deeplime-io/PyCG/issues"
Repository = "https://github.com/deeplime-io/PyCG"

[build-system]
requires = ["hatchling"]
Expand All @@ -29,33 +35,14 @@ build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
packages = ["pycg"]

[tool.black]
line-length = 88
target_version = ['py38', 'py39', 'py310', 'py311', 'py312']
preview = true
exclude = '''
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.mypy_cache
| \.vscode
| build
| dist
| micro-benchmark
| micro-benchmark-key-errs
)/
'''

[tool.ruff]
exclude = ["micro-benchmark", "micro-benchmark-key-errs"]
target-version = "py310"

[tool.ruff.lint]
# Do not enforce `E501` (line length violations) for now.
ignore = ["E501"]

exclude = ["micro-benchmark", "micro-benchmark-key-errs"]

# Ignore `E402` (import violations) in all `__init__.py` files
[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402", "F401"]


[tool.isort]
profile = "black"
4 changes: 0 additions & 4 deletions requirements-dev.txt

This file was deleted.

Empty file removed requirements.txt
Empty file.
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

61 changes: 0 additions & 61 deletions setup.py

This file was deleted.

Loading
Loading