r/learnpython • • May 05 '26

I built a script that initializes Python Projects - Please give me feedback

I have a Github repo that has a Python script in it. I've used this script to automate the initial steps of creating a Pyhton project. Those are:

  1. Create a project folder

  2. Create a virtual environment

  3. Update the packet manager - I am using pip

  4. Install requirements

  5. Save installed requirements for sharing

Here is the GitHub link to this repo: Mohamork/PythonProjectInitializer: A script that reduces the initial steps of creating a Python project

0 Upvotes

16 comments sorted by

32

u/zanfar May 05 '26
  • Modern projects should not be using os.path or requirements.txt. Use pathlib and pyproject.toml instead.

  • pip freeze should be avoided as a way to identify dependencies as well.

  • except: pass is a huge red flag.

  • This requires me to edit the script every time I make a project in a different location?

  • Avoid string concatenation, especially unnecessary concatenation or path concatenation.

  • pkg = (sum(1 for _ in f))? Why? Why? and Why?

  • Code "commented" out as a docstring, and included in a production release, is a yellow flag.

4

u/Kevdog824_ May 05 '26

I want to add to the third bullet point here. The idiomatic way to ignore exceptions in Python is contextlib.suppress. except: pass could be an artifact from an exception handler that was meant to be implemented later, but forgotten. It doesn’t communicate intention. contextlib.suppress is explicit and better communicates that the exception is being intentionally ignored.

The bigger issue though is that they really shouldn’t be ignoring this exception. This would treat both the requirements.txt file being missing and a pip dependency resolution error the same way; both being ignored. I highly doubt this is what OP was intending to happen.

1

u/neuralbeans May 06 '26

What's wrong with requirements.txt?

1

u/TheSoulHokib May 06 '26

Nothing really wrong, but pyproject.toml are way more modern, robust and reliable

1

u/neuralbeans May 06 '26

Doesn't the toml file refer to the requirements.txt file? They're not mutually exclusive.

1

u/TheSoulHokib May 06 '26

Since you can manage everything that is managed by requirements.txt inside pyproject.toml, seems a bit redundant. You can have a look right there : https://pydevtools.com/handbook/explanation/pyproject-vs-requirements/ Plus, pyproject.toml now is the standard.

1

u/neuralbeans May 06 '26

This doesn't say how the toml file replaces requirements.txt. It just says not to use requirements.txt only, which is obvious as it's not meant for project management.

1

u/TheSoulHokib May 06 '26

All the dependencies, that you manage in requirements.txt, can be managed in pyproject.toml, as well as all the metadatas, setup.py, linters conf, etc. A single file to unify them all. On the dependencies aspect, also allow to manage dependencies by groups, depending on the usage (for example, dependencies only needed during dev). You can check out https://packaging.python.org/en/latest/guides/writing-pyproject-toml/, and google for more informations.

1

u/nirbyschreibt May 06 '26

I am curious, why not os.path?

I use dotenv for config files.

5

u/corey_sheerer May 05 '26

Not bad to experiment, but this is already a best practice to use environment management (UV is dominating, but I used to really kike poetry as well)

0

u/[deleted] May 05 '26

[deleted]

4

u/Extreme_Sympathy_868 May 05 '26

It is just practice my friend. 

2

u/guitarot May 05 '26

I'd suggest letting the user choose the package environment (pip, uv, etc), and then your script could automate any of them.

0

u/[deleted] May 06 '26

[deleted]

2

u/Extreme_Sympathy_868 May 06 '26

Wasn't useless at all. I already knew about uv but I've left it out just because I was learning the basics. Now I fully understand why uv is the better packet manager for modern software development. Thanks.