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

Can this generate pyproject.toml from requirements.txt or from import statements #141

Open
datatalking opened this issue Dec 15, 2023 · 3 comments

Comments

@datatalking
Copy link

I've been looking at building a tool that generates 'pyproject.toml' files from my python scripts and found this repo on Github.

What I'm looking for:

  1. you pip install <package name>
  2. Once its installed it scans the python code and generates the pyproject.toml file based on the existing scripts, settings or .idea since we are 100% a jetbrains shop.
  3. I'd like to help update the docs on a few items so you will see me lurking around the repo, loving the design of this.
@diazona
Copy link
Owner

diazona commented Dec 15, 2023

Nice, thanks for checking this out! Any contributions you care to offer would be much appreciated.

I think the use case you're describing of making a pyproject.toml from requirements.txt or the contents of a virtualenv would be out of scope for this project. We're specifically focused on converting setup.py files or other setuptools configuration files, and requirements.txt isn't really a project configuration file in that sense - it only handles dependencies, not other metadata (like project name, version, etc.).

I'm sure it would be a handy thing to build as a separate tool though. There are definitely cases where people could use that.

@sjlongland
Copy link
Collaborator

I seem to recall there was a tool that could analyse the Python import statements and figure out what external modules you were using, with a view to maintaining the metadata to match.

Quick search reveals https://pypi.org/project/pip-module-scanner/ -- there looks to be an API one might be able to use to get a listing of packages/versions.

Accuracy is a big question at this stage. There are a few ways to write an import statement, statements can appear anywhere in the code, and therefore be subject to control flow statements.

So lots of edge cases there that might trip things up, causing a dependency to be erroneously included or omitted.

That said, this isn't a reason to throw away the idea, it could be quite useful to supply the basic project metadata on the command line, then use a tool like that above to figure out what dependencies should be put there. Hand-massaging might be needed at the end, but it may still save significant effort.

@datatalking
Copy link
Author

@sjlongland @diazona i'll play with this repo a little and will look at the ''module-scanner' you mention.

I might bookend the front of your repo with one that starts with [black] or [ruff] linters and 'requirements.txt'.

Maybe I could call it "pyprojectoml_generator"?

Then once those are created point the user to your repo for expansion, that way we can support your work and stay in scope.

Users with a Python script, that just has import statements.

  1. We scan the .py file
  2. They could be linted with black or ruff.
  3. We generate the requirements file
  4. We generate a README.md (I already built this)
  5. We generate supporting folders for data, tests, model (I already built this)
  6. Generating a setup.py should be an interesting issue programmatically since my IDE just does this with a click of a button.

If I understand correctly, with the exception of step 6, I should this to be enough for me to code up a prototype of this in a week or two.

"Scoped to support a broad array of brand new, advanced and supporting data migrating users to provide a path to better pyproject.toml files."

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

No branches or pull requests

3 participants