-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
26 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,29 +21,30 @@ A basic template for building Python packages. | |
2. **Clone this repository** and give it the name of your repository: `git clone [email protected]:tomsilver/python-starter.git <NAME>`. You should now have a directory called NAME. **Enter** that directory: `cd <NAME>`. | ||
3. **Configure the repository:** Make changes to `config.json` and then save. | ||
4. **Apply the configuration**: Run `python apply_configuration.py`. | ||
5. **Push your changes**: For example, run `git add . && git commit -m "First commit" && git push -u origin main`. | ||
|
||
:tada: **That's it! Your code is ready to use** :tada: You should see your code back on GitHub where you previously had an empty repository. | ||
|
||
### Common Next Steps | ||
5. **Make changes** to `pyproject.toml`, especially in the dependencies section. | ||
6. **Install your repository**: `pip install -e .` (recommended: use a virtualenv). | ||
7. **Replace the starter files** (`README.md`, `LICENSE`, `config.json`, `apply_configuration.py`, `structs.py`, `utils.py` and the analogous files in `tests/`) with some of your own. | ||
6. **Make changes** to `pyproject.toml`, especially in the dependencies section. | ||
7. **Install your repository**: `pip install -e .` (recommended: use a virtualenv). | ||
8. **Replace the starter files** (`README.md`, `LICENSE`, `config.json`, `apply_configuration.py`, `structs.py`, `utils.py` and the analogous files in `tests/`) with some of your own. | ||
|
||
### Configure GitHub (Optional but Recommended) | ||
8. **Set up branch protections** to prevent accidental changes to your main branch. In `https://github.com/<USER>/<NAME>/settings/branches`: | ||
9. **Set up branch protections** to prevent accidental changes to your main branch. In `https://github.com/<USER>/<NAME>/settings/branches`: | ||
- Click `Add classic branch protection rule`. | ||
- The branch pattern name is `main`. | ||
- Check "Require a pull request before merging (optionally: uncheck "Require approvals"). | ||
- Check "Require status checks to pass before merging". | ||
- Check "Require branches to be up to date before merging". | ||
- Then type in `autoformat`, `static-type-checking`, `linting`, `unit-tests`. | ||
- Check "Do not allow bypassing the above settings". | ||
9. **Set up repository settings** in `https://github.com/<USER>/<NAME>/settings`: | ||
10. **Set up repository settings** in `https://github.com/<USER>/<NAME>/settings`: | ||
- Check "Allow auto-merge". | ||
- Check "Automatically delete head branches". | ||
- Uncheck "Allow merge commits". | ||
- Uncheck "Allow rebase merging". | ||
10. **Set up contributor settings** to lower the barrier for external contributions. In `https://github.com/<USER>/<NAME>/settings/actions`: | ||
11. **Set up contributor settings** to lower the barrier for external contributions. In `https://github.com/<USER>/<NAME>/settings/actions`: | ||
- Update "Fork pull request workflows from outside collaborators" to "Require approval for first-time contributors who are new to GitHub". | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ def _replace_all_occurences( | |
["git", "ls-files"], encoding="utf-8", stdout=subprocess.PIPE, check=True | ||
) | ||
for line in proc.stdout.split("\n"): | ||
known_files.add(outer_dir / line) | ||
known_files.add((outer_dir / line).resolve()) | ||
known_files -= exclude | ||
for file_path in known_files: | ||
if file_path.is_dir(): | ||
|
@@ -38,7 +38,8 @@ def _replace_all_occurences( | |
|
||
def _main() -> None: | ||
# Parse the config. | ||
config_file = Path(".").parent / "config.json" | ||
outer_dir = Path(".").parent.resolve() | ||
config_file = outer_dir / "config.json" | ||
assert config_file.exists(), "Missing config file" | ||
with open(config_file, "r", encoding="utf-8") as fp: | ||
config = json.load(fp) | ||
|
@@ -64,10 +65,10 @@ def _main() -> None: | |
assert python_subversion.isdigit() | ||
|
||
# Get the repository name from this directory. | ||
repo_name = Path(".").parent.resolve().name | ||
repo_name = outer_dir.name | ||
|
||
# Delete the existing git files if they are from the starter repo. | ||
git_repo = Path(".").parent / ".git" | ||
git_repo = outer_dir / ".git" | ||
if git_repo.exists(): | ||
git_config_file = git_repo / "config" | ||
with open(git_config_file, "r", encoding="utf-8") as fp: | ||
|
@@ -78,6 +79,16 @@ def _main() -> None: | |
# Initialize the repo anew. | ||
subprocess.run(["git", "init", "-b", "main"], check=True) | ||
subprocess.run(["git", "add", "."], check=True) | ||
subprocess.run( | ||
[ | ||
"git", | ||
"remote", | ||
"add", | ||
"origin", | ||
f"[email protected]:{github_username}/{repo_name}.git", | ||
], | ||
check=True, | ||
) | ||
|
||
# Replace all occurrences of default names. | ||
substitutions = { | ||
|
@@ -89,26 +100,13 @@ def _main() -> None: | |
"310": f"3{python_subversion}", | ||
} | ||
for old, new in substitutions.items(): | ||
_replace_all_occurences(old, new, exclude={Path("."), config_file}) | ||
_replace_all_occurences( | ||
old, new, exclude={outer_dir / "apply_configuration.py", config_file} | ||
) | ||
|
||
# Rename the package repo. | ||
subprocess.run(["mv", "src/python_starter", f"src/{package_name}"], check=True) | ||
|
||
# Commit and push. | ||
subprocess.run(["git", "add", "."], check=True) | ||
subprocess.run(["git", "commit", "-m", "First commit"], check=True) | ||
subprocess.run( | ||
[ | ||
"git", | ||
"remote", | ||
"add", | ||
"origin", | ||
f"[email protected]:{github_username}/{repo_name}.git", | ||
], | ||
check=True, | ||
) | ||
subprocess.run(["git", "push", "-u", "origin", "main"], check=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |