Skip to content

Commit

Permalink
fixes and feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsilver committed Aug 25, 2024
1 parent 5a0facc commit 848ea03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
pip install -e ".[develop]"
- name: Lint
run: |
pytest . --pylint -m pylint --pylint-rcfile=.python_starter_pylintrc
pytest . --pylint -m pylint --pylint-rcfile=.pylintrc
static-type-checking:
runs-on: ubuntu-latest
strategy:
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".


Expand Down
38 changes: 18 additions & 20 deletions apply_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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 = {
Expand All @@ -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()

0 comments on commit 848ea03

Please sign in to comment.