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

feat: pdm init template argument #2053

Merged
merged 16 commits into from
Jun 27, 2023
Merged

feat: pdm init template argument #2053

merged 16 commits into from
Jun 27, 2023

Conversation

frostming
Copy link
Collaborator

@frostming frostming commented Jun 25, 2023

Signed-off-by: Frost Ming [email protected]

Pull Request Checklist

  • A news fragment is added in news/ describing what is new.
  • Test cases added for changed code.

Describe what you have changed in this PR.

Discussion: #2037

@frostming
Copy link
Collaborator Author

An initial working implementation is ready, you can test it now with git+https://github.com/pdm-project/pdm@feat/template
@pawamoy @larrycai

Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2023

Codecov Report

Patch coverage: 90.57% and project coverage change: -0.21 ⚠️

Comparison is base (81f7fc4) 84.96% compared to head (3339e8b) 84.75%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2053      +/-   ##
==========================================
- Coverage   84.96%   84.75%   -0.21%     
==========================================
  Files          99      100       +1     
  Lines        9419     9559     +140     
  Branches     2060     2087      +27     
==========================================
+ Hits         8003     8102      +99     
- Misses        966     1004      +38     
- Partials      450      453       +3     
Flag Coverage Δ
unittests 84.54% <90.05%> (-0.22%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/pdm/cli/templates/__init__.py 87.93% <87.93%> (ø)
src/pdm/cli/commands/init.py 94.89% <93.54%> (+2.72%) ⬆️
src/pdm/cli/commands/run.py 93.38% <100.00%> (ø)
src/pdm/cli/utils.py 83.62% <100.00%> (ø)
src/pdm/compat.py 89.58% <100.00%> (+0.69%) ⬆️
src/pdm/pytest.py 92.35% <100.00%> (+0.04%) ⬆️

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
@frostming frostming marked this pull request as ready for review June 25, 2023 10:22
Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
Signed-off-by: Frost Ming <[email protected]>
@larrycai
Copy link

Username for 'https://github.com': larrycai   
Password for 'https://[email protected]': 

Why do we need to ask for user&passwd, is it anonymous access?

@larrycai
Copy link

Some testing

name

$ pdm init gitlab/copier-fastapi => https://github.com/pdm-project/template-gitlab/copier-fastapi/ not found
$ pdm init ../gitlab/copier-fastapi  => check locally, and I have folder there, it works

or if "/" in name, we treat it is local package?

template

$ pdm --version
PDM, version 2.7.5.dev32+g9854a9ea
$ pdm init django 
Creating a pyproject.toml for PDM...
Please enter the Python interpreter to use
..
Please select (0): 
Is the project a library that is installable?
If yes, we will need to ask a few more questions to include the project name and build backend [y/n] (n): y
Project name (tmp): hello
...
"/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_app'

@pawamoy
Copy link
Contributor

pawamoy commented Jun 26, 2023

namespace/proiect was left out of the feature, yes.

What is django in your context? A folder in the current working directory? Is this the full traceback?

@larrycai
Copy link

namespace/proiect was left out of the feature, yes.

What is django in your context? A folder in the current working directory? Is this the full traceback?

I saw https://github.com/pdm-project/template-django, then just want to give a try ;-). HappyTesting or ChaosTesting

@frostming
Copy link
Collaborator Author

@larrycai Thanks for the testing, it was fixed.

The complete logic finding template is here:

def prepare_template(self) -> None:
if self.template is None:
self._prepare_package_template(BUILTIN_TEMPLATE)
elif "://" in self.template or self.template.startswith("git@"):
self._prepare_git_template(self.template)
elif os.path.exists(self.template):
self._prepare_local_template(self.template)
else: # template name
template = f"https://github.com/pdm-project/template-{self.template}"
self._prepare_git_template(template)

@frostming
Copy link
Collaborator Author

frostming commented Jun 27, 2023

Why do we need to ask for user&passwd, is it anonymous access?

It is just inheriting your current git authentication. make sure to set credentials correctly so you can successfully run git clone.

@frostming
Copy link
Collaborator Author

frostming commented Jun 27, 2023

Now pdm init django should work like a charm! I will merge this first and cut an alpha release, where you can continue testing.

@frostming frostming merged commit 5149924 into main Jun 27, 2023
@frostming frostming deleted the feat/template branch June 27, 2023 02:26
@larrycai
Copy link

thx for quick fix, well done!

@frostming
Copy link
Collaborator Author

Now pdm init also supports --copier and --cookiecutter option, to use another project generators. They are now listed as optional dependencies, although I don't see any advantage over calling copier and cookiecutter CLI directly.

@j178 j178 mentioned this pull request Apr 3, 2024
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.

4 participants