Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ __pycache__/
*.py[cod]
*$py.class

# OSX
*.DS_Store

# C extensions
*.so

Expand Down Expand Up @@ -101,3 +104,7 @@ ENV/
.mypy_cache/

.pytest_cache


# VSCode
.vscode/
29 changes: 29 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

image: python:3.9

before_script:
- python --version # For debugging
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate

.test:
script:
- pip install tox codecov pre-commit
- tox

test:
extends: .test
variables:
TOXENV: py39

deploy:
environment: deploy
script:
- cp $PYPIRC $HOME/.pypirc # get your specific pypi config
- python setup.py bdist_wheel upload -r local-da # replace local-da with your pypi setting
artifacts:
paths:
- dist/*.whl
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
include python_seed/template/*
include python_seed/template/ci/*
include python_seed/template/ci/.github/workflows/*
include python_seed/template/ci/.circleci/*
include python_seed/template/cov/*
include python_seed/template/module/pyseed/*
include python_seed/template/module/tests/*
include python_seed/template/module/*
include python_seed/template/docs/*
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Usage: pyseed create [OPTIONS] NAME
Create new python seed skeleton.

Options:
--ci [circleci|github] Add CI configuration
--ci [circleci|github|gitlab] Add CI configuration.
--docs Add sphinx docs starter.
--help Show this message and exit.
```

Expand Down Expand Up @@ -131,7 +132,7 @@ Issues and pull requests are more than welcome.
```bash
$ git clone https://github.com/developmentseed/python-seed.git
$ cd python-seed
$ pip install -e .[dev]
$ pip install -e ".[dev]"
```

**Python3.7 only**
Expand Down
54 changes: 41 additions & 13 deletions python_seed/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,53 @@ def pyseed():
pass


CI_CHOICES = ["circleci", "github", "gitlab"]

@pyseed.command(short_help="Create new python seed skeleton")
@click.argument("name", type=str, nargs=1)
@click.option(
"--ci", type=click.Choice(["circleci", "github"]), help="Add CI configuration"
"--ci", type=click.Choice(CI_CHOICES), help="Add CI configuration"
)
@click.option(
"--docs", is_flag=True, help="Add Sphinx Docs"
)
def create(name, ci):
def create(name, ci, docs):
"""Create new python seed skeleton."""
template_dir = str(resources_files("python_seed") / "template" / "module")
shutil.copytree(template_dir, name)
shutil.rmtree(f"{name}/{name}", ignore_errors=True)
shutil.rmtree(f"{name}/docs", ignore_errors=True)
shutil.copytree(template_dir, name, dirs_exist_ok=True)

gitignore = str(resources_files("python_seed") / "template" / ".gitignore")
shutil.copy2(gitignore, f"{name}/.gitignore")

if ci:
template_dir = str(
resources_files("python_seed") / "template" / "ci" / f".{ci}"
)
shutil.copytree(template_dir, f"{name}/.{ci}")
# acommodate gitlab's single file ci config
if ci == 'gitlab':
template_file = str(
resources_files("python_seed") / "template" / "ci" / ".gitlab-ci.yml"
)
shutil.copy2(template_file, f"{name}/.gitlab-ci.yml")
else:
template_dir = str(
resources_files("python_seed") / "template" / "ci" / f".{ci}"
)
shutil.copytree(template_dir, f"{name}/.{ci}", dirs_exist_ok=True)

covconfig = str(
resources_files("python_seed") / "template" / "cov" / "codecov.yml"
)
shutil.copy2(covconfig, f"{name}/codecov.yml")

if docs:
docs_dir = str(
resources_files("python_seed") / "template" / "docs"
)
shutil.copytree(docs_dir, f"{name}/docs", dirs_exist_ok=True)





new_dir = name
name = name.replace("-", "_")
Expand All @@ -50,10 +77,11 @@ def create(name, ci):

for root, _, files in os.walk(new_dir):
for filename in files:
if filename.endswith(".pyc"):
continue
with open(f"{root}/{filename}", "r", encoding="utf-8") as f:
s = f.read().replace("pyseed", name)
try:
with open(f"{root}/{filename}", "r", encoding="utf-8") as f:
s = f.read().replace("pyseed", name)

with open(f"{root}/{filename}", "w", encoding="utf-8") as f:
f.write(s)
with open(f"{root}/{filename}", "w", encoding="utf-8") as f:
f.write(s)
except UnicodeDecodeError:
pass
109 changes: 109 additions & 0 deletions python_seed/template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# OSX
*.DS_Store

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.pytest_cache

# VSCode
.vscode/
62 changes: 62 additions & 0 deletions python_seed/template/ci/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

image: python:3.9

before_script:
- python --version # For debugging
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate

.test:
script:
- pip install tox codecov pre-commit
- tox

test:
extends: .test
variables:
TOXENV: py39

deploy:
environment: deploy
script:
- cp $PYPIRC $HOME/.pypirc # get your specific pypi config
- python setup.py bdist_wheel upload -r local-da # replace local-da with your pypi setting
artifacts:
paths:
- dist/*.whl
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

pages:
script:
- pip install sphinx sphinx-rtd-theme myst-parser
- cd docs ; make html
- mv _build/html/ ../public/
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH


# py3.6-test:
# extends: .test
# image: python:3.6
# variables:
# TOXENV: py36

# py3.7-test:
# extends: .test
# image: python:3.7
# variables:
# TOXENV: py37

# py3.8-test:
# extends: .test
# image: python:3.8
# variables:
# TOXENV: py38



20 changes: 20 additions & 0 deletions python_seed/template/docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Loading