python-poetry / python-poetry/poetry

Add exclude options for `poetry new`

Open
#5,460 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/feature
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Feature Request

Add exclude options for poetry new.

My usual workflow is as follows.

  1. Make a repo at GitHub and pull it to my local machine.
  2. Add python package with poetry.

However,
poetry init is not enough.
poetry new returns FileExistsError since 1st step create .git and LICENSE,

I want to exclude .git and LICENSE from the poetry new limitation and utilize poetry new for 2nd step.

My proposal is as below.

  1. Add exclude to config in a form of a list.
exclud_pattern = ['.git', 'LICENSE']
  1. Modify check workflow in src/poetry/console/commands/new.py
- if path.exists() and list(path.glob("*")):
+ glob_all = [str(p.relative_to(path)) for p in path.glob("*")]
+ if path.exists() and len(set(glob_all + exclude_pattern)) > len(exclude_pattern):
      # Directory is not empty. Aborting.
      raise RuntimeError(
          f"Destination <fg=yellow>{path}</> exists and is not empty"
      )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the poetry new entry point in src/poetry/console/commands/new.py and trace how destination contents are checked and how configuration is loaded. Define the exclusion behavior for existing .git and LICENSE entries, then verify that poetry new accepts those contents while still rejecting other non-empty destinations.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.