Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions #28

Closed
wants to merge 5 commits into from
Closed

Extensions #28

wants to merge 5 commits into from

Conversation

dg-pb
Copy link
Contributor

@dg-pb dg-pb commented May 27, 2024

a) Correct extending _ext
b) Support for mac specific extension modules
c) Support custom attributes for dot graph

Copy link
Owner

@mgedmin mgedmin left a comment

Choose a reason for hiding this comment

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

This PR appears to have two unrelated purposes:

  • some kind of fix for self._exts
  • a new --attrs feature

Both have some minor problems (wrong .so extension, missing semicolon for attrs).

I would prefer two separate PRs for each. Also, I would like to have a PR description that's suitable for pasting into the changelog.

digraph ModuleDependencies {
rankdir=TB
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't there be a ; at the end of this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per documentation attributes has no semicolon

Copy link
Owner

Choose a reason for hiding this comment

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

But the grammar at https://graphviz.org/doc/info/lang.html shows that a graph has a ;-separated statement list inside the { }, and ID = ID is just one possible form of a statement.

I admit that I only checked the grammar and haven't actually tried running dot on any of the example graphs.

Copy link
Owner

Choose a reason for hiding this comment

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

I have tried it now, and dot from graphviz 2.43.0 accepts both spellings (with ; and without ;), and then rewrites them both into graph [rankdir=TB];

Oh! I misread the grammar! The ; separator in the statement list is optional everywhere!

Still, since findimports adds ; after nodes and edges, I'd like it to add ; after attributes as well, for consistency.

findimports.py Show resolved Hide resolved
findimports.py Show resolved Hide resolved
findimports.py Show resolved Hide resolved
self._exts.append(f".{sys._multiarch}.so")
if hasattr(sys, 'platform'):
ver = ''.join(map(str, sys.version_info[:2]))
self._exts.append(f'.cpython-{ver}-{sys.platform}.so')
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is right. sys.platform is "linux", but all the modules in /usr/lib/python3.12/lib-dynload/ use "x86_64-linux-gnu" in this spot on my machine.

You want sysconfig.get_config_var('EXT_SUFFIX') here.

(Personally, I don't even remember what self._exts is used for. Discovering whether named Python modules exist on disk?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a fallback for determining if it is a module.

@@ -51,6 +51,8 @@
nothing are removed.
-D MAX_DEPTH, --depth MAX_DEPTH
import depth in ast tree. Default: no limit
--attrs ATTRIBUTES Add custom attributes to dot graph.
Specified as json string.
Copy link
Owner

Choose a reason for hiding this comment

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

Wouldn't it be more convenient to do -a rank=TB instead of --attrs '{"rank": "TB"}'? Spelling out JSON on the command line is a pain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, depends on how many attributes. If it is just one or 2 I go with multiple-argument flag, if it can be more of a small config size, I use JSON and quite happy about it. But I don't see this used often so I am ok with your suggestion as well.

@dg-pb
Copy link
Contributor Author

dg-pb commented May 27, 2024

Split into 2 other PRs

@dg-pb dg-pb closed this May 27, 2024
@dg-pb dg-pb deleted the extensions branch May 27, 2024 17:40
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.

2 participants