Skip to content

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

@thatch thatch merged commit 8873151 into main Nov 12, 2024
29 checks passed
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.

3 participants