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

Add basic setup.py extraction #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add basic setup.py extraction #4

wants to merge 1 commit into from

Conversation

thatch
Copy link
Member

@thatch thatch commented Sep 20, 2024

Not that impressive, but a starting point that works for simple enough cases with only stdlib.

  1. It's less accurate about qualified names of imports
  2. It can't handle assignment to locals and using that as an arg
  3. It marks too-complex cases a bit more obviously, although kwargs currently get a pass
  4. It requires that setup.py (if it exists) be parseable in the current python, and raises otherwise
  5. Could probably use some more tests to validate I got the dotted lookup even remotely right (import setuptools and from setuptools import setup are all I've really checked)

I would estimate this only works for ~40% of the real-world setup.py, while the dowsing impl works for more like ~70%. I'm intending to use this for hdeps . support right now, but the same basic code would be useful in a future advice that migrates to pep621 metadata (right now we don't save any positions, so editing the args is not possible). See past use in opine for how this might be used.

@thatch thatch requested a review from amjith September 20, 2024 01:33
return True


class QualifiedNameSaver(ShortCircuitingVisitor):
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: currently doesn't use the short-circuiting feature for anything but skipping func(setup(...)) by accident.

Path(d, "setup.py").write_text(
"from setuptools import setup; setup(install_requires=blarg)"
)
with self.assertRaises(ValueError):
Copy link
Member Author

Choose a reason for hiding this comment

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

Ought to match on message too

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.

1 participant