Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: add pre-commit and nox #45

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

Merged
merged 2 commits into from
Feb 25, 2023
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.DS_Store
.idea
sphinx_presentation/build/
sphinx_presentation/source/_build/

__pycache__
.nox
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
exclude: test_recipes/bitarray/meta.yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: name-tests-test
args: ["--pytest-test-first"]
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: "23.1.0"
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.252"
hooks:
- id: ruff

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.2"
hooks:
- id: codespell

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
8 changes: 3 additions & 5 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ The sections are ordered from most recent to the oldest.
Better handling data file in :ref:`setup_py_exercise_small_example_package` section
-----------------------------------------------------------------------------------

* Put package data in `data` directory.
* Put package data in ``data`` directory.
* Reflect this change in the code.
* Add `package_data` to setup function.
* Add ``package_data`` to setup function.


2018-07
Expand All @@ -38,6 +38,4 @@ Making a Python Package
Building and Uploading to PyPI
------------------------------

* Update `Installing a wheel` tutorial adding :ref:`Install a package from TestPyPI <install_wheel_from_testpypi>` section.


* Update ``Installing a wheel`` tutorial adding :ref:`Install a package from TestPyPI <install_wheel_from_testpypi>` section.
16 changes: 8 additions & 8 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
This repository contain the materials for a tutorial.

The code is licences under the Apache licence, version 2.0.

Text and other non-code written materials are licenced under the
Creative Commons Attribution-ShareAlike 4.0 International licence.

Text of both licenses below:


Apache License
==============
Version 2.0, January 2004
Expand Down Expand Up @@ -531,8 +531,8 @@ Section 8 – Interpretation.
---------------------------

a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be mad without permission under this Public License.

b. To the extent possible, if any provision of this Public License is
Expand All @@ -548,5 +548,5 @@ Section 8 – Interpretation.

d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ anaconda upload /Users/msarahan/miniconda3/conda-bld/osx-64/bitarray-0.8.1-py36h

anaconda_upload is not set. Not uploading wheels: []
####################################################################################
Resoource usage summary:
Resource usage summary:

Total time: 0:00:36.9
CPU usage: sys=0:00:00.2, user=0:00:00.2
Expand Down
2 changes: 1 addition & 1 deletion conda_build_recipes/03_copy_file/bld.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
COPY somefile.txt %PREFIX%
COPY somefile.txt %PREFIX%
2 changes: 1 addition & 1 deletion conda_build_recipes/04_python_in_build/bld.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
COPY somefile.py %SP_DIR%
COPY somefile.py %SP_DIR%
2 changes: 1 addition & 1 deletion conda_build_recipes/05_test_python/bld.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
COPY somefile.py %SP_DIR%
COPY somefile.py %SP_DIR%
2 changes: 1 addition & 1 deletion conda_build_recipes/06_has_run_exports/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package:

build:
run_exports:
- {{ pin_subpackage("has_run_exports") }}
- '{{ pin_subpackage("has_run_exports") }}'
25 changes: 25 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations

import nox


@nox.session(reuse_venv=True)
def docs(session: nox.Session) -> None:
"""
Build the docs. Pass "serve" to serve.
"""

session.install("-r", "sphinx_presentation/requirements.txt")
session.chdir("sphinx_presentation/source")

if "pdf" in session.posargs:
session.run("sphinx-build", "-M", "latexpdf", ".", "_build")
return

session.run("sphinx-build", "-M", "html", ".", "_build")

if "serve" in session.posargs:
session.log("Launching docs at http://localhost:8000/ - use Ctrl-C to quit")
session.run("python", "-m", "http.server", "8000", "-d", "_build/html")
elif session.posargs:
session.error("Unsupported argument to docs")
4 changes: 2 additions & 2 deletions setup_example/capitalize/capitalize/cap_data.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# list of words that don't get capitalized
is
or
or
a
the
it
to
to
10 changes: 5 additions & 5 deletions setup_example/capitalize/capitalize/capital_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def load_special_words(data_file_name, words=None):
from the data file in the package

data file is a text file with one work per line
the # charactor is a comment -- everything after it will be ignored
the # character is a comment -- everything after it will be ignored

"""
words = set() if words is None else words
with open(data_file_name) as data_file:
for line in data_file:
word = line.split('#')[0].strip()
word = line.split("#")[0].strip()
if word:
words.add(word.lower())
return words
Expand All @@ -45,7 +45,7 @@ def capitalize_line(instr, special_words=special_words):
:type instr: string

:param special_words: set of words that should not be capitalized
defaults to the words in the encosed data file
defaults to the words in the enclosed data file
:type special_words: set of str

:returns: a capitalized version of instr
Expand Down Expand Up @@ -83,8 +83,8 @@ def capitalize(infilename, outfilename):

:raises: IOError if infilename doesn't exist.
"""
infile = open(infilename, 'U')
outfile = open(outfilename, 'w')
infile = open(infilename, "U")
outfile = open(outfilename, "w")

for line in infile:
outfile.write(capitalize_line(line))
Expand Down
33 changes: 17 additions & 16 deletions setup_example/capitalize/capitalize/test/test_capital_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

import capital_mod


# fixture that creates and removes a file with special words in it
@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def special_words_path():
"""
fixture to generate a special words file to test reading
Expand All @@ -25,35 +26,37 @@ def special_words_path():
# A couple words for the file
words = ["in", "As", "the"]
temp_path = Path("special_words_file")
with open(temp_path, 'w') as outfile:
with open(temp_path, "w") as outfile:
for word in words:
outfile.write(word + "\n")
# test comments, too:
outfile.write("# random stuff")
outfile.write(" in # comment after a word\n")
# the file wil be created and filled, then the path passed on
# the file will be created and filled, then the path passed on
yield temp_path
# at "teardown", the file will be removed
os.remove(temp_path)


# fixture that creates and removes a file with some test lines in it.
@pytest.fixture(scope='module')
@pytest.fixture(scope="module")
def test_file_path():
"""
Fixture to generate a file with some sample data in it
"""
# A couple words for the file
temp_path = Path("input_test_file.txt")
with open(temp_path, 'w') as outfile:
outfile.write("""This is a really simple Text file.
with open(temp_path, "w") as outfile:
outfile.write(
"""This is a really simple Text file.
It is here so that I can test the capitalize script.

And that's only there to try out packaging.

So there.
""")
# the file wil be created and filled, then the path passed on
"""
)
# the file will be created and filled, then the path passed on
yield temp_path
# at "teardown", the file will be removed
os.remove(temp_path)
Expand All @@ -70,15 +73,16 @@ def test_load_special_words(special_words_path):


def test_capitalize_line():
special = {'is', 'a', 'to'}
line = "this is a Line to capitalize"
special = {"is", "a", "to"}
line = "this is a Line to capitalize"
expected = "This is a Line to Capitalize"

result = capital_mod.capitalize_line(line, special_words=special)
assert result == expected
assert result == expected


def test_capitalize(test_file_path):
""" test an actual file """
"""test an actual file"""
p = test_file_path

new_file_path = (p.parent / (p.stem + "_cap")).with_suffix(p.suffix)
Expand All @@ -92,7 +96,4 @@ def test_capitalize(test_file_path):
And That's Only There to Try Out Packaging.

So There."""
assert contents.strip() == expected



assert contents.strip() == expected
2 changes: 1 addition & 1 deletion sphinx_presentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ help:
# 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)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
2 changes: 1 addition & 1 deletion sphinx_presentation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Thanks to the integration of this GitHub project with readthedocs, this happens
automatically after the ``master`` branch is updated.

Historically, the website was only updated if a contributor was locally generating
the associated web pages and commiting them on the `gh-pages` branch.
the associated web pages and committing them on the ``gh-pages`` branch.


Building the slides
Expand Down
1 change: 1 addition & 0 deletions sphinx_presentation/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
furo
hieroglyph
sphinx
15 changes: 5 additions & 10 deletions sphinx_presentation/slides2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
rst.append("")
# find end of title page:
line = inlines.pop(0)
while line.strip() != '1':
while line.strip() != "1":
rst.append(line)
line = inlines.pop(0)

Expand All @@ -44,22 +44,17 @@
rst.append("-" * len(header))

# content is the stuff above it
for line in inlines[:start_ind - 1]:
for line in inlines[: start_ind - 1]:
rst.append(line)
# footer is the stuff in between
rst.append("")
for line in inlines[start_ind + 1:end_ind]:
for line in inlines[start_ind + 1 : end_ind]:
rst.append(line)
# clear it all out:
del inlines[:end_ind + 1]
del inlines[: end_ind + 1]
# and clear out any empty lines
while inlines and (not inlines[0].strip()):
del inlines[0]






open(outfilename, 'w').write("\n".join(rst))

open(outfilename, "w").write("\n".join(rst))
Loading